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

Side by Side Diff: chrome/browser/extensions/web_view_browsertest.cc

Issue 11366140: Fix on-disk structure for persistent storage in webview tags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Charlie's comments Created 8 years, 1 month 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view_isolation/main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/automation/automation_util.h" 6 #include "chrome/browser/automation/automation_util.h"
7 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 7 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
8 #include "chrome/browser/ui/browser_tabstrip.h" 8 #include "chrome/browser/ui/browser_tabstrip.h"
9 #include "chrome/test/base/ui_test_utils.h" 9 #include "chrome/test/base/ui_test_utils.h"
10 #include "chrome/test/base/test_launcher_utils.h" 10 #include "chrome/test/base/test_launcher_utils.h"
(...skipping 14 matching lines...) Expand all
25 #endif 25 #endif
26 ui::DisableTestCompositor(); 26 ui::DisableTestCompositor();
27 } 27 }
28 28
29 // This method is responsible for initializing a packaged app, which contains 29 // This method is responsible for initializing a packaged app, which contains
30 // multiple webview tags. The tags have different partition identifiers and 30 // multiple webview tags. The tags have different partition identifiers and
31 // their WebContent objects are returned as output. The method also verifies 31 // their WebContent objects are returned as output. The method also verifies
32 // the expected process allocation and storage partition assignment. 32 // the expected process allocation and storage partition assignment.
33 // The |navigate_to_url| parameter is used to navigate the main browser 33 // The |navigate_to_url| parameter is used to navigate the main browser
34 // window. 34 // window.
35 //
36 // TODO(ajwong): This function is getting to be too large. Either refactor it
37 // so the test can specify a configuration of WebView tags that we will
38 // dynamically inject JS to generate, or move this test wholesale into
39 // something that RunPlatformAppTest() can execute purely in Javascript. This
40 // won't let us do a white-box examination of the StoragePartition equivalence
41 // directly, but we will be able to view the black box effects which is good
42 // enough. http://crbug.com/160361
35 void NavigateAndOpenAppForIsolation( 43 void NavigateAndOpenAppForIsolation(
36 GURL navigate_to_url, 44 GURL navigate_to_url,
37 content::WebContents** default_tag_contents1, 45 content::WebContents** default_tag_contents1,
38 content::WebContents** default_tag_contents2, 46 content::WebContents** default_tag_contents2,
39 content::WebContents** named_partition_contents1, 47 content::WebContents** named_partition_contents1,
40 content::WebContents** named_partition_contents2) { 48 content::WebContents** named_partition_contents2,
49 content::WebContents** persistent_partition_contents1,
50 content::WebContents** persistent_partition_contents2,
51 content::WebContents** persistent_partition_contents3) {
41 GURL::Replacements replace_host; 52 GURL::Replacements replace_host;
42 std::string host_str("localhost"); // Must stay in scope with replace_host. 53 std::string host_str("localhost"); // Must stay in scope with replace_host.
43 replace_host.SetHostStr(host_str); 54 replace_host.SetHostStr(host_str);
44 55
45 navigate_to_url = navigate_to_url.ReplaceComponents(replace_host); 56 navigate_to_url = navigate_to_url.ReplaceComponents(replace_host);
46 57
47 GURL tag_url1 = test_server()->GetURL( 58 GURL tag_url1 = test_server()->GetURL(
48 "files/extensions/platform_apps/web_view_isolation/cookie.html"); 59 "files/extensions/platform_apps/web_view_isolation/cookie.html");
49 tag_url1 = tag_url1.ReplaceComponents(replace_host); 60 tag_url1 = tag_url1.ReplaceComponents(replace_host);
50 GURL tag_url2 = test_server()->GetURL( 61 GURL tag_url2 = test_server()->GetURL(
51 "files/extensions/platform_apps/web_view_isolation/cookie2.html"); 62 "files/extensions/platform_apps/web_view_isolation/cookie2.html");
52 tag_url2 = tag_url2.ReplaceComponents(replace_host); 63 tag_url2 = tag_url2.ReplaceComponents(replace_host);
53 GURL tag_url3 = test_server()->GetURL( 64 GURL tag_url3 = test_server()->GetURL(
54 "files/extensions/platform_apps/web_view_isolation/storage1.html"); 65 "files/extensions/platform_apps/web_view_isolation/storage1.html");
55 tag_url3 = tag_url3.ReplaceComponents(replace_host); 66 tag_url3 = tag_url3.ReplaceComponents(replace_host);
56 GURL tag_url4 = test_server()->GetURL( 67 GURL tag_url4 = test_server()->GetURL(
57 "files/extensions/platform_apps/web_view_isolation/storage2.html"); 68 "files/extensions/platform_apps/web_view_isolation/storage2.html");
58 tag_url4 = tag_url4.ReplaceComponents(replace_host); 69 tag_url4 = tag_url4.ReplaceComponents(replace_host);
70 GURL tag_url5 = test_server()->GetURL(
71 "files/extensions/platform_apps/web_view_isolation/storage1.html#p1");
72 tag_url5 = tag_url5.ReplaceComponents(replace_host);
73 GURL tag_url6 = test_server()->GetURL(
74 "files/extensions/platform_apps/web_view_isolation/storage1.html#p2");
75 tag_url6 = tag_url6.ReplaceComponents(replace_host);
76 GURL tag_url7 = test_server()->GetURL(
77 "files/extensions/platform_apps/web_view_isolation/storage1.html#p3");
78 tag_url7 = tag_url7.ReplaceComponents(replace_host);
59 79
60 ui_test_utils::NavigateToURLWithDisposition( 80 ui_test_utils::NavigateToURLWithDisposition(
61 browser(), navigate_to_url, CURRENT_TAB, 81 browser(), navigate_to_url, CURRENT_TAB,
62 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 82 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
63 83
64 ui_test_utils::UrlLoadObserver observer1( 84 ui_test_utils::UrlLoadObserver observer1(
65 tag_url1, content::NotificationService::AllSources()); 85 tag_url1, content::NotificationService::AllSources());
66 ui_test_utils::UrlLoadObserver observer2( 86 ui_test_utils::UrlLoadObserver observer2(
67 tag_url2, content::NotificationService::AllSources()); 87 tag_url2, content::NotificationService::AllSources());
68 ui_test_utils::UrlLoadObserver observer3( 88 ui_test_utils::UrlLoadObserver observer3(
69 tag_url3, content::NotificationService::AllSources()); 89 tag_url3, content::NotificationService::AllSources());
70 ui_test_utils::UrlLoadObserver observer4( 90 ui_test_utils::UrlLoadObserver observer4(
71 tag_url4, content::NotificationService::AllSources()); 91 tag_url4, content::NotificationService::AllSources());
92 ui_test_utils::UrlLoadObserver observer5(
93 tag_url5, content::NotificationService::AllSources());
94 ui_test_utils::UrlLoadObserver observer6(
95 tag_url6, content::NotificationService::AllSources());
96 ui_test_utils::UrlLoadObserver observer7(
97 tag_url7, content::NotificationService::AllSources());
72 LoadAndLaunchPlatformApp("web_view_isolation"); 98 LoadAndLaunchPlatformApp("web_view_isolation");
73 observer1.Wait(); 99 observer1.Wait();
74 observer2.Wait(); 100 observer2.Wait();
75 observer3.Wait(); 101 observer3.Wait();
76 observer4.Wait(); 102 observer4.Wait();
103 observer5.Wait();
104 observer6.Wait();
105 observer7.Wait();
77 106
78 content::Source<content::NavigationController> source1 = observer1.source(); 107 content::Source<content::NavigationController> source1 = observer1.source();
79 EXPECT_TRUE(source1->GetWebContents()->GetRenderProcessHost()->IsGuest()); 108 EXPECT_TRUE(source1->GetWebContents()->GetRenderProcessHost()->IsGuest());
80 content::Source<content::NavigationController> source2 = observer2.source(); 109 content::Source<content::NavigationController> source2 = observer2.source();
81 EXPECT_TRUE(source2->GetWebContents()->GetRenderProcessHost()->IsGuest()); 110 EXPECT_TRUE(source2->GetWebContents()->GetRenderProcessHost()->IsGuest());
82 content::Source<content::NavigationController> source3 = observer3.source(); 111 content::Source<content::NavigationController> source3 = observer3.source();
83 EXPECT_TRUE(source3->GetWebContents()->GetRenderProcessHost()->IsGuest()); 112 EXPECT_TRUE(source3->GetWebContents()->GetRenderProcessHost()->IsGuest());
84 content::Source<content::NavigationController> source4 = observer4.source(); 113 content::Source<content::NavigationController> source4 = observer4.source();
85 EXPECT_TRUE(source4->GetWebContents()->GetRenderProcessHost()->IsGuest()); 114 EXPECT_TRUE(source4->GetWebContents()->GetRenderProcessHost()->IsGuest());
115 content::Source<content::NavigationController> source5 = observer5.source();
116 EXPECT_TRUE(source5->GetWebContents()->GetRenderProcessHost()->IsGuest());
117 content::Source<content::NavigationController> source6 = observer6.source();
118 EXPECT_TRUE(source6->GetWebContents()->GetRenderProcessHost()->IsGuest());
119 content::Source<content::NavigationController> source7 = observer7.source();
120 EXPECT_TRUE(source7->GetWebContents()->GetRenderProcessHost()->IsGuest());
86 121
87 // Check that the first two tags use the same process and it is different 122 // Check that the first two tags use the same process and it is different
88 // than the process used by the other two. 123 // than the process used by the other two.
89 EXPECT_EQ(source1->GetWebContents()->GetRenderProcessHost()->GetID(), 124 EXPECT_EQ(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
90 source2->GetWebContents()->GetRenderProcessHost()->GetID()); 125 source2->GetWebContents()->GetRenderProcessHost()->GetID());
91 EXPECT_EQ(source3->GetWebContents()->GetRenderProcessHost()->GetID(), 126 EXPECT_EQ(source3->GetWebContents()->GetRenderProcessHost()->GetID(),
92 source4->GetWebContents()->GetRenderProcessHost()->GetID()); 127 source4->GetWebContents()->GetRenderProcessHost()->GetID());
93 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(), 128 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(),
94 source3->GetWebContents()->GetRenderProcessHost()->GetID()); 129 source3->GetWebContents()->GetRenderProcessHost()->GetID());
95 130
(...skipping 16 matching lines...) Expand all
112 source3->GetWebContents()->GetRenderProcessHost()-> 147 source3->GetWebContents()->GetRenderProcessHost()->
113 GetStoragePartition(), 148 GetStoragePartition(),
114 source4->GetWebContents()->GetRenderProcessHost()-> 149 source4->GetWebContents()->GetRenderProcessHost()->
115 GetStoragePartition()); 150 GetStoragePartition());
116 EXPECT_NE( 151 EXPECT_NE(
117 source1->GetWebContents()->GetRenderProcessHost()-> 152 source1->GetWebContents()->GetRenderProcessHost()->
118 GetStoragePartition(), 153 GetStoragePartition(),
119 source3->GetWebContents()->GetRenderProcessHost()-> 154 source3->GetWebContents()->GetRenderProcessHost()->
120 GetStoragePartition()); 155 GetStoragePartition());
121 156
157 // Ensure the persistent storage partitions are different.
158 EXPECT_EQ(
159 source5->GetWebContents()->GetRenderProcessHost()->
160 GetStoragePartition(),
161 source6->GetWebContents()->GetRenderProcessHost()->
162 GetStoragePartition());
163 EXPECT_NE(
164 source5->GetWebContents()->GetRenderProcessHost()->
165 GetStoragePartition(),
166 source7->GetWebContents()->GetRenderProcessHost()->
167 GetStoragePartition());
168 EXPECT_NE(
169 source1->GetWebContents()->GetRenderProcessHost()->
170 GetStoragePartition(),
171 source5->GetWebContents()->GetRenderProcessHost()->
172 GetStoragePartition());
173 EXPECT_NE(
174 source1->GetWebContents()->GetRenderProcessHost()->
175 GetStoragePartition(),
176 source7->GetWebContents()->GetRenderProcessHost()->
177 GetStoragePartition());
178
122 *default_tag_contents1 = source1->GetWebContents(); 179 *default_tag_contents1 = source1->GetWebContents();
123 *default_tag_contents2 = source2->GetWebContents(); 180 *default_tag_contents2 = source2->GetWebContents();
124 *named_partition_contents1 = source3->GetWebContents(); 181 *named_partition_contents1 = source3->GetWebContents();
125 *named_partition_contents2 = source4->GetWebContents(); 182 *named_partition_contents2 = source4->GetWebContents();
183 if (persistent_partition_contents1) {
184 *persistent_partition_contents1 = source5->GetWebContents();
185 }
186 if (persistent_partition_contents2) {
187 *persistent_partition_contents2 = source6->GetWebContents();
188 }
189 if (persistent_partition_contents3) {
190 *persistent_partition_contents3 = source7->GetWebContents();
191 }
126 } 192 }
127 193
128 void ExecuteScriptWaitForTitle(content::WebContents* web_contents, 194 void ExecuteScriptWaitForTitle(content::WebContents* web_contents,
129 const char* script, 195 const char* script,
130 const char* title) { 196 const char* title) {
131 std::wstring js_script = ASCIIToWide(script); 197 std::wstring js_script = ASCIIToWide(script);
132 string16 expected_title(ASCIIToUTF16(title)); 198 string16 expected_title(ASCIIToUTF16(title));
133 string16 error_title(ASCIIToUTF16("error")); 199 string16 error_title(ASCIIToUTF16("error"));
134 200
135 content::TitleWatcher title_watcher(web_contents, expected_title); 201 content::TitleWatcher title_watcher(web_contents, expected_title);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // The first two partitions will be used to set cookies and ensure they are 241 // The first two partitions will be used to set cookies and ensure they are
176 // shared. The named partition is used to ensure that cookies are isolated 242 // shared. The named partition is used to ensure that cookies are isolated
177 // between partitions within the same app. 243 // between partitions within the same app.
178 content::WebContents* cookie_contents1; 244 content::WebContents* cookie_contents1;
179 content::WebContents* cookie_contents2; 245 content::WebContents* cookie_contents2;
180 content::WebContents* named_partition_contents1; 246 content::WebContents* named_partition_contents1;
181 content::WebContents* named_partition_contents2; 247 content::WebContents* named_partition_contents2;
182 248
183 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, 249 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1,
184 &cookie_contents2, &named_partition_contents1, 250 &cookie_contents2, &named_partition_contents1,
185 &named_partition_contents2); 251 &named_partition_contents2, NULL, NULL, NULL);
186 252
187 EXPECT_TRUE(content::ExecuteJavaScript( 253 EXPECT_TRUE(content::ExecuteJavaScript(
188 cookie_contents1->GetRenderViewHost(), std::wstring(), cookie_script1)); 254 cookie_contents1->GetRenderViewHost(), std::wstring(), cookie_script1));
189 EXPECT_TRUE(content::ExecuteJavaScript( 255 EXPECT_TRUE(content::ExecuteJavaScript(
190 cookie_contents2->GetRenderViewHost(), std::wstring(), cookie_script2)); 256 cookie_contents2->GetRenderViewHost(), std::wstring(), cookie_script2));
191 257
192 int cookie_size; 258 int cookie_size;
193 std::string cookie_value; 259 std::string cookie_value;
194 260
195 // Test the regular browser context to ensure we have only one cookie. 261 // Test the regular browser context to ensure we have only one cookie.
(...skipping 16 matching lines...) Expand all
212 &cookie_size, &cookie_value); 278 &cookie_size, &cookie_value);
213 EXPECT_EQ("guest1=true; guest2=true", cookie_value); 279 EXPECT_EQ("guest1=true; guest2=true", cookie_value);
214 280
215 // The third tag should not have any cookies as it is in a separate partition. 281 // The third tag should not have any cookies as it is in a separate partition.
216 automation_util::GetCookies(GURL("http://localhost"), 282 automation_util::GetCookies(GURL("http://localhost"),
217 named_partition_contents1, 283 named_partition_contents1,
218 &cookie_size, &cookie_value); 284 &cookie_size, &cookie_value);
219 EXPECT_EQ("", cookie_value); 285 EXPECT_EQ("", cookie_value);
220 } 286 }
221 287
288 // This tests that in-memory storage partitions are reset on browser restart,
289 // but persistent ones maintain state for cookies and HTML5 storage.
290 IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) {
291 ASSERT_TRUE(StartTestServer());
292 const std::wstring kExpire =
293 L"var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
294 std::wstring cookie_script1(kExpire);
295 cookie_script1.append(
296 L"document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';");
297 std::wstring cookie_script2(kExpire);
298 cookie_script2.append(
299 L"document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
300 std::wstring cookie_script3(kExpire);
301 cookie_script3.append(
302 L"document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
303
304 // We don't care where the main browser is on this test.
305 GURL blank_url("about:blank");
306
307 // The first two partitions will be used to set cookies and ensure they are
308 // shared. The named partition is used to ensure that cookies are isolated
309 // between partitions within the same app.
310 content::WebContents* cookie_contents1;
311 content::WebContents* cookie_contents2;
312 content::WebContents* named_partition_contents1;
313 content::WebContents* named_partition_contents2;
314 content::WebContents* persistent_partition_contents1;
315 content::WebContents* persistent_partition_contents2;
316 content::WebContents* persistent_partition_contents3;
317 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
318 &cookie_contents2, &named_partition_contents1,
319 &named_partition_contents2,
320 &persistent_partition_contents1,
321 &persistent_partition_contents2,
322 &persistent_partition_contents3);
323
324 // Set the inmemory=true cookie for tags with inmemory partitions.
325 EXPECT_TRUE(content::ExecuteJavaScript(
326 cookie_contents1->GetRenderViewHost(), std::wstring(),
327 cookie_script1));
328 EXPECT_TRUE(content::ExecuteJavaScript(
329 named_partition_contents1->GetRenderViewHost(), std::wstring(),
330 cookie_script1));
331
332 // For the two different persistent storage partitions, set the
333 // two different cookies so we can check that they aren't comingled below.
334 EXPECT_TRUE(content::ExecuteJavaScript(
335 persistent_partition_contents1->GetRenderViewHost(), std::wstring(),
336 cookie_script2));
337
338 EXPECT_TRUE(content::ExecuteJavaScript(
339 persistent_partition_contents3->GetRenderViewHost(), std::wstring(),
340 cookie_script3));
341
342 int cookie_size;
343 std::string cookie_value;
344
345 // Check that all in-memory partitions have a cookie set.
346 automation_util::GetCookies(GURL("http://localhost"),
347 cookie_contents1,
348 &cookie_size, &cookie_value);
349 EXPECT_EQ("inmemory=true", cookie_value);
350 automation_util::GetCookies(GURL("http://localhost"),
351 cookie_contents2,
352 &cookie_size, &cookie_value);
353 EXPECT_EQ("inmemory=true", cookie_value);
354 automation_util::GetCookies(GURL("http://localhost"),
355 named_partition_contents1,
356 &cookie_size, &cookie_value);
357 EXPECT_EQ("inmemory=true", cookie_value);
358 automation_util::GetCookies(GURL("http://localhost"),
359 named_partition_contents2,
360 &cookie_size, &cookie_value);
361 EXPECT_EQ("inmemory=true", cookie_value);
362
363 // Check that all persistent partitions kept their state.
364 automation_util::GetCookies(GURL("http://localhost"),
365 persistent_partition_contents1,
366 &cookie_size, &cookie_value);
367 EXPECT_EQ("persist1=true", cookie_value);
368 automation_util::GetCookies(GURL("http://localhost"),
369 persistent_partition_contents2,
370 &cookie_size, &cookie_value);
371 EXPECT_EQ("persist1=true", cookie_value);
372 automation_util::GetCookies(GURL("http://localhost"),
373 persistent_partition_contents3,
374 &cookie_size, &cookie_value);
375 EXPECT_EQ("persist2=true", cookie_value);
376 }
377
378 // This is the post-reset portion of the StoragePersistence test. See
379 // PRE_StoragePersistence for main comment.
380 IN_PROC_BROWSER_TEST_F(WebViewTest, StoragePersistence) {
381 ASSERT_TRUE(StartTestServer());
382
383 // We don't care where the main browser is on this test.
384 GURL blank_url("about:blank");
385
386 // The first two partitions will be used to set cookies and ensure they are
387 // shared. The named partition is used to ensure that cookies are isolated
388 // between partitions within the same app.
389 content::WebContents* cookie_contents1;
390 content::WebContents* cookie_contents2;
391 content::WebContents* named_partition_contents1;
392 content::WebContents* named_partition_contents2;
393 content::WebContents* persistent_partition_contents1;
394 content::WebContents* persistent_partition_contents2;
395 content::WebContents* persistent_partition_contents3;
396 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
397 &cookie_contents2, &named_partition_contents1,
398 &named_partition_contents2,
399 &persistent_partition_contents1,
400 &persistent_partition_contents2,
401 &persistent_partition_contents3);
402
403 int cookie_size;
404 std::string cookie_value;
405
406 // Check that all in-memory partitions lost their state.
407 automation_util::GetCookies(GURL("http://localhost"),
408 cookie_contents1,
409 &cookie_size, &cookie_value);
410 EXPECT_EQ("", cookie_value);
411 automation_util::GetCookies(GURL("http://localhost"),
412 cookie_contents2,
413 &cookie_size, &cookie_value);
414 EXPECT_EQ("", cookie_value);
415 automation_util::GetCookies(GURL("http://localhost"),
416 named_partition_contents1,
417 &cookie_size, &cookie_value);
418 EXPECT_EQ("", cookie_value);
419 automation_util::GetCookies(GURL("http://localhost"),
420 named_partition_contents2,
421 &cookie_size, &cookie_value);
422 EXPECT_EQ("", cookie_value);
423
424 // Check that all persistent partitions kept their state.
425 automation_util::GetCookies(GURL("http://localhost"),
426 persistent_partition_contents1,
427 &cookie_size, &cookie_value);
428 EXPECT_EQ("persist1=true", cookie_value);
429 automation_util::GetCookies(GURL("http://localhost"),
430 persistent_partition_contents2,
431 &cookie_size, &cookie_value);
432 EXPECT_EQ("persist1=true", cookie_value);
433 automation_util::GetCookies(GURL("http://localhost"),
434 persistent_partition_contents3,
435 &cookie_size, &cookie_value);
436 EXPECT_EQ("persist2=true", cookie_value);
437 }
438
222 // This tests DOM storage isolation for packaged apps with webview tags. It 439 // This tests DOM storage isolation for packaged apps with webview tags. It
223 // loads an app with multiple webview tags and each tag sets DOM storage 440 // loads an app with multiple webview tags and each tag sets DOM storage
224 // entries, which the test checks to ensure proper storage isolation is 441 // entries, which the test checks to ensure proper storage isolation is
225 // enforced. 442 // enforced.
226 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) { 443 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) {
227 ASSERT_TRUE(StartTestServer()); 444 ASSERT_TRUE(StartTestServer());
228 GURL regular_url = test_server()->GetURL("files/title1.html"); 445 GURL regular_url = test_server()->GetURL("files/title1.html");
229 446
230 std::string output; 447 std::string output;
231 std::wstring get_local_storage(L"window.domAutomationController.send(" 448 std::wstring get_local_storage(L"window.domAutomationController.send("
232 L"window.localStorage.getItem('foo') || 'badval')"); 449 L"window.localStorage.getItem('foo') || 'badval')");
233 std::wstring get_session_storage(L"window.domAutomationController.send(" 450 std::wstring get_session_storage(L"window.domAutomationController.send("
234 L"window.sessionStorage.getItem('bar') || 'badval')"); 451 L"window.sessionStorage.getItem('bar') || 'badval')");
235 452
236 content::WebContents* default_tag_contents1; 453 content::WebContents* default_tag_contents1;
237 content::WebContents* default_tag_contents2; 454 content::WebContents* default_tag_contents2;
238 content::WebContents* storage_contents1; 455 content::WebContents* storage_contents1;
239 content::WebContents* storage_contents2; 456 content::WebContents* storage_contents2;
240 457
241 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, 458 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
242 &default_tag_contents2, &storage_contents1, 459 &default_tag_contents2, &storage_contents1,
243 &storage_contents2); 460 &storage_contents2, NULL, NULL, NULL);
244 461
245 // Initialize the storage for the first of the two tags that share a storage 462 // Initialize the storage for the first of the two tags that share a storage
246 // partition. 463 // partition.
247 EXPECT_TRUE(content::ExecuteJavaScript( 464 EXPECT_TRUE(content::ExecuteJavaScript(
248 storage_contents1->GetRenderViewHost(), std::wstring(), 465 storage_contents1->GetRenderViewHost(), std::wstring(),
249 L"initDomStorage('page1')")); 466 L"initDomStorage('page1')"));
250 467
251 // Let's test that the expected values are present in the first tag, as they 468 // Let's test that the expected values are present in the first tag, as they
252 // will be overwritten once we call the initDomStorage on the second tag. 469 // will be overwritten once we call the initDomStorage on the second tag.
253 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( 470 EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ASSERT_TRUE(StartTestServer()); 531 ASSERT_TRUE(StartTestServer());
315 GURL regular_url = test_server()->GetURL("files/title1.html"); 532 GURL regular_url = test_server()->GetURL("files/title1.html");
316 533
317 content::WebContents* default_tag_contents1; 534 content::WebContents* default_tag_contents1;
318 content::WebContents* default_tag_contents2; 535 content::WebContents* default_tag_contents2;
319 content::WebContents* storage_contents1; 536 content::WebContents* storage_contents1;
320 content::WebContents* storage_contents2; 537 content::WebContents* storage_contents2;
321 538
322 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, 539 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
323 &default_tag_contents2, &storage_contents1, 540 &default_tag_contents2, &storage_contents1,
324 &storage_contents2); 541 &storage_contents2, NULL, NULL, NULL);
325 542
326 // Initialize the storage for the first of the two tags that share a storage 543 // Initialize the storage for the first of the two tags that share a storage
327 // partition. 544 // partition.
328 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created"); 545 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created");
329 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')", 546 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')",
330 "addItemIDB complete"); 547 "addItemIDB complete");
331 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", 548 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
332 "readItemIDB complete"); 549 "readItemIDB complete");
333 550
334 std::string output; 551 std::string output;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 "indexedDB.open('isolation').onsuccess = function(e) {" 602 "indexedDB.open('isolation').onsuccess = function(e) {"
386 " if (e.target.result.version == 1)" 603 " if (e.target.result.version == 1)"
387 " document.title = 'db not found';" 604 " document.title = 'db not found';"
388 " else " 605 " else "
389 " document.title = 'error';" 606 " document.title = 'error';"
390 "}"; 607 "}";
391 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0), 608 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0),
392 script, "db not found"); 609 script, "db not found");
393 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); 610 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found");
394 } 611 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view_isolation/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698