OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "base/file_path.h" |
| 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/test/thread_test_helper.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/browser/tab_contents/tab_contents.h" |
| 14 #include "content/common/content_switches.h" |
| 15 #include "webkit/quota/quota_manager.h" |
| 16 |
| 17 using quota::QuotaManager; |
| 18 |
| 19 // This browser test is aimed towards exercising the FileAPI bindings and |
| 20 // the actual implementation that lives in the browser side. |
| 21 class FileSystemBrowserTest : public InProcessBrowserTest { |
| 22 public: |
| 23 FileSystemBrowserTest() { |
| 24 EnableDOMAutomation(); |
| 25 } |
| 26 |
| 27 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 28 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); |
| 29 } |
| 30 |
| 31 GURL testUrl(const FilePath& file_path) { |
| 32 const FilePath kTestDir(FILE_PATH_LITERAL("fileapi")); |
| 33 return ui_test_utils::GetTestUrl(kTestDir, file_path); |
| 34 } |
| 35 |
| 36 void SimpleTest(const GURL& test_url, bool incognito = false) { |
| 37 // The test page will perform tests on FileAPI, then navigate to either |
| 38 // a #pass or #fail ref. |
| 39 Browser* the_browser = incognito ? CreateIncognitoBrowser() : browser(); |
| 40 |
| 41 LOG(INFO) << "Navigating to URL and blocking."; |
| 42 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 43 the_browser, test_url, 2); |
| 44 LOG(INFO) << "Navigation done."; |
| 45 std::string result = the_browser->GetSelectedTabContents()->GetURL().ref(); |
| 46 if (result != "pass") { |
| 47 std::string js_result; |
| 48 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 49 the_browser->GetSelectedTabContents()->render_view_host(), L"", |
| 50 L"window.domAutomationController.send(getLog())", &js_result)); |
| 51 FAIL() << "Failed: " << js_result; |
| 52 } |
| 53 } |
| 54 }; |
| 55 |
| 56 class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest { |
| 57 public: |
| 58 virtual void SetUpOnMainThread() { |
| 59 const int kInitialQuotaKilobytes = 5000; |
| 60 const int kTemporaryStorageQuotaMaxSize = |
| 61 kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion; |
| 62 SetTempQuota( |
| 63 kTemporaryStorageQuotaMaxSize, browser()->profile()->GetQuotaManager()); |
| 64 } |
| 65 |
| 66 class SetTempQuotaCallback : public quota::QuotaCallback { |
| 67 public: |
| 68 void Run(quota::QuotaStatusCode, quota::StorageType, int64) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 70 } |
| 71 |
| 72 void RunWithParams(const Tuple3<quota::QuotaStatusCode, |
| 73 quota::StorageType, int64>& params) { |
| 74 Run(params.a, params.b, params.c); |
| 75 } |
| 76 }; |
| 77 |
| 78 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { |
| 79 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 80 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 81 NewRunnableFunction(&FileSystemBrowserTestWithLowQuota::SetTempQuota, |
| 82 bytes, qm)); |
| 83 return; |
| 84 } |
| 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 86 qm->SetTemporaryGlobalQuota(bytes, new SetTempQuotaCallback); |
| 87 // Don't return until the quota has been set. |
| 88 scoped_refptr<base::ThreadTestHelper> helper( |
| 89 new base::ThreadTestHelper( |
| 90 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); |
| 91 ASSERT_TRUE(helper->Run()); |
| 92 } |
| 93 }; |
| 94 |
| 95 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, RequestTest) { |
| 96 SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("request_test.html")))); |
| 97 } |
| 98 |
| 99 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, CreateTest) { |
| 100 SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("create_test.html")))); |
| 101 } |
| 102 |
| 103 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTestWithLowQuota, QuotaTest) { |
| 104 SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("quota_test.html")))); |
| 105 } |
OLD | NEW |