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/message_loop.h" |
10 #include "base/process_util.h" | 11 #include "base/process_util.h" |
11 #include "base/test/thread_test_helper.h" | 12 #include "base/test/thread_test_helper.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" | 14 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" |
14 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/storage_partition.h" | 19 #include "content/public/browser/storage_partition.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 const char* expected_string) { | 62 const char* expected_string) { |
62 GURL url = GetTestUrl("indexeddb", filename); | 63 GURL url = GetTestUrl("indexeddb", filename); |
63 if (hash) | 64 if (hash) |
64 url = GURL(url.spec() + hash); | 65 url = GURL(url.spec() + hash); |
65 | 66 |
66 string16 expected_title16(ASCIIToUTF16(expected_string)); | 67 string16 expected_title16(ASCIIToUTF16(expected_string)); |
67 TitleWatcher title_watcher(shell->web_contents(), expected_title16); | 68 TitleWatcher title_watcher(shell->web_contents(), expected_title16); |
68 NavigateToURL(shell, url); | 69 NavigateToURL(shell, url); |
69 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 70 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
70 } | 71 } |
| 72 |
| 73 scoped_refptr<IndexedDBContext> GetContext() { |
| 74 StoragePartition* partition = |
| 75 BrowserContext::GetDefaultStoragePartition( |
| 76 shell()->web_contents()->GetBrowserContext()); |
| 77 return partition->GetIndexedDBContext(); |
| 78 }; |
71 }; | 79 }; |
72 | 80 |
73 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTest) { | 81 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTest) { |
74 SimpleTest(GetTestUrl("indexeddb", "cursor_test.html")); | 82 SimpleTest(GetTestUrl("indexeddb", "cursor_test.html")); |
75 } | 83 } |
76 | 84 |
77 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTestIncognito) { | 85 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTestIncognito) { |
78 SimpleTest(GetTestUrl("indexeddb", "cursor_test.html"), | 86 SimpleTest(GetTestUrl("indexeddb", "cursor_test.html"), |
79 true /* incognito */); | 87 true /* incognito */); |
80 } | 88 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 virtual void SetUpCommandLine(CommandLine* command_line) { | 193 virtual void SetUpCommandLine(CommandLine* command_line) { |
186 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | 194 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); |
187 } | 195 } |
188 }; | 196 }; |
189 | 197 |
190 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, | 198 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, |
191 DatabaseCallbacksTest) { | 199 DatabaseCallbacksTest) { |
192 SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html")); | 200 SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html")); |
193 } | 201 } |
194 | 202 |
195 class IndexedDBBrowserTestWithVersion0Schema : public IndexedDBBrowserTest { | 203 static void CopyLevelDBToProfile(Shell* shell, |
| 204 scoped_refptr<IndexedDBContext> context, |
| 205 const std::string& test_directory) { |
| 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
| 207 FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb")); |
| 208 FilePath test_data_dir = |
| 209 GetTestFilePath("indexeddb", test_directory.c_str()).Append(leveldb_dir); |
| 210 IndexedDBContextImpl* context_impl = |
| 211 static_cast<IndexedDBContextImpl*>(context.get()); |
| 212 FilePath dest = context_impl->data_path().Append(leveldb_dir); |
| 213 // If we don't create the destination directory first, the contents of the |
| 214 // leveldb directory are copied directly into profile/IndexedDB instead of |
| 215 // profile/IndexedDB/file__0.xxx/ |
| 216 ASSERT_TRUE(file_util::CreateDirectory(dest)); |
| 217 const bool kRecursive = true; |
| 218 ASSERT_TRUE(file_util::CopyDirectory(test_data_dir, |
| 219 context_impl->data_path(), |
| 220 kRecursive)); |
| 221 } |
| 222 |
| 223 class IndexedDBBrowserTestWithPreexisingLevelDB : public IndexedDBBrowserTest { |
196 public: | 224 public: |
197 virtual void SetUpOnMainThread() { | 225 virtual void SetUpOnMainThread() { |
198 scoped_refptr<IndexedDBContext> context = | 226 scoped_refptr<IndexedDBContext> context = GetContext(); |
199 BrowserContext::GetDefaultStoragePartition( | |
200 shell()->web_contents()->GetBrowserContext())-> | |
201 GetIndexedDBContext(); | |
202 BrowserThread::PostTask( | 227 BrowserThread::PostTask( |
203 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 228 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
204 base::Bind( | 229 base::Bind(&CopyLevelDBToProfile, shell(), context, |
205 &IndexedDBBrowserTestWithVersion0Schema::CopyLevelDBToProfile, | 230 EnclosingLevelDBDir())); |
206 shell(), | |
207 context)); | |
208 scoped_refptr<base::ThreadTestHelper> helper( | 231 scoped_refptr<base::ThreadTestHelper> helper( |
209 new base::ThreadTestHelper(BrowserThread::GetMessageLoopProxyForThread( | 232 new base::ThreadTestHelper(BrowserThread::GetMessageLoopProxyForThread( |
210 BrowserThread::WEBKIT_DEPRECATED))); | 233 BrowserThread::WEBKIT_DEPRECATED))); |
211 ASSERT_TRUE(helper->Run()); | 234 ASSERT_TRUE(helper->Run()); |
212 } | 235 } |
213 static void CopyLevelDBToProfile(Shell* shell, | 236 |
214 scoped_refptr<IndexedDBContext> context) { | 237 virtual std::string EnclosingLevelDBDir() = 0; |
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 238 }; |
216 FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb")); | 239 |
217 FilePath test_data_dir = | 240 class IndexedDBBrowserTestWithVersion0Schema : public |
218 GetTestFilePath("indexeddb", "migration_from_0").Append(leveldb_dir); | 241 IndexedDBBrowserTestWithPreexisingLevelDB { |
219 IndexedDBContextImpl* context_impl = | 242 virtual std::string EnclosingLevelDBDir() { |
220 static_cast<IndexedDBContextImpl*>(context.get()); | 243 return "migration_from_0"; |
221 FilePath dest = context_impl->data_path().Append(leveldb_dir); | |
222 // If we don't create the destination directory first, the contents of the | |
223 // leveldb directory are copied directly into profile/IndexedDB instead of | |
224 // profile/IndexedDB/file__0.xxx/ | |
225 ASSERT_TRUE(file_util::CreateDirectory(dest)); | |
226 const bool kRecursive = true; | |
227 ASSERT_TRUE(file_util::CopyDirectory(test_data_dir, | |
228 context_impl->data_path(), | |
229 kRecursive)); | |
230 } | 244 } |
231 }; | 245 }; |
232 | 246 |
233 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithVersion0Schema, MigrationTest) { | 247 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithVersion0Schema, MigrationTest) { |
234 SimpleTest(GetTestUrl("indexeddb", "migration_test.html")); | 248 SimpleTest(GetTestUrl("indexeddb", "migration_test.html")); |
235 } | 249 } |
236 | 250 |
| 251 class IndexedDBBrowserTestWithVersion123456Schema : public |
| 252 IndexedDBBrowserTestWithPreexisingLevelDB { |
| 253 protected: |
| 254 virtual void RequestDiskUsage() { |
| 255 BrowserThread::PostTaskAndReplyWithResult( |
| 256 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
| 257 base::Bind(&IndexedDBContext::GetOriginDiskUsage, GetContext(), |
| 258 GURL("file:///")), base::Bind( |
| 259 &IndexedDBBrowserTestWithVersion123456Schema::DidGetDiskUsage, |
| 260 this)); |
| 261 scoped_refptr<base::ThreadTestHelper> helper( |
| 262 new base::ThreadTestHelper(BrowserThread::GetMessageLoopProxyForThread( |
| 263 BrowserThread::WEBKIT_DEPRECATED))); |
| 264 ASSERT_TRUE(helper->Run()); |
| 265 // Wait for DidGetDiskUsage to be called. |
| 266 MessageLoop::current()->RunAllPending(); |
| 267 } |
| 268 |
| 269 virtual std::string EnclosingLevelDBDir() { |
| 270 return "schema_version_123456"; |
| 271 } |
| 272 int64 disk_usage_ = -1; |
| 273 private: |
| 274 virtual void DidGetDiskUsage(int64 bytes) { |
| 275 EXPECT_GT(bytes, 0); |
| 276 disk_usage_ = bytes; |
| 277 } |
| 278 }; |
| 279 |
| 280 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithVersion123456Schema, |
| 281 DestroyTest) { |
| 282 RequestDiskUsage(); |
| 283 int64 original_size = disk_usage_; |
| 284 EXPECT_GT(original_size, 0); |
| 285 SimpleTest(GetTestUrl("indexeddb", "invalid_schema.html")); |
| 286 RequestDiskUsage(); |
| 287 EXPECT_NE(original_size, disk_usage_); |
| 288 } |
| 289 |
237 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, LevelDBLogFileTest) { | 290 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, LevelDBLogFileTest) { |
238 // Any page that opens an IndexedDB will work here. | 291 // Any page that opens an IndexedDB will work here. |
239 SimpleTest(GetTestUrl("indexeddb", "database_test.html")); | 292 SimpleTest(GetTestUrl("indexeddb", "database_test.html")); |
240 scoped_refptr<IndexedDBContext> context = | 293 scoped_refptr<IndexedDBContext> context = |
241 BrowserContext::GetDefaultStoragePartition( | 294 BrowserContext::GetDefaultStoragePartition( |
242 shell()->web_contents()->GetBrowserContext())-> | 295 shell()->web_contents()->GetBrowserContext())-> |
243 GetIndexedDBContext(); | 296 GetIndexedDBContext(); |
244 IndexedDBContextImpl* context_impl = | 297 IndexedDBContextImpl* context_impl = |
245 static_cast<IndexedDBContextImpl*>(context.get()); | 298 static_cast<IndexedDBContextImpl*>(context.get()); |
246 FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb")); | 299 FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb")); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 TitleWatcher title_watcher(new_shell->web_contents(), expected_title16); | 353 TitleWatcher title_watcher(new_shell->web_contents(), expected_title16); |
301 | 354 |
302 base::KillProcess( | 355 base::KillProcess( |
303 shell()->web_contents()->GetRenderProcessHost()->GetHandle(), 0, true); | 356 shell()->web_contents()->GetRenderProcessHost()->GetHandle(), 0, true); |
304 shell()->Close(); | 357 shell()->Close(); |
305 | 358 |
306 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 359 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
307 } | 360 } |
308 | 361 |
309 } // namespace content | 362 } // namespace content |
OLD | NEW |