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/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/public/browser/storage_partition.h" | 9 #include "content/public/browser/storage_partition.h" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 TestBrowserContext browser_context; | 48 TestBrowserContext browser_context; |
49 | 49 |
50 const GURL kNormalOrigin("http://normal/"); | 50 const GURL kNormalOrigin("http://normal/"); |
51 const GURL kSessionOnlyOrigin("http://session-only/"); | 51 const GURL kSessionOnlyOrigin("http://session-only/"); |
52 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 52 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
53 new quota::MockSpecialStoragePolicy; | 53 new quota::MockSpecialStoragePolicy; |
54 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); | 54 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); |
55 | 55 |
56 // Create some indexedDB paths. | 56 // Create some indexedDB paths. |
57 // With the levelDB backend, these are directories. | 57 // With the levelDB backend, these are directories. |
58 IndexedDBContextImpl* idb_context = | 58 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>( |
59 static_cast<IndexedDBContextImpl*>( | 59 BrowserContext::GetDefaultStoragePartition(&browser_context) |
60 BrowserContext::GetDefaultStoragePartition(&browser_context)-> | 60 ->GetIndexedDBContext()); |
61 GetIndexedDBContext()); | |
62 | 61 |
63 // Override the storage policy with our own. | 62 // Override the storage policy with our own. |
64 idb_context->special_storage_policy_ = special_storage_policy; | 63 idb_context->special_storage_policy_ = special_storage_policy; |
65 idb_context->set_data_path_for_testing(temp_dir.path()); | 64 idb_context->set_data_path_for_testing(temp_dir.path()); |
66 | 65 |
67 normal_path = idb_context->GetFilePathForTesting( | 66 normal_path = idb_context->GetFilePathForTesting( |
68 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin)); | 67 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin)); |
69 session_only_path = idb_context->GetFilePathForTesting( | 68 session_only_path = idb_context->GetFilePathForTesting( |
70 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin)); | 69 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin)); |
71 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | 70 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); |
(...skipping 20 matching lines...) Expand all Loading... |
92 TestBrowserContext browser_context; | 91 TestBrowserContext browser_context; |
93 | 92 |
94 const GURL kNormalOrigin("http://normal/"); | 93 const GURL kNormalOrigin("http://normal/"); |
95 const GURL kSessionOnlyOrigin("http://session-only/"); | 94 const GURL kSessionOnlyOrigin("http://session-only/"); |
96 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = | 95 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = |
97 new quota::MockSpecialStoragePolicy; | 96 new quota::MockSpecialStoragePolicy; |
98 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); | 97 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); |
99 | 98 |
100 // Create some indexedDB paths. | 99 // Create some indexedDB paths. |
101 // With the levelDB backend, these are directories. | 100 // With the levelDB backend, these are directories. |
102 IndexedDBContextImpl* idb_context = | 101 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>( |
103 static_cast<IndexedDBContextImpl*>( | 102 BrowserContext::GetDefaultStoragePartition(&browser_context) |
104 BrowserContext::GetDefaultStoragePartition(&browser_context)-> | 103 ->GetIndexedDBContext()); |
105 GetIndexedDBContext()); | |
106 | 104 |
107 // Override the storage policy with our own. | 105 // Override the storage policy with our own. |
108 idb_context->special_storage_policy_ = special_storage_policy; | 106 idb_context->special_storage_policy_ = special_storage_policy; |
109 idb_context->set_data_path_for_testing(temp_dir.path()); | 107 idb_context->set_data_path_for_testing(temp_dir.path()); |
110 | 108 |
111 // Save session state. This should bypass the destruction-time deletion. | 109 // Save session state. This should bypass the destruction-time deletion. |
112 idb_context->SetForceKeepSessionState(); | 110 idb_context->SetForceKeepSessionState(); |
113 | 111 |
114 normal_path = idb_context->GetFilePathForTesting( | 112 normal_path = idb_context->GetFilePathForTesting( |
115 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin)); | 113 webkit_base::GetOriginIdentifierFromURL(kNormalOrigin)); |
116 session_only_path = idb_context->GetFilePathForTesting( | 114 session_only_path = idb_context->GetFilePathForTesting( |
117 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin)); | 115 webkit_base::GetOriginIdentifierFromURL(kSessionOnlyOrigin)); |
118 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); | 116 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); |
119 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); | 117 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); |
120 message_loop_.RunUntilIdle(); | 118 message_loop_.RunUntilIdle(); |
121 } | 119 } |
122 | 120 |
123 // Make sure we wait until the destructor has run. | 121 // Make sure we wait until the destructor has run. |
124 message_loop_.RunUntilIdle(); | 122 message_loop_.RunUntilIdle(); |
125 | 123 |
126 // No data was cleared because of SetForceKeepSessionState. | 124 // No data was cleared because of SetForceKeepSessionState. |
127 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); | 125 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); |
128 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); | 126 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); |
129 } | 127 } |
130 | 128 |
131 class MockWebIDBDatabase : public WebKit::WebIDBDatabase | 129 class MockWebIDBDatabase : public WebKit::WebIDBDatabase { |
132 { | |
133 public: | 130 public: |
134 MockWebIDBDatabase(bool expect_force_close) | 131 MockWebIDBDatabase(bool expect_force_close) |
135 : expect_force_close_(expect_force_close), | 132 : expect_force_close_(expect_force_close), force_close_called_(false) {} |
136 force_close_called_(false) {} | |
137 | 133 |
138 virtual ~MockWebIDBDatabase() | 134 virtual ~MockWebIDBDatabase() { |
139 { | |
140 EXPECT_TRUE(force_close_called_ == expect_force_close_); | 135 EXPECT_TRUE(force_close_called_ == expect_force_close_); |
141 } | 136 } |
142 | 137 |
143 virtual void forceClose() | 138 virtual void forceClose() { |
144 { | |
145 ASSERT_TRUE(expect_force_close_); | 139 ASSERT_TRUE(expect_force_close_); |
146 force_close_called_ = true; | 140 force_close_called_ = true; |
147 } | 141 } |
148 | 142 |
149 private: | 143 private: |
150 bool expect_force_close_; | 144 bool expect_force_close_; |
151 bool force_close_called_; | 145 bool force_close_called_; |
152 }; | 146 }; |
153 | 147 |
154 | |
155 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { | 148 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { |
156 base::ScopedTempDir temp_dir; | 149 base::ScopedTempDir temp_dir; |
157 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 150 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
158 | 151 |
159 base::FilePath test_path; | 152 base::FilePath test_path; |
160 | 153 |
161 // Create the scope which will ensure we run the destructor of the webkit | 154 // Create the scope which will ensure we run the destructor of the webkit |
162 // context. | 155 // context. |
163 { | 156 { |
164 TestBrowserContext browser_context; | 157 TestBrowserContext browser_context; |
165 | 158 |
166 const GURL kTestOrigin("http://test/"); | 159 const GURL kTestOrigin("http://test/"); |
167 | 160 |
168 IndexedDBContextImpl* idb_context = | 161 IndexedDBContextImpl* idb_context = static_cast<IndexedDBContextImpl*>( |
169 static_cast<IndexedDBContextImpl*>( | 162 BrowserContext::GetDefaultStoragePartition(&browser_context) |
170 BrowserContext::GetDefaultStoragePartition(&browser_context)-> | 163 ->GetIndexedDBContext()); |
171 GetIndexedDBContext()); | |
172 | 164 |
173 idb_context->quota_manager_proxy_ = NULL; | 165 idb_context->quota_manager_proxy_ = NULL; |
174 idb_context->set_data_path_for_testing(temp_dir.path()); | 166 idb_context->set_data_path_for_testing(temp_dir.path()); |
175 | 167 |
176 test_path = idb_context->GetFilePathForTesting( | 168 test_path = idb_context->GetFilePathForTesting( |
177 webkit_base::GetOriginIdentifierFromURL(kTestOrigin)); | 169 webkit_base::GetOriginIdentifierFromURL(kTestOrigin)); |
178 ASSERT_TRUE(file_util::CreateDirectory(test_path)); | 170 ASSERT_TRUE(file_util::CreateDirectory(test_path)); |
179 | 171 |
180 const bool kExpectForceClose = true; | 172 const bool kExpectForceClose = true; |
181 | 173 |
182 MockWebIDBDatabase connection1(kExpectForceClose); | 174 MockWebIDBDatabase connection1(kExpectForceClose); |
183 idb_context->ConnectionOpened(kTestOrigin, &connection1); | 175 idb_context->ConnectionOpened(kTestOrigin, &connection1); |
184 | 176 |
185 MockWebIDBDatabase connection2(!kExpectForceClose); | 177 MockWebIDBDatabase connection2(!kExpectForceClose); |
186 idb_context->ConnectionOpened(kTestOrigin, &connection2); | 178 idb_context->ConnectionOpened(kTestOrigin, &connection2); |
187 idb_context->ConnectionClosed(kTestOrigin, &connection2); | 179 idb_context->ConnectionClosed(kTestOrigin, &connection2); |
188 | 180 |
189 idb_context->DeleteForOrigin(kTestOrigin); | 181 idb_context->DeleteForOrigin(kTestOrigin); |
190 | 182 |
191 message_loop_.RunUntilIdle(); | 183 message_loop_.RunUntilIdle(); |
192 } | 184 } |
193 | 185 |
194 // Make sure we wait until the destructor has run. | 186 // Make sure we wait until the destructor has run. |
195 message_loop_.RunUntilIdle(); | 187 message_loop_.RunUntilIdle(); |
196 | 188 |
197 EXPECT_FALSE(file_util::DirectoryExists(test_path)); | 189 EXPECT_FALSE(file_util::DirectoryExists(test_path)); |
198 } | 190 } |
199 | 191 |
200 } // namespace content | 192 } // namespace content |
OLD | NEW |