| 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/bind.h" | |
| 6 #include "base/command_line.h" | |
| 7 #include "base/file_path.h" | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "base/test/thread_test_helper.h" | |
| 10 #include "chrome/browser/ui/browser.h" | |
| 11 #include "chrome/test/base/in_process_browser_test.h" | |
| 12 #include "chrome/test/base/testing_profile.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | |
| 14 #include "content/browser/tab_contents/tab_contents.h" | |
| 15 #include "content/public/common/content_switches.h" | |
| 16 #include "webkit/quota/quota_manager.h" | |
| 17 | |
| 18 using content::BrowserThread; | |
| 19 using quota::QuotaManager; | |
| 20 | |
| 21 // This browser test is aimed towards exercising the FileAPI bindings and | |
| 22 // the actual implementation that lives in the browser side. | |
| 23 class FileSystemBrowserTest : public InProcessBrowserTest { | |
| 24 public: | |
| 25 FileSystemBrowserTest() { | |
| 26 EnableDOMAutomation(); | |
| 27 } | |
| 28 | |
| 29 GURL testUrl(const FilePath& file_path) { | |
| 30 const FilePath kTestDir(FILE_PATH_LITERAL("fileapi")); | |
| 31 return ui_test_utils::GetTestUrl(kTestDir, file_path); | |
| 32 } | |
| 33 | |
| 34 void SimpleTest(const GURL& test_url, bool incognito = false) { | |
| 35 // The test page will perform tests on FileAPI, then navigate to either | |
| 36 // a #pass or #fail ref. | |
| 37 Browser* the_browser = incognito ? CreateIncognitoBrowser() : browser(); | |
| 38 | |
| 39 LOG(INFO) << "Navigating to URL and blocking."; | |
| 40 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | |
| 41 the_browser, test_url, 2); | |
| 42 LOG(INFO) << "Navigation done."; | |
| 43 std::string result = the_browser->GetSelectedWebContents()->GetURL().ref(); | |
| 44 if (result != "pass") { | |
| 45 std::string js_result; | |
| 46 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | |
| 47 the_browser->GetSelectedWebContents()->GetRenderViewHost(), L"", | |
| 48 L"window.domAutomationController.send(getLog())", &js_result)); | |
| 49 FAIL() << "Failed: " << js_result; | |
| 50 } | |
| 51 } | |
| 52 }; | |
| 53 | |
| 54 class FileSystemBrowserTestWithLowQuota : public FileSystemBrowserTest { | |
| 55 public: | |
| 56 virtual void SetUpOnMainThread() { | |
| 57 const int kInitialQuotaKilobytes = 5000; | |
| 58 const int kTemporaryStorageQuotaMaxSize = | |
| 59 kInitialQuotaKilobytes * 1024 * QuotaManager::kPerHostTemporaryPortion; | |
| 60 SetTempQuota( | |
| 61 kTemporaryStorageQuotaMaxSize, | |
| 62 content::BrowserContext::GetQuotaManager(browser()->profile())); | |
| 63 } | |
| 64 | |
| 65 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { | |
| 66 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
| 67 BrowserThread::PostTask( | |
| 68 BrowserThread::IO, FROM_HERE, | |
| 69 base::Bind(&FileSystemBrowserTestWithLowQuota::SetTempQuota, bytes, | |
| 70 qm)); | |
| 71 return; | |
| 72 } | |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 74 qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback()); | |
| 75 // Don't return until the quota has been set. | |
| 76 scoped_refptr<base::ThreadTestHelper> helper( | |
| 77 new base::ThreadTestHelper( | |
| 78 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | |
| 79 ASSERT_TRUE(helper->Run()); | |
| 80 } | |
| 81 }; | |
| 82 | |
| 83 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, RequestTest) { | |
| 84 SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("request_test.html")))); | |
| 85 } | |
| 86 | |
| 87 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTest, CreateTest) { | |
| 88 SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("create_test.html")))); | |
| 89 } | |
| 90 | |
| 91 IN_PROC_BROWSER_TEST_F(FileSystemBrowserTestWithLowQuota, QuotaTest) { | |
| 92 SimpleTest(testUrl(FilePath(FILE_PATH_LITERAL("quota_test.html")))); | |
| 93 } | |
| OLD | NEW |