[email protected] | 16dd6e2 | 2012-03-01 19:08:20 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 5 | #include "base/bind.h" |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 6 | #include "base/command_line.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 7 | #include "base/files/file_path.h" |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 8 | #include "base/memory/ref_counted.h" |
| 9 | #include "base/test/thread_test_helper.h" |
[email protected] | 93ddb3c | 2012-04-11 21:44:29 | [diff] [blame] | 10 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 11 | #include "content/public/browser/browser_context.h" |
| 12 | #include "content/public/browser/browser_thread.h" |
[email protected] | f13b268 | 2012-08-22 00:37:55 | [diff] [blame] | 13 | #include "content/public/browser/storage_partition.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 14 | #include "content/public/common/content_switches.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 15 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 16 | #include "content/shell/shell.h" |
| 17 | #include "content/test/content_browser_test.h" |
| 18 | #include "content/test/content_browser_test_utils.h" |
[email protected] | 7660ec9 | 2013-05-30 05:12:39 | [diff] [blame] | 19 | #include "webkit/browser/quota/quota_manager.h" |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 20 | |
| 21 | using quota::QuotaManager; |
| 22 | |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 23 | namespace content { |
| 24 | |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 25 | // This browser test is aimed towards exercising the FileAPI bindings and |
| 26 | // the actual implementation that lives in the browser side. |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 27 | class FileSystemBrowserTest : public ContentBrowserTest { |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 28 | public: |
[email protected] | 90ca4427 | 2012-07-18 18:15:48 | [diff] [blame] | 29 | FileSystemBrowserTest() {} |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 30 | |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 31 | void SimpleTest(const GURL& test_url, bool incognito = false) { |
| 32 | // The test page will perform tests on FileAPI, then navigate to either |
| 33 | // a #pass or #fail ref. |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 34 | Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell(); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 35 | |
| 36 | LOG(INFO) << "Navigating to URL and blocking."; |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 37 | NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 38 | LOG(INFO) << "Navigation done."; |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 39 | std::string result = the_browser->web_contents()->GetURL().ref(); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 40 | if (result != "pass") { |
| 41 | std::string js_result; |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 42 | ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 43 | the_browser->web_contents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 44 | "window.domAutomationController.send(getLog())", |
| 45 | &js_result)); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 46 | FAIL() << "Failed: " << js_result; |
| 47 | } |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest { |
| 52 | public: |
[email protected] | c3e3589 | 2013-02-12 02:08:01 | [diff] [blame] | 53 | virtual void SetUpOnMainThread() OVERRIDE { |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 54 | const int kInitialQuotaKilobytes = 5000; |
| 55 | const int kTemporaryStorageQuotaMaxSize = |
| 56 | kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion; |
| 57 | SetTempQuota( |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 58 | kTemporaryStorageQuotaMaxSize, |
[email protected] | f13b268 | 2012-08-22 00:37:55 | [diff] [blame] | 59 | BrowserContext::GetDefaultStoragePartition( |
| 60 | shell()->web_contents()->GetBrowserContext())->GetQuotaManager()); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 61 | } |
| 62 | |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 63 | static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { |
| 64 | if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
[email protected] | 8075105 | 2011-11-12 17:10:58 | [diff] [blame] | 65 | BrowserThread::PostTask( |
| 66 | BrowserThread::IO, FROM_HERE, |
| 67 | base::Bind(&FileSystemBrowserTestWithLowQuota::SetTempQuota, bytes, |
| 68 | qm)); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 69 | return; |
| 70 | } |
| 71 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 4d99be5 | 2011-10-18 14:11:03 | [diff] [blame] | 72 | qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback()); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 73 | // Don't return until the quota has been set. |
| 74 | scoped_refptr<base::ThreadTestHelper> helper( |
| 75 | new base::ThreadTestHelper( |
| 76 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
| 77 | ASSERT_TRUE(helper->Run()); |
| 78 | } |
| 79 | }; |
| 80 | |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 81 | IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, RequestTest) { |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 82 | SimpleTest(GetTestUrl("fileapi", "request_test.html")); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, CreateTest) { |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 86 | SimpleTest(GetTestUrl("fileapi", "create_test.html")); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | IN_PROC_BROWSER_TEST_F(FileSystemBrowserTestWithLowQuota, QuotaTest) { |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 90 | SimpleTest(GetTestUrl("fileapi", "quota_test.html")); |
[email protected] | b4449206 | 2011-09-06 12:47:47 | [diff] [blame] | 91 | } |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 92 | |
[email protected] | 4cdc9a2 | 2012-07-26 03:39:31 | [diff] [blame] | 93 | } // namespace content |