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

Side by Side Diff: content/browser/indexed_db/indexed_db_unittest.cc

Issue 16879013: Use chromium logic for database identifier<->origin conversions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove webkit/base/origin_url_conversions Created 7 years, 6 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "content/browser/browser_thread_impl.h" 7 #include "content/browser/browser_thread_impl.h"
8 #include "content/browser/indexed_db/indexed_db_context_impl.h" 8 #include "content/browser/indexed_db/indexed_db_context_impl.h"
9 #include "content/browser/indexed_db/webidbdatabase_impl.h" 9 #include "content/browser/indexed_db/webidbdatabase_impl.h"
10 #include "content/public/browser/storage_partition.h" 10 #include "content/public/browser/storage_partition.h"
11 #include "content/public/common/url_constants.h" 11 #include "content/public/common/url_constants.h"
12 #include "content/public/test/test_browser_context.h" 12 #include "content/public/test/test_browser_context.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/base/origin_url_conversions.h"
15 #include "webkit/browser/quota/mock_special_storage_policy.h" 14 #include "webkit/browser/quota/mock_special_storage_policy.h"
16 #include "webkit/browser/quota/quota_manager.h" 15 #include "webkit/browser/quota/quota_manager.h"
17 #include "webkit/browser/quota/special_storage_policy.h" 16 #include "webkit/browser/quota/special_storage_policy.h"
17 #include "webkit/common/database/database_identifier.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 class IndexedDBTest : public testing::Test { 21 class IndexedDBTest : public testing::Test {
22 public: 22 public:
23 IndexedDBTest() 23 IndexedDBTest()
24 : message_loop_(base::MessageLoop::TYPE_IO), 24 : message_loop_(base::MessageLoop::TYPE_IO),
25 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_), 25 webkit_thread_(BrowserThread::WEBKIT_DEPRECATED, &message_loop_),
26 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_), 26 file_thread_(BrowserThread::FILE_USER_BLOCKING, &message_loop_),
27 io_thread_(BrowserThread::IO, &message_loop_) {} 27 io_thread_(BrowserThread::IO, &message_loop_) {}
(...skipping 29 matching lines...) Expand all
57 // With the levelDB backend, these are directories. 57 // With the levelDB backend, these are directories.
58 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>( 58 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>(
59 BrowserContext::GetDefaultStoragePartition(&browser_context) 59 BrowserContext::GetDefaultStoragePartition(&browser_context)
60 ->GetIndexedDBContext()); 60 ->GetIndexedDBContext());
61 61
62 // Override the storage policy with our own. 62 // Override the storage policy with our own.
63 idb_context->special_storage_policy_ = special_storage_policy; 63 idb_context->special_storage_policy_ = special_storage_policy;
64 idb_context->set_data_path_for_testing(temp_dir.path()); 64 idb_context->set_data_path_for_testing(temp_dir.path());
65 65
66 normal_path = idb_context->GetFilePathForTesting( 66 normal_path = idb_context->GetFilePathForTesting(
67 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin)); 67 webkit_database::GetIdentifierFromOrigin(kNormalOrigin));
68 session_only_path = idb_context->GetFilePathForTesting( 68 session_only_path = idb_context->GetFilePathForTesting(
69 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin)); 69 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin));
70 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); 70 ASSERT_TRUE(file_util::CreateDirectory(normal_path));
71 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); 71 ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
72 message_loop_.RunUntilIdle(); 72 message_loop_.RunUntilIdle();
73 } 73 }
74 74
75 message_loop_.RunUntilIdle(); 75 message_loop_.RunUntilIdle();
76 76
77 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); 77 EXPECT_TRUE(file_util::DirectoryExists(normal_path));
78 EXPECT_FALSE(file_util::DirectoryExists(session_only_path)); 78 EXPECT_FALSE(file_util::DirectoryExists(session_only_path));
79 } 79 }
(...skipping 23 matching lines...) Expand all
103 ->GetIndexedDBContext()); 103 ->GetIndexedDBContext());
104 104
105 // Override the storage policy with our own. 105 // Override the storage policy with our own.
106 idb_context->special_storage_policy_ = special_storage_policy; 106 idb_context->special_storage_policy_ = special_storage_policy;
107 idb_context->set_data_path_for_testing(temp_dir.path()); 107 idb_context->set_data_path_for_testing(temp_dir.path());
108 108
109 // Save session state. This should bypass the destruction-time deletion. 109 // Save session state. This should bypass the destruction-time deletion.
110 idb_context->SetForceKeepSessionState(); 110 idb_context->SetForceKeepSessionState();
111 111
112 normal_path = idb_context->GetFilePathForTesting( 112 normal_path = idb_context->GetFilePathForTesting(
113 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin)); 113 webkit_database::GetIdentifierFromOrigin(kNormalOrigin));
114 session_only_path = idb_context->GetFilePathForTesting( 114 session_only_path = idb_context->GetFilePathForTesting(
115 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin)); 115 webkit_database::GetIdentifierFromOrigin(kSessionOnlyOrigin));
116 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); 116 ASSERT_TRUE(file_util::CreateDirectory(normal_path));
117 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); 117 ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
118 message_loop_.RunUntilIdle(); 118 message_loop_.RunUntilIdle();
119 } 119 }
120 120
121 // Make sure we wait until the destructor has run. 121 // Make sure we wait until the destructor has run.
122 message_loop_.RunUntilIdle(); 122 message_loop_.RunUntilIdle();
123 123
124 // No data was cleared because of SetForceKeepSessionState. 124 // No data was cleared because of SetForceKeepSessionState.
125 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); 125 EXPECT_TRUE(file_util::DirectoryExists(normal_path));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 const GURL kTestOrigin("http://test/"); 161 const GURL kTestOrigin("http://test/");
162 162
163 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>( 163 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>(
164 BrowserContext::GetDefaultStoragePartition(&browser_context) 164 BrowserContext::GetDefaultStoragePartition(&browser_context)
165 ->GetIndexedDBContext()); 165 ->GetIndexedDBContext());
166 166
167 idb_context->quota_manager_proxy_ = NULL; 167 idb_context->quota_manager_proxy_ = NULL;
168 idb_context->set_data_path_for_testing(temp_dir.path()); 168 idb_context->set_data_path_for_testing(temp_dir.path());
169 169
170 test_path = idb_context->GetFilePathForTesting( 170 test_path = idb_context->GetFilePathForTesting(
171 webkit_base::GetOriginIdentifierFromURL(kTestOrigin)); 171 webkit_database::GetIdentifierFromOrigin(kTestOrigin));
172 ASSERT_TRUE(file_util::CreateDirectory(test_path)); 172 ASSERT_TRUE(file_util::CreateDirectory(test_path));
173 173
174 const bool kExpectForceClose = true; 174 const bool kExpectForceClose = true;
175 175
176 MockWebIDBDatabase connection1(kExpectForceClose); 176 MockWebIDBDatabase connection1(kExpectForceClose);
177 idb_context->ConnectionOpened(kTestOrigin, &connection1); 177 idb_context->ConnectionOpened(kTestOrigin, &connection1);
178 178
179 MockWebIDBDatabase connection2(!kExpectForceClose); 179 MockWebIDBDatabase connection2(!kExpectForceClose);
180 idb_context->ConnectionOpened(kTestOrigin, &connection2); 180 idb_context->ConnectionOpened(kTestOrigin, &connection2);
181 idb_context->ConnectionClosed(kTestOrigin, &connection2); 181 idb_context->ConnectionClosed(kTestOrigin, &connection2);
182 182
183 idb_context->DeleteForOrigin(kTestOrigin); 183 idb_context->DeleteForOrigin(kTestOrigin);
184 184
185 message_loop_.RunUntilIdle(); 185 message_loop_.RunUntilIdle();
186 } 186 }
187 187
188 // Make sure we wait until the destructor has run. 188 // Make sure we wait until the destructor has run.
189 message_loop_.RunUntilIdle(); 189 message_loop_.RunUntilIdle();
190 190
191 EXPECT_FALSE(file_util::DirectoryExists(test_path)); 191 EXPECT_FALSE(file_util::DirectoryExists(test_path));
192 } 192 }
193 193
194 } // namespace content 194 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698