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/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" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 1); | 128 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 1); |
129 } | 129 } |
130 | 130 |
131 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug109187Test) { | 131 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, Bug109187Test) { |
132 const GURL url = GetTestURL(FilePath(FILE_PATH_LITERAL("bug_109187.html"))); | 132 const GURL url = GetTestURL(FilePath(FILE_PATH_LITERAL("bug_109187.html"))); |
133 | 133 |
134 // Just navigate to the URL. Test will crash if it fails. | 134 // Just navigate to the URL. Test will crash if it fails. |
135 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 1); | 135 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 1); |
136 } | 136 } |
137 | 137 |
138 #if defined(OS_MACOSX) | |
139 // http://crbug.com/115188. On Mac, failure rate is about 18% currently. | |
140 #define MAYBE_ClearLocalState DISABLED_ClearLocalState | |
141 #else | |
142 #define MAYBE_ClearLocalState ClearLocalState | |
143 #endif | |
144 | |
145 // In proc browser test is needed here because ClearLocalState indirectly calls | |
146 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. | |
147 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, MAYBE_ClearLocalState) { | |
148 ScopedTempDir temp_dir; | |
149 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
150 | |
151 FilePath protected_path; | |
152 FilePath unprotected_path; | |
153 | |
154 // Create the scope which will ensure we run the destructor of the webkit | |
155 // context which should trigger the clean up. | |
156 { | |
157 TestingProfile profile; | |
158 | |
159 // Test our assumptions about what is protected and what is not. | |
160 const GURL kProtectedOrigin("chrome-extension://foo/"); | |
161 const GURL kUnprotectedOrigin("http://foo/"); | |
162 quota::SpecialStoragePolicy* policy = profile.GetSpecialStoragePolicy(); | |
163 ASSERT_TRUE(policy->IsStorageProtected(kProtectedOrigin)); | |
164 ASSERT_FALSE(policy->IsStorageProtected(kUnprotectedOrigin)); | |
165 | |
166 // Create some indexedDB paths. | |
167 // With the levelDB backend, these are directories. | |
168 IndexedDBContextImpl* idb_context = | |
169 static_cast<IndexedDBContextImpl*>( | |
170 BrowserContext::GetIndexedDBContext(&profile)); | |
171 idb_context->set_data_path_for_testing(temp_dir.path()); | |
172 protected_path = idb_context->GetFilePathForTesting( | |
173 DatabaseUtil::GetOriginIdentifier(kProtectedOrigin)); | |
174 unprotected_path = idb_context->GetFilePathForTesting( | |
175 DatabaseUtil::GetOriginIdentifier(kUnprotectedOrigin)); | |
176 ASSERT_TRUE(file_util::CreateDirectory(protected_path)); | |
177 ASSERT_TRUE(file_util::CreateDirectory(unprotected_path)); | |
178 | |
179 // Setup to clear all unprotected origins on exit. | |
180 idb_context->set_clear_local_state_on_exit(true); | |
181 } | |
182 | |
183 // Make sure we wait until the destructor has run. | |
184 scoped_refptr<base::ThreadTestHelper> helper_io( | |
185 new base::ThreadTestHelper( | |
186 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | |
187 ASSERT_TRUE(helper_io->Run()); | |
188 scoped_refptr<base::ThreadTestHelper> helper_webkit( | |
189 new base::ThreadTestHelper( | |
190 BrowserThread::GetMessageLoopProxyForThread( | |
191 BrowserThread::WEBKIT_DEPRECATED))); | |
192 ASSERT_TRUE(helper_webkit->Run()); | |
193 | |
194 ASSERT_TRUE(file_util::DirectoryExists(protected_path)); | |
195 ASSERT_FALSE(file_util::DirectoryExists(unprotected_path)); | |
196 } | |
197 | |
198 // In proc browser test is needed here because ClearLocalState indirectly calls | |
199 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. | |
200 // http://crbug.com/115307 | |
201 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, | |
202 DISABLED_ClearSessionOnlyDatabases) { | |
203 ScopedTempDir temp_dir; | |
204 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
205 | |
206 FilePath normal_path; | |
207 FilePath session_only_path; | |
208 | |
209 // Create the scope which will ensure we run the destructor of the webkit | |
210 // context which should trigger the clean up. | |
211 { | |
212 TestingProfile profile; | |
213 | |
214 const GURL kNormalOrigin("http://normal/"); | |
215 const GURL kSessionOnlyOrigin("http://session-only/"); | |
216 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | |
217 new quota::MockSpecialStoragePolicy; | |
218 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); | |
219 | |
220 // Create some indexedDB paths. | |
221 // With the levelDB backend, these are directories. | |
222 IndexedDBContextImpl* idb_context = | |
223 static_cast<IndexedDBContextImpl*>( | |
224 BrowserContext::GetIndexedDBContext(&profile)); | |
225 | |
226 // Override the storage policy with our own. | |
227 idb_context->special_storage_policy_ = special_storage_policy; | |
228 idb_context->set_data_path_for_testing(temp_dir.path()); | |
229 | |
230 normal_path = idb_context->GetFilePathForTesting( | |
231 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); | |
232 session_only_path = idb_context->GetFilePathForTesting( | |
233 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin)); | |
234 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | |
235 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); | |
236 } | |
237 | |
238 scoped_refptr<base::ThreadTestHelper> helper_io( | |
239 new base::ThreadTestHelper( | |
240 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | |
241 ASSERT_TRUE(helper_io->Run()); | |
242 scoped_refptr<base::ThreadTestHelper> helper_webkit( | |
243 new base::ThreadTestHelper( | |
244 BrowserThread::GetMessageLoopProxyForThread( | |
245 BrowserThread::WEBKIT_DEPRECATED))); | |
246 ASSERT_TRUE(helper_webkit->Run()); | |
247 | |
248 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); | |
249 EXPECT_FALSE(file_util::DirectoryExists(session_only_path)); | |
250 } | |
251 | |
252 #if defined(OS_MACOSX) | |
253 // http://crbug.com/115188. On Mac, failure rate is about 18% currently. | |
254 #define MAYBE_SaveSessionState DISABLED_SaveSessionState | |
255 #else | |
256 #define MAYBE_SaveSessionState SaveSessionState | |
257 #endif | |
258 | |
259 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, MAYBE_SaveSessionState) { | |
260 ScopedTempDir temp_dir; | |
261 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
262 | |
263 FilePath normal_path; | |
264 FilePath session_only_path; | |
265 | |
266 // Create the scope which will ensure we run the destructor of the webkit | |
267 // context. | |
268 { | |
269 TestingProfile profile; | |
270 | |
271 const GURL kNormalOrigin("http://normal/"); | |
272 const GURL kSessionOnlyOrigin("http://session-only/"); | |
273 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | |
274 new quota::MockSpecialStoragePolicy; | |
275 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); | |
276 | |
277 // Create some indexedDB paths. | |
278 // With the levelDB backend, these are directories. | |
279 IndexedDBContextImpl* idb_context = | |
280 static_cast<IndexedDBContextImpl*>( | |
281 BrowserContext::GetIndexedDBContext(&profile)); | |
282 | |
283 // Override the storage policy with our own. | |
284 idb_context->special_storage_policy_ = special_storage_policy; | |
285 idb_context->set_clear_local_state_on_exit(true); | |
286 idb_context->set_data_path_for_testing(temp_dir.path()); | |
287 | |
288 // Save session state. This should bypass the destruction-time deletion. | |
289 idb_context->SaveSessionState(); | |
290 | |
291 normal_path = idb_context->GetFilePathForTesting( | |
292 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); | |
293 session_only_path = idb_context->GetFilePathForTesting( | |
294 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin)); | |
295 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | |
296 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); | |
297 } | |
298 | |
299 // Make sure we wait until the destructor has run. | |
300 scoped_refptr<base::ThreadTestHelper> helper( | |
301 new base::ThreadTestHelper( | |
302 BrowserThread::GetMessageLoopProxyForThread( | |
303 BrowserThread::WEBKIT_DEPRECATED))); | |
304 ASSERT_TRUE(helper->Run()); | |
305 | |
306 // No data was cleared because of SaveSessionState. | |
307 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); | |
308 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); | |
309 } | |
310 | |
311 class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest { | 138 class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest { |
312 public: | 139 public: |
313 virtual void SetUpOnMainThread() { | 140 virtual void SetUpOnMainThread() { |
314 const int kInitialQuotaKilobytes = 5000; | 141 const int kInitialQuotaKilobytes = 5000; |
315 const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes | 142 const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes |
316 * 1024 * QuotaManager::kPerHostTemporaryPortion; | 143 * 1024 * QuotaManager::kPerHostTemporaryPortion; |
317 SetTempQuota( | 144 SetTempQuota( |
318 kTemporaryStorageQuotaMaxSize, | 145 kTemporaryStorageQuotaMaxSize, |
319 content::BrowserContext::GetQuotaManager(browser()->profile())); | 146 content::BrowserContext::GetQuotaManager(browser()->profile())); |
320 } | 147 } |
(...skipping 26 matching lines...) Expand all Loading... |
347 virtual void SetUpCommandLine(CommandLine* command_line) { | 174 virtual void SetUpCommandLine(CommandLine* command_line) { |
348 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | 175 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); |
349 } | 176 } |
350 }; | 177 }; |
351 | 178 |
352 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, | 179 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, |
353 DatabaseCallbacksTest) { | 180 DatabaseCallbacksTest) { |
354 SimpleTest( | 181 SimpleTest( |
355 GetTestURL(FilePath(FILE_PATH_LITERAL("database_callbacks_first.html")))); | 182 GetTestURL(FilePath(FILE_PATH_LITERAL("database_callbacks_first.html")))); |
356 } | 183 } |
OLD | NEW |