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_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/thread_test_helper.h" | 13 #include "base/test/thread_test_helper.h" |
| 14 #include "content/browser/browser_main_loop.h" |
14 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 15 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
15 #include "content/browser/web_contents/web_contents_impl.h" | 16 #include "content/browser/web_contents/web_contents_impl.h" |
16 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/storage_partition.h" | 20 #include "content/public/browser/storage_partition.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
22 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
23 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 GURL url = GetTestUrl("indexeddb", filename); | 65 GURL url = GetTestUrl("indexeddb", filename); |
65 if (hash) | 66 if (hash) |
66 url = GURL(url.spec() + hash); | 67 url = GURL(url.spec() + hash); |
67 | 68 |
68 string16 expected_title16(ASCIIToUTF16(expected_string)); | 69 string16 expected_title16(ASCIIToUTF16(expected_string)); |
69 TitleWatcher title_watcher(shell->web_contents(), expected_title16); | 70 TitleWatcher title_watcher(shell->web_contents(), expected_title16); |
70 NavigateToURL(shell, url); | 71 NavigateToURL(shell, url); |
71 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 72 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
72 } | 73 } |
73 | 74 |
74 scoped_refptr<IndexedDBContext> GetContext() { | 75 IndexedDBContextImpl* GetContext() { |
75 StoragePartition* partition = | 76 StoragePartition* partition = |
76 BrowserContext::GetDefaultStoragePartition( | 77 BrowserContext::GetDefaultStoragePartition( |
77 shell()->web_contents()->GetBrowserContext()); | 78 shell()->web_contents()->GetBrowserContext()); |
78 return partition->GetIndexedDBContext(); | 79 return static_cast<IndexedDBContextImpl*>(partition->GetIndexedDBContext()); |
79 }; | 80 }; |
80 | 81 |
81 void SetQuota(int quotaKilobytes) { | 82 void SetQuota(int quotaKilobytes) { |
82 const int kTemporaryStorageQuotaSize = quotaKilobytes | 83 const int kTemporaryStorageQuotaSize = quotaKilobytes |
83 * 1024 * QuotaManager::kPerHostTemporaryPortion; | 84 * 1024 * QuotaManager::kPerHostTemporaryPortion; |
84 SetTempQuota(kTemporaryStorageQuotaSize, | 85 SetTempQuota(kTemporaryStorageQuotaSize, |
85 BrowserContext::GetDefaultStoragePartition( | 86 BrowserContext::GetDefaultStoragePartition( |
86 shell()->web_contents()->GetBrowserContext())->GetQuotaManager()); | 87 shell()->web_contents()->GetBrowserContext())->GetQuotaManager()); |
87 } | 88 } |
88 | 89 |
89 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { | 90 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { |
90 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 91 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
91 BrowserThread::PostTask( | 92 BrowserThread::PostTask( |
92 BrowserThread::IO, FROM_HERE, | 93 BrowserThread::IO, FROM_HERE, |
93 base::Bind(&IndexedDBBrowserTest::SetTempQuota, bytes, qm)); | 94 base::Bind(&IndexedDBBrowserTest::SetTempQuota, bytes, qm)); |
94 return; | 95 return; |
95 } | 96 } |
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
97 qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback()); | 98 qm->SetTemporaryGlobalOverrideQuota(bytes, quota::QuotaCallback()); |
98 // Don't return until the quota has been set. | 99 // Don't return until the quota has been set. |
99 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( | 100 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( |
100 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get())); | 101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB).get())); |
101 ASSERT_TRUE(helper->Run()); | 102 ASSERT_TRUE(helper->Run()); |
102 } | 103 } |
103 | 104 |
104 virtual int64 RequestDiskUsage() { | 105 virtual int64 RequestDiskUsage() { |
105 BrowserThread::PostTaskAndReplyWithResult( | 106 PostTaskAndReplyWithResult( |
106 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 107 GetContext()->TaskRunner(), |
107 base::Bind(&IndexedDBContext::GetOriginDiskUsage, GetContext(), | 108 FROM_HERE, |
108 GURL("file:///")), base::Bind( | 109 base::Bind(&IndexedDBContext::GetOriginDiskUsage, |
109 &IndexedDBBrowserTest::DidGetDiskUsage, this)); | 110 GetContext(), |
110 scoped_refptr<base::ThreadTestHelper> helper( | 111 GURL("file:///")), |
111 new base::ThreadTestHelper(BrowserThread::GetMessageLoopProxyForThread( | 112 base::Bind(&IndexedDBBrowserTest::DidGetDiskUsage, this)); |
112 BrowserThread::WEBKIT_DEPRECATED).get())); | 113 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( |
| 114 BrowserMainLoop::GetInstance()->indexed_db_thread() |
| 115 ->message_loop_proxy())); |
113 EXPECT_TRUE(helper->Run()); | 116 EXPECT_TRUE(helper->Run()); |
114 // Wait for DidGetDiskUsage to be called. | 117 // Wait for DidGetDiskUsage to be called. |
115 base::MessageLoop::current()->RunUntilIdle(); | 118 base::MessageLoop::current()->RunUntilIdle(); |
116 return disk_usage_; | 119 return disk_usage_; |
117 } | 120 } |
118 private: | 121 private: |
119 virtual void DidGetDiskUsage(int64 bytes) { | 122 virtual void DidGetDiskUsage(int64 bytes) { |
120 EXPECT_GT(bytes, 0); | 123 EXPECT_GT(bytes, 0); |
121 disk_usage_ = bytes; | 124 disk_usage_ = bytes; |
122 } | 125 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 }; | 224 }; |
222 | 225 |
223 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, | 226 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, |
224 DatabaseCallbacksTest) { | 227 DatabaseCallbacksTest) { |
225 SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html")); | 228 SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html")); |
226 } | 229 } |
227 | 230 |
228 static void CopyLevelDBToProfile(Shell* shell, | 231 static void CopyLevelDBToProfile(Shell* shell, |
229 scoped_refptr<IndexedDBContext> context, | 232 scoped_refptr<IndexedDBContext> context, |
230 const std::string& test_directory) { | 233 const std::string& test_directory) { |
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 234 DCHECK(context->TaskRunner()->RunsTasksOnCurrentThread()); |
232 base::FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb")); | 235 base::FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb")); |
233 base::FilePath test_data_dir = | 236 base::FilePath test_data_dir = |
234 GetTestFilePath("indexeddb", test_directory.c_str()).Append(leveldb_dir); | 237 GetTestFilePath("indexeddb", test_directory.c_str()).Append(leveldb_dir); |
235 IndexedDBContextImpl* context_impl = | 238 IndexedDBContextImpl* context_impl = |
236 static_cast<IndexedDBContextImpl*>(context.get()); | 239 static_cast<IndexedDBContextImpl*>(context.get()); |
237 base::FilePath dest = context_impl->data_path().Append(leveldb_dir); | 240 base::FilePath dest = context_impl->data_path().Append(leveldb_dir); |
238 // If we don't create the destination directory first, the contents of the | 241 // If we don't create the destination directory first, the contents of the |
239 // leveldb directory are copied directly into profile/IndexedDB instead of | 242 // leveldb directory are copied directly into profile/IndexedDB instead of |
240 // profile/IndexedDB/file__0.xxx/ | 243 // profile/IndexedDB/file__0.xxx/ |
241 ASSERT_TRUE(file_util::CreateDirectory(dest)); | 244 ASSERT_TRUE(file_util::CreateDirectory(dest)); |
242 const bool kRecursive = true; | 245 const bool kRecursive = true; |
243 ASSERT_TRUE(file_util::CopyDirectory(test_data_dir, | 246 ASSERT_TRUE(file_util::CopyDirectory(test_data_dir, |
244 context_impl->data_path(), | 247 context_impl->data_path(), |
245 kRecursive)); | 248 kRecursive)); |
246 } | 249 } |
247 | 250 |
248 class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest { | 251 class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest { |
249 public: | 252 public: |
250 virtual void SetUpOnMainThread() OVERRIDE { | 253 virtual void SetUpOnMainThread() OVERRIDE { |
251 scoped_refptr<IndexedDBContext> context = GetContext(); | 254 scoped_refptr<IndexedDBContextImpl> context = GetContext(); |
252 BrowserThread::PostTask( | 255 context->TaskRunner()->PostTask( |
253 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 256 FROM_HERE, |
254 base::Bind(&CopyLevelDBToProfile, shell(), context, | 257 base::Bind( |
255 EnclosingLevelDBDir())); | 258 &CopyLevelDBToProfile, shell(), context, EnclosingLevelDBDir())); |
256 scoped_refptr<base::ThreadTestHelper> helper( | 259 scoped_refptr<base::ThreadTestHelper> helper(new base::ThreadTestHelper( |
257 new base::ThreadTestHelper(BrowserThread::GetMessageLoopProxyForThread( | 260 BrowserMainLoop::GetInstance()->indexed_db_thread() |
258 BrowserThread::WEBKIT_DEPRECATED).get())); | 261 ->message_loop_proxy())); |
259 ASSERT_TRUE(helper->Run()); | 262 ASSERT_TRUE(helper->Run()); |
260 } | 263 } |
261 | 264 |
262 virtual std::string EnclosingLevelDBDir() = 0; | 265 virtual std::string EnclosingLevelDBDir() = 0; |
263 | 266 |
264 }; | 267 }; |
265 | 268 |
266 class IndexedDBBrowserTestWithVersion0Schema : public | 269 class IndexedDBBrowserTestWithVersion0Schema : public |
267 IndexedDBBrowserTestWithPreexistingLevelDB { | 270 IndexedDBBrowserTestWithPreexistingLevelDB { |
268 virtual std::string EnclosingLevelDBDir() OVERRIDE { | 271 virtual std::string EnclosingLevelDBDir() OVERRIDE { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 TitleWatcher title_watcher(new_shell->web_contents(), expected_title16); | 416 TitleWatcher title_watcher(new_shell->web_contents(), expected_title16); |
414 | 417 |
415 base::KillProcess( | 418 base::KillProcess( |
416 shell()->web_contents()->GetRenderProcessHost()->GetHandle(), 0, true); | 419 shell()->web_contents()->GetRenderProcessHost()->GetHandle(), 0, true); |
417 shell()->Close(); | 420 shell()->Close(); |
418 | 421 |
419 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 422 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
420 } | 423 } |
421 | 424 |
422 } // namespace content | 425 } // namespace content |
OLD | NEW |