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

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

Issue 7480041: Adding session-only localStorage. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Streamlining: Moving ResourceContext& from DOMStorageContext to DOMMessageFilter. Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
8 #include "base/test/thread_test_helper.h" 8 #include "base/test/thread_test_helper.h"
9 #include "base/utf_string_conversions.h"
9 #include "chrome/test/in_process_browser_test.h" 10 #include "chrome/test/in_process_browser_test.h"
10 #include "chrome/test/testing_profile.h" 11 #include "chrome/test/testing_profile.h"
12 #include "content/browser/in_process_webkit/dom_storage_area.h"
11 #include "content/browser/in_process_webkit/dom_storage_context.h" 13 #include "content/browser/in_process_webkit/dom_storage_context.h"
14 #include "content/browser/in_process_webkit/dom_storage_message_filter.h"
15 #include "content/browser/in_process_webkit/dom_storage_namespace.h"
12 #include "content/browser/in_process_webkit/webkit_context.h" 16 #include "content/browser/in_process_webkit/webkit_context.h"
13 17
18 namespace base {
19 class MessageLoopProxy;
20 }
21
14 typedef InProcessBrowserTest DOMStorageBrowserTest; 22 typedef InProcessBrowserTest DOMStorageBrowserTest;
15 23
24 namespace dom_storage_test_helpers {
25
26 class ChangingSettingsTestHelper : public base::ThreadTestHelper {
27 public:
28 ChangingSettingsTestHelper(base::MessageLoopProxy* target_thread,
29 DOMStorageContext* storage_context)
30 : base::ThreadTestHelper(target_thread),
31 storage_context_(storage_context){
32 }
33 virtual ~ChangingSettingsTestHelper() {
34 }
35 void RunTest() {
36 DOMStorageNamespace* storage_namespace =
37 storage_context_->GetStorageNamespace(0, true);
38
39 // After a storage for an origin is created, it can always be retrieved,
40 // even if the content setting for that origin is changed.
41 string16 origin1(ASCIIToUTF16("http://www.someorigin.com"));
42 string16 origin2(ASCIIToUTF16("http://www.someotherorigin.com"));
43
44 DOMStorageArea* storage_area1 =
45 storage_namespace->GetStorageArea(origin1, true);
46 EXPECT_TRUE(storage_area1 != NULL);
47 EXPECT_TRUE(storage_area1 ==
48 storage_namespace->GetStorageArea(origin1, false));
49 EXPECT_TRUE(storage_area1 ==
50 storage_namespace->GetStorageArea(origin1, true));
51
52 DOMStorageArea* storage_area2 =
53 storage_namespace->GetStorageArea(origin2, false);
54 EXPECT_TRUE(storage_area2 != NULL);
55 EXPECT_TRUE(storage_area2 != storage_area1);
56 EXPECT_TRUE(storage_area2 ==
57 storage_namespace->GetStorageArea(origin2, false));
58 EXPECT_TRUE(storage_area2 ==
59 storage_namespace->GetStorageArea(origin2, true));
60 set_test_result(true);
61 }
62 DOMStorageContext* storage_context_;
63 };
64
65 class SessionOnlyTestHelper : public base::ThreadTestHelper {
66 public:
67 SessionOnlyTestHelper(base::MessageLoopProxy* target_thread,
68 DOMStorageContext* storage_context,
69 WebKitContext* webkit_context,
70 const content::ResourceContext& resource_context)
71 : base::ThreadTestHelper(target_thread),
72 storage_context_(storage_context),
73 webkit_context_(webkit_context),
74 resource_context_(resource_context) {
75 }
76 virtual ~SessionOnlyTestHelper() {
77 }
78 void RunTest() {
79 DOMStorageNamespace* storage_namespace =
80 storage_context_->GetStorageNamespace(0, true);
81
82 // Write data into the session-only localStorage and the permanent
83 // localStorage.
84 string16 session_only_origin(ASCIIToUTF16("http://www.sessiononly.com"));
85 string16 permanent_origin(ASCIIToUTF16("http://www.permanent.com"));
86
87 DOMStorageArea* session_only_storage_area =
88 storage_namespace->GetStorageArea(session_only_origin, true);
89 EXPECT_TRUE(session_only_storage_area != NULL);
90 DOMStorageArea* permanent_storage_area =
91 storage_namespace->GetStorageArea(permanent_origin, false);
92 EXPECT_TRUE(permanent_storage_area != NULL);
93
94 string16 key(ASCIIToUTF16("Key"));
95 string16 value(ASCIIToUTF16("Value"));
96 WebKit::WebStorageArea::Result result;
97 NullableString16 old_value;
98 scoped_refptr<DOMStorageMessageFilter> filter =
99 new DOMStorageMessageFilter(0, webkit_context_, resource_context_);
100
101 // Invoke DOMStorageArea::SetItem with this indirection, to have the message
102 // filters set up correctly.
103 filter->OnSetItem(session_only_storage_area->id(), key, value, GURL(""),
104 &result, &old_value);
105 EXPECT_TRUE(result == WebKit::WebStorageArea::ResultOK);
106 filter->OnSetItem(permanent_storage_area->id(), key, value, GURL(""),
107 &result, &old_value);
108 EXPECT_TRUE(result == WebKit::WebStorageArea::ResultOK);
109
110 set_test_result(true);
111 }
112 DOMStorageContext* storage_context_;
113 WebKitContext* webkit_context_;
114 const content::ResourceContext& resource_context_;
115 };
116
117 } // namespace dom_storage_test_helpers
118
16 // In proc browser test is needed here because ClearLocalState indirectly calls 119 // In proc browser test is needed here because ClearLocalState indirectly calls
17 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. 120 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin.
18 IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ClearLocalState) { 121 IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ClearLocalState) {
19 // Create test files. 122 // Create test files.
20 ScopedTempDir temp_dir; 123 ScopedTempDir temp_dir;
21 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 124 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
22 FilePath domstorage_dir = temp_dir.path().Append( 125 FilePath domstorage_dir = temp_dir.path().Append(
23 DOMStorageContext::kLocalStorageDirectory); 126 DOMStorageContext::kLocalStorageDirectory);
24 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir)); 127 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
25 128
(...skipping 19 matching lines...) Expand all
45 scoped_refptr<base::ThreadTestHelper> helper( 148 scoped_refptr<base::ThreadTestHelper> helper(
46 new base::ThreadTestHelper( 149 new base::ThreadTestHelper(
47 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT))); 150 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT)));
48 ASSERT_TRUE(helper->Run()); 151 ASSERT_TRUE(helper->Run());
49 152
50 // Because we specified https for scheme to be skipped the second file 153 // Because we specified https for scheme to be skipped the second file
51 // should survive and the first go into vanity. 154 // should survive and the first go into vanity.
52 ASSERT_FALSE(file_util::PathExists(temp_file_path_1)); 155 ASSERT_FALSE(file_util::PathExists(temp_file_path_1));
53 ASSERT_TRUE(file_util::PathExists(temp_file_path_2)); 156 ASSERT_TRUE(file_util::PathExists(temp_file_path_2));
54 } 157 }
158
159 IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, ChangingSettings) {
160 ScopedTempDir temp_dir;
161 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
162 FilePath domstorage_dir = temp_dir.path().Append(
163 DOMStorageContext::kLocalStorageDirectory);
164 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
165
166 TestingProfile profile;
167
168 scoped_refptr<dom_storage_test_helpers::ChangingSettingsTestHelper> helper(
169 new dom_storage_test_helpers::ChangingSettingsTestHelper(
170 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT),
171 profile.GetWebKitContext()->dom_storage_context()));
172 ASSERT_TRUE(helper->Run());
173 }
174
175 IN_PROC_BROWSER_TEST_F(DOMStorageBrowserTest, SessionOnly) {
176 ScopedTempDir temp_dir;
177 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
178 FilePath domstorage_dir = temp_dir.path().Append(
179 DOMStorageContext::kLocalStorageDirectory);
180 ASSERT_TRUE(file_util::CreateDirectory(domstorage_dir));
181
182 // Create the scope which will ensure we run the destructor of the webkit
183 // context which should trigger the clean up.
184 {
185 TestingProfile profile;
186 DOMStorageContext* storage_context =
187 profile.GetWebKitContext()->dom_storage_context();
188 storage_context->set_data_path(temp_dir.path());
189
190 scoped_refptr<dom_storage_test_helpers::SessionOnlyTestHelper> helper(
191 new dom_storage_test_helpers::SessionOnlyTestHelper(
192 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT),
193 storage_context,
194 profile.GetWebKitContext(),
195 profile.GetResourceContext()));
196 ASSERT_TRUE(helper->Run());
197 }
198 // Make sure we wait until the destructor has run.
199 scoped_refptr<base::ThreadTestHelper> helper(
200 new base::ThreadTestHelper(
201 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT)));
202 ASSERT_TRUE(helper->Run());
203
204 // Expected result: the database file for the permanent storage was created,
205 // but the database for the session only storage was not created.
206 FilePath::StringType session_only_database(
207 FILE_PATH_LITERAL("http_www.sessiononly.com_0"));
208 FilePath::StringType permanent_database(
209 FILE_PATH_LITERAL("http_www.permanent.com_0"));
210 session_only_database.append(DOMStorageContext::kLocalStorageExtension);
211 permanent_database.append(DOMStorageContext::kLocalStorageExtension);
212
213 FilePath session_only_database_path =
214 domstorage_dir.Append(session_only_database);
215 FilePath permanent_database_path =
216 domstorage_dir.Append(permanent_database);
217
218 EXPECT_FALSE(file_util::PathExists(session_only_database_path));
219 EXPECT_TRUE(file_util::PathExists(permanent_database_path));
220 }
OLDNEW
« no previous file with comments | « content/browser/content_browser_client.h ('k') | content/browser/in_process_webkit/dom_storage_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698