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