Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: content/browser/in_process_webkit/indexed_db_browsertest.cc

Issue 10821037: Move a number of other tests from browser_tests to content_browsertests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: a little cleaner Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
12 #include "base/test/thread_test_helper.h" 12 #include "base/test/thread_test_helper.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_tabstrip.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" 14 #include "content/browser/in_process_webkit/indexed_db_context_impl.h"
20 #include "content/browser/web_contents/web_contents_impl.h" 15 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/public/browser/browser_context.h"
17 #include "content/public/browser/browser_thread.h"
21 #include "content/public/common/content_paths.h" 18 #include "content/public/common/content_paths.h"
22 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
23 #include "content/public/test/browser_test_utils.h" 20 #include "content/public/test/browser_test_utils.h"
21 #include "content/shell/shell.h"
22 #include "content/test/content_browser_test.h"
23 #include "content/test/content_browser_test_utils.h"
24 #include "net/base/net_util.h" 24 #include "net/base/net_util.h"
25 #include "webkit/database/database_util.h" 25 #include "webkit/database/database_util.h"
26 #include "webkit/quota/mock_special_storage_policy.h" 26 #include "webkit/quota/mock_special_storage_policy.h"
27 #include "webkit/quota/quota_manager.h" 27 #include "webkit/quota/quota_manager.h"
28 #include "webkit/quota/special_storage_policy.h" 28 #include "webkit/quota/special_storage_policy.h"
29 29
30 using content::BrowserContext;
31 using content::BrowserThread;
32 using quota::QuotaManager; 30 using quota::QuotaManager;
33 using webkit_database::DatabaseUtil; 31 using webkit_database::DatabaseUtil;
34 32
33 namespace content {
34
35 // This browser test is aimed towards exercising the IndexedDB bindings and 35 // This browser test is aimed towards exercising the IndexedDB bindings and
36 // the actual implementation that lives in the browser side (in_process_webkit). 36 // the actual implementation that lives in the browser side (in_process_webkit).
37 class IndexedDBBrowserTest : public InProcessBrowserTest { 37 class IndexedDBBrowserTest : public ContentBrowserTest {
38 public: 38 public:
39 IndexedDBBrowserTest() {} 39 IndexedDBBrowserTest() {}
40 40
41 GURL GetTestURL(const FilePath& file_path) {
42 FilePath dir;
43 PathService::Get(content::DIR_TEST_DATA, &dir);
44 return net::FilePathToFileURL(
45 dir.Append(FILE_PATH_LITERAL("indexeddb")).Append(file_path));
46 }
47
48 void SimpleTest(const GURL& test_url, bool incognito = false) { 41 void SimpleTest(const GURL& test_url, bool incognito = false) {
49 // The test page will perform tests on IndexedDB, then navigate to either 42 // The test page will perform tests on IndexedDB, then navigate to either
50 // a #pass or #fail ref. 43 // a #pass or #fail ref.
51 Browser* the_browser = incognito ? CreateIncognitoBrowser() : browser(); 44 Shell* the_browser = incognito ? CreateOffTheRecordBrowser() : shell();
52 45
53 LOG(INFO) << "Navigating to URL and blocking."; 46 LOG(INFO) << "Navigating to URL and blocking.";
54 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 47 NavigateToURLBlockUntilNavigationsComplete(the_browser, test_url, 2);
55 the_browser, test_url, 2);
56 LOG(INFO) << "Navigation done."; 48 LOG(INFO) << "Navigation done.";
57 std::string result = 49 std::string result = the_browser->web_contents()->GetURL().ref();
58 chrome::GetActiveWebContents(the_browser)->GetURL().ref();
59 if (result != "pass") { 50 if (result != "pass") {
60 std::string js_result; 51 std::string js_result;
61 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( 52 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
62 chrome::GetActiveWebContents(the_browser)->GetRenderViewHost(), L"", 53 the_browser->web_contents()->GetRenderViewHost(), L"",
63 L"window.domAutomationController.send(getLog())", &js_result)); 54 L"window.domAutomationController.send(getLog())", &js_result));
64 FAIL() << "Failed: " << js_result; 55 FAIL() << "Failed: " << js_result;
65 } 56 }
66 } 57 }
67 }; 58 };
68 59
69 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTest) { 60 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTest) {
70 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("cursor_test.html")))); 61 SimpleTest(GetTestUrl("indexeddb", "cursor_test.html"));
71 } 62 }
72 63
73 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTestIncognito) { 64 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTestIncognito) {
74 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("cursor_test.html"))), 65 SimpleTest(GetTestUrl("indexeddb", "cursor_test.html"),
75 true /* incognito */); 66 true /* incognito */);
76 } 67 }
77 68
78 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorPrefetch) { 69 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorPrefetch) {
79 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("cursor_prefetch.html")))); 70 SimpleTest(GetTestUrl("indexeddb", "cursor_prefetch.html"));
80 } 71 }
81 72
82 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, IndexTest) { 73 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, IndexTest) {
83 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("index_test.html")))); 74 SimpleTest(GetTestUrl("indexeddb", "index_test.html"));
84 } 75 }
85 76
86 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, KeyPathTest) { 77 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, KeyPathTest) {
87 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("key_path_test.html")))); 78 SimpleTest(GetTestUrl("indexeddb", "key_path_test.html"));
88 } 79 }
89 80
90 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, TransactionGetTest) { 81 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, TransactionGetTest) {
91 SimpleTest(GetTestURL(FilePath( 82 SimpleTest(GetTestUrl("indexeddb", "transaction_get_test.html"));
92 FILE_PATH_LITERAL("transaction_get_test.html"))));
93 } 83 }
94 84
95 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, KeyTypesTest) { 85 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, KeyTypesTest) {
96 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("key_types_test.html")))); 86 SimpleTest(GetTestUrl("indexeddb", "key_types_test.html"));
97 } 87 }
98 88
99 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ObjectStoreTest) { 89 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ObjectStoreTest) {
100 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("object_store_test.html")))); 90 SimpleTest(GetTestUrl("indexeddb", "object_store_test.html"));
101 } 91 }
102 92
103 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DatabaseTest) { 93 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DatabaseTest) {
104 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("database_test.html")))); 94 SimpleTest(GetTestUrl("indexeddb", "database_test.html"));
105 } 95 }
106 96
107 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, TransactionTest) { 97 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, TransactionTest) {
108 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("transaction_test.html")))); 98 SimpleTest(GetTestUrl("indexeddb", "transaction_test.html"));
109 } 99 }
110 100
111 // Appears flaky/slow, see: http://crbug.com/120298 101 // Appears flaky/slow, see: http://crbug.com/120298
112 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DISABLED_ValueSizeTest) { 102 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DISABLED_ValueSizeTest) {
113 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("value_size_test.html")))); 103 SimpleTest(GetTestUrl("indexeddb", "value_size_test.html"));
114 } 104 }
115 105
116 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DoesntHangTest) { 106 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, DoesntHangTest) {
117 SimpleTest(GetTestURL(FilePath( 107 SimpleTest(GetTestUrl("indexeddb", "transaction_run_forever.html"));
118 FILE_PATH_LITERAL("transaction_run_forever.html")))); 108 CrashTab(shell()->web_contents());
119 content::CrashTab(chrome::GetActiveWebContents(browser())); 109 SimpleTest(GetTestUrl("indexeddb", "transaction_test.html"));
120 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("transaction_test.html"))));
121 } 110 }
122 111
123 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug84933Test) { 112 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug84933Test) {
124 const GURL url = GetTestURL(FilePath(FILE_PATH_LITERAL("bug_84933.html"))); 113 const GURL url = GetTestUrl("indexeddb", "bug_84933.html");
125 114
126 // Just navigate to the URL. Test will crash if it fails. 115 // Just navigate to the URL. Test will crash if it fails.
127 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 1); 116 NavigateToURLBlockUntilNavigationsComplete(shell(), url, 1);
128 } 117 }
129 118
130 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug106883Test) { 119 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug106883Test) {
131 const GURL url = GetTestURL(FilePath(FILE_PATH_LITERAL("bug_106883.html"))); 120 const GURL url = GetTestUrl("indexeddb", "bug_106883.html");
132 121
133 // Just navigate to the URL. Test will crash if it fails. 122 // Just navigate to the URL. Test will crash if it fails.
134 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 1); 123 NavigateToURLBlockUntilNavigationsComplete(shell(), url, 1);
135 } 124 }
136 125
137 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug109187Test) { 126 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug109187Test) {
138 const GURL url = GetTestURL(FilePath(FILE_PATH_LITERAL("bug_109187.html"))); 127 const GURL url = GetTestUrl("indexeddb", "bug_109187.html");
139 128
140 // Just navigate to the URL. Test will crash if it fails. 129 // Just navigate to the URL. Test will crash if it fails.
141 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 1); 130 NavigateToURLBlockUntilNavigationsComplete(shell(), url, 1);
142 } 131 }
143 132
144 class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest { 133 class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest {
145 public: 134 public:
146 virtual void SetUpOnMainThread() { 135 virtual void SetUpOnMainThread() {
147 const int kInitialQuotaKilobytes = 5000; 136 const int kInitialQuotaKilobytes = 5000;
148 const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes 137 const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes
149 * 1024 * QuotaManager::kPerHostTemporaryPortion; 138 * 1024 * QuotaManager::kPerHostTemporaryPortion;
150 SetTempQuota( 139 SetTempQuota(
151 kTemporaryStorageQuotaMaxSize, 140 kTemporaryStorageQuotaMaxSize,
152 content::BrowserContext::GetQuotaManager(browser()->profile())); 141 BrowserContext::GetQuotaManager(
142 shell()->web_contents()->GetBrowserContext()));
153 } 143 }
154 144
155 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { 145 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) {
156 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 146 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
157 BrowserThread::PostTask( 147 BrowserThread::PostTask(
158 BrowserThread::IO, FROM_HERE, 148 BrowserThread::IO, FROM_HERE,
159 base::Bind(&IndexedDBBrowserTestWithLowQuota::SetTempQuota, bytes, 149 base::Bind(&IndexedDBBrowserTestWithLowQuota::SetTempQuota, bytes,
160 qm)); 150 qm));
161 return; 151 return;
162 } 152 }
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
164 qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback()); 154 qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback());
165 // Don't return until the quota has been set. 155 // Don't return until the quota has been set.
166 scoped_refptr<base::ThreadTestHelper> helper( 156 scoped_refptr<base::ThreadTestHelper> helper(
167 new base::ThreadTestHelper( 157 new base::ThreadTestHelper(
168 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); 158 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)));
169 ASSERT_TRUE(helper->Run()); 159 ASSERT_TRUE(helper->Run());
170 } 160 }
171 161
172 }; 162 };
173 163
174 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithLowQuota, QuotaTest) { 164 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithLowQuota, QuotaTest) {
175 SimpleTest(GetTestURL(FilePath(FILE_PATH_LITERAL("quota_test.html")))); 165 SimpleTest(GetTestUrl("indexeddb", "quota_test.html"));
176 } 166 }
177 167
178 class IndexedDBBrowserTestWithGCExposed : public IndexedDBBrowserTest { 168 class IndexedDBBrowserTestWithGCExposed : public IndexedDBBrowserTest {
179 public: 169 public:
180 virtual void SetUpCommandLine(CommandLine* command_line) { 170 virtual void SetUpCommandLine(CommandLine* command_line) {
181 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); 171 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
182 } 172 }
183 }; 173 };
184 174
185 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, 175 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed,
186 DatabaseCallbacksTest) { 176 DatabaseCallbacksTest) {
187 SimpleTest( 177 SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html"));
188 GetTestURL(FilePath(FILE_PATH_LITERAL("database_callbacks_first.html"))));
189 } 178 }
179
180 } // namespace content
OLDNEW
« no previous file with comments | « chrome/test/data/webkit/xslt-bad-import.html ('k') | content/browser/indexed_db/idbbindingutilities_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698