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