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

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

Issue 10447117: Unwire the clear on exit preference from the storage systems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 8 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/scoped_temp_dir.h" 6 #include "base/scoped_temp_dir.h"
7 #include "chrome/test/base/ui_test_utils.h" 7 #include "chrome/test/base/ui_test_utils.h"
8 #include "content/browser/browser_thread_impl.h" 8 #include "content/browser/browser_thread_impl.h"
9 #include "content/browser/in_process_webkit/indexed_db_context_impl.h" 9 #include "content/browser/in_process_webkit/indexed_db_context_impl.h"
10 #include "content/public/common/url_constants.h" 10 #include "content/public/common/url_constants.h"
(...skipping 18 matching lines...) Expand all
29 29
30 protected: 30 protected:
31 MessageLoop message_loop_; 31 MessageLoop message_loop_;
32 32
33 private: 33 private:
34 BrowserThreadImpl webkit_thread_; 34 BrowserThreadImpl webkit_thread_;
35 BrowserThreadImpl file_thread_; 35 BrowserThreadImpl file_thread_;
36 BrowserThreadImpl io_thread_; 36 BrowserThreadImpl io_thread_;
37 }; 37 };
38 38
39 TEST_F(IndexedDBTest, ClearLocalState) {
40 ScopedTempDir temp_dir;
41 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
42
43 FilePath protected_path;
44 FilePath unprotected_path;
45
46 // Create the scope which will ensure we run the destructor of the webkit
47 // context which should trigger the clean up.
48 {
49 TestBrowserContext browser_context;
50
51 // Test our assumptions about what is protected and what is not.
52 const GURL kProtectedOrigin("https://foo/");
53 const GURL kUnprotectedOrigin("http://foo/");
54 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
55 new quota::MockSpecialStoragePolicy;
56 special_storage_policy->AddProtected(kProtectedOrigin);
57 browser_context.SetSpecialStoragePolicy(special_storage_policy);
58 quota::SpecialStoragePolicy* policy =
59 browser_context.GetSpecialStoragePolicy();
60 ASSERT_TRUE(policy->IsStorageProtected(kProtectedOrigin));
61 ASSERT_FALSE(policy->IsStorageProtected(kUnprotectedOrigin));
62
63 // Create some indexedDB paths.
64 // With the levelDB backend, these are directories.
65 IndexedDBContextImpl* idb_context =
66 static_cast<IndexedDBContextImpl*>(
67 BrowserContext::GetIndexedDBContext(&browser_context));
68 idb_context->set_data_path_for_testing(temp_dir.path());
69 protected_path = idb_context->GetFilePathForTesting(
70 DatabaseUtil::GetOriginIdentifier(kProtectedOrigin));
71 unprotected_path = idb_context->GetFilePathForTesting(
72 DatabaseUtil::GetOriginIdentifier(kUnprotectedOrigin));
73 ASSERT_TRUE(file_util::CreateDirectory(protected_path));
74 ASSERT_TRUE(file_util::CreateDirectory(unprotected_path));
75
76 // Setup to clear all unprotected origins on exit.
77 idb_context->set_clear_local_state_on_exit(true);
78 message_loop_.RunAllPending();
79 }
80
81 // Make sure we wait until the destructor has run.
82 message_loop_.RunAllPending();
83
84 ASSERT_TRUE(file_util::DirectoryExists(protected_path));
85 ASSERT_FALSE(file_util::DirectoryExists(unprotected_path));
86 }
87
88 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) { 39 TEST_F(IndexedDBTest, ClearSessionOnlyDatabases) {
89 ScopedTempDir temp_dir; 40 ScopedTempDir temp_dir;
90 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 41 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
91 42
92 FilePath normal_path; 43 FilePath normal_path;
93 FilePath session_only_path; 44 FilePath session_only_path;
94 45
95 // Create the scope which will ensure we run the destructor of the webkit 46 // Create the scope which will ensure we run the destructor of the webkit
96 // context which should trigger the clean up. 47 // context which should trigger the clean up.
97 { 48 {
(...skipping 23 matching lines...) Expand all
121 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); 72 ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
122 message_loop_.RunAllPending(); 73 message_loop_.RunAllPending();
123 } 74 }
124 75
125 message_loop_.RunAllPending(); 76 message_loop_.RunAllPending();
126 77
127 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); 78 EXPECT_TRUE(file_util::DirectoryExists(normal_path));
128 EXPECT_FALSE(file_util::DirectoryExists(session_only_path)); 79 EXPECT_FALSE(file_util::DirectoryExists(session_only_path));
129 } 80 }
130 81
131 TEST_F(IndexedDBTest, SaveSessionState) { 82 TEST_F(IndexedDBTest, SetForceKeepSessionState) {
132 ScopedTempDir temp_dir; 83 ScopedTempDir temp_dir;
133 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 84 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
134 85
135 FilePath normal_path; 86 FilePath normal_path;
136 FilePath session_only_path; 87 FilePath session_only_path;
137 88
138 // Create the scope which will ensure we run the destructor of the webkit 89 // Create the scope which will ensure we run the destructor of the webkit
139 // context. 90 // context.
140 { 91 {
141 TestBrowserContext browser_context; 92 TestBrowserContext browser_context;
142 93
143 const GURL kNormalOrigin("http://normal/"); 94 const GURL kNormalOrigin("http://normal/");
144 const GURL kSessionOnlyOrigin("http://session-only/"); 95 const GURL kSessionOnlyOrigin("http://session-only/");
145 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 96 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
146 new quota::MockSpecialStoragePolicy; 97 new quota::MockSpecialStoragePolicy;
147 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); 98 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin);
148 99
149 // Create some indexedDB paths. 100 // Create some indexedDB paths.
150 // With the levelDB backend, these are directories. 101 // With the levelDB backend, these are directories.
151 IndexedDBContextImpl* idb_context = 102 IndexedDBContextImpl* idb_context =
152 static_cast<IndexedDBContextImpl*>( 103 static_cast<IndexedDBContextImpl*>(
153 BrowserContext::GetIndexedDBContext(&browser_context)); 104 BrowserContext::GetIndexedDBContext(&browser_context));
154 105
155 // Override the storage policy with our own. 106 // Override the storage policy with our own.
156 idb_context->special_storage_policy_ = special_storage_policy; 107 idb_context->special_storage_policy_ = special_storage_policy;
157 idb_context->set_clear_local_state_on_exit(true);
158 idb_context->set_data_path_for_testing(temp_dir.path()); 108 idb_context->set_data_path_for_testing(temp_dir.path());
159 109
160 // Save session state. This should bypass the destruction-time deletion. 110 // Save session state. This should bypass the destruction-time deletion.
161 idb_context->SaveSessionState(); 111 idb_context->SetForceKeepSessionState();
162 112
163 normal_path = idb_context->GetFilePathForTesting( 113 normal_path = idb_context->GetFilePathForTesting(
164 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); 114 DatabaseUtil::GetOriginIdentifier(kNormalOrigin));
165 session_only_path = idb_context->GetFilePathForTesting( 115 session_only_path = idb_context->GetFilePathForTesting(
166 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin)); 116 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin));
167 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); 117 ASSERT_TRUE(file_util::CreateDirectory(normal_path));
168 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); 118 ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
169 message_loop_.RunAllPending(); 119 message_loop_.RunAllPending();
170 } 120 }
171 121
172 // Make sure we wait until the destructor has run. 122 // Make sure we wait until the destructor has run.
173 message_loop_.RunAllPending(); 123 message_loop_.RunAllPending();
174 124
175 // No data was cleared because of SaveSessionState. 125 // No data was cleared because of SetForceKeepSessionState.
176 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); 126 EXPECT_TRUE(file_util::DirectoryExists(normal_path));
177 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); 127 EXPECT_TRUE(file_util::DirectoryExists(session_only_path));
178 } 128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698