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/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 Loading... | |
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()); |
86 | 115 |
nasko
2012/11/12 16:47:28
Why the empty line?
awong
2012/11/12 21:36:16
Done.
| |
116 content::Source<content::NavigationController> source5 = observer5.source(); | |
117 EXPECT_TRUE(source5->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
118 content::Source<content::NavigationController> source6 = observer6.source(); | |
119 EXPECT_TRUE(source6->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
120 content::Source<content::NavigationController> source7 = observer7.source(); | |
121 EXPECT_TRUE(source7->GetWebContents()->GetRenderProcessHost()->IsGuest()); | |
122 | |
87 // Check that the first two tags use the same process and it is different | 123 // Check that the first two tags use the same process and it is different |
88 // than the process used by the other two. | 124 // than the process used by the other two. |
89 EXPECT_EQ(source1->GetWebContents()->GetRenderProcessHost()->GetID(), | 125 EXPECT_EQ(source1->GetWebContents()->GetRenderProcessHost()->GetID(), |
90 source2->GetWebContents()->GetRenderProcessHost()->GetID()); | 126 source2->GetWebContents()->GetRenderProcessHost()->GetID()); |
91 EXPECT_EQ(source3->GetWebContents()->GetRenderProcessHost()->GetID(), | 127 EXPECT_EQ(source3->GetWebContents()->GetRenderProcessHost()->GetID(), |
92 source4->GetWebContents()->GetRenderProcessHost()->GetID()); | 128 source4->GetWebContents()->GetRenderProcessHost()->GetID()); |
93 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(), | 129 EXPECT_NE(source1->GetWebContents()->GetRenderProcessHost()->GetID(), |
94 source3->GetWebContents()->GetRenderProcessHost()->GetID()); | 130 source3->GetWebContents()->GetRenderProcessHost()->GetID()); |
95 | 131 |
96 // The two sets of tags should also be isolated from the main browser. | 132 // The two sets of tags should also be isolated from the main browser. |
(...skipping 15 matching lines...) Expand all Loading... | |
112 source3->GetWebContents()->GetRenderProcessHost()-> | 148 source3->GetWebContents()->GetRenderProcessHost()-> |
113 GetStoragePartition(), | 149 GetStoragePartition(), |
114 source4->GetWebContents()->GetRenderProcessHost()-> | 150 source4->GetWebContents()->GetRenderProcessHost()-> |
115 GetStoragePartition()); | 151 GetStoragePartition()); |
116 EXPECT_NE( | 152 EXPECT_NE( |
117 source1->GetWebContents()->GetRenderProcessHost()-> | 153 source1->GetWebContents()->GetRenderProcessHost()-> |
118 GetStoragePartition(), | 154 GetStoragePartition(), |
119 source3->GetWebContents()->GetRenderProcessHost()-> | 155 source3->GetWebContents()->GetRenderProcessHost()-> |
120 GetStoragePartition()); | 156 GetStoragePartition()); |
121 | 157 |
158 // Ensure the persistent storage partitions are different. | |
159 EXPECT_EQ( | |
160 source5->GetWebContents()->GetRenderProcessHost()-> | |
161 GetStoragePartition(), | |
162 source6->GetWebContents()->GetRenderProcessHost()-> | |
163 GetStoragePartition()); | |
164 EXPECT_NE( | |
165 source5->GetWebContents()->GetRenderProcessHost()-> | |
166 GetStoragePartition(), | |
167 source7->GetWebContents()->GetRenderProcessHost()-> | |
168 GetStoragePartition()); | |
169 EXPECT_NE( | |
170 source1->GetWebContents()->GetRenderProcessHost()-> | |
171 GetStoragePartition(), | |
172 source5->GetWebContents()->GetRenderProcessHost()-> | |
173 GetStoragePartition()); | |
174 EXPECT_NE( | |
175 source1->GetWebContents()->GetRenderProcessHost()-> | |
176 GetStoragePartition(), | |
177 source7->GetWebContents()->GetRenderProcessHost()-> | |
178 GetStoragePartition()); | |
179 | |
122 *default_tag_contents1 = source1->GetWebContents(); | 180 *default_tag_contents1 = source1->GetWebContents(); |
123 *default_tag_contents2 = source2->GetWebContents(); | 181 *default_tag_contents2 = source2->GetWebContents(); |
124 *named_partition_contents1 = source3->GetWebContents(); | 182 *named_partition_contents1 = source3->GetWebContents(); |
125 *named_partition_contents2 = source4->GetWebContents(); | 183 *named_partition_contents2 = source4->GetWebContents(); |
184 if (persistent_partition_contents1) { | |
185 *persistent_partition_contents1 = source5->GetWebContents(); | |
186 } | |
187 if (persistent_partition_contents2) { | |
188 *persistent_partition_contents2 = source6->GetWebContents(); | |
189 } | |
190 if (persistent_partition_contents3) { | |
191 *persistent_partition_contents3 = source7->GetWebContents(); | |
192 } | |
126 } | 193 } |
127 | 194 |
128 void ExecuteScriptWaitForTitle(content::WebContents* web_contents, | 195 void ExecuteScriptWaitForTitle(content::WebContents* web_contents, |
129 const char* script, | 196 const char* script, |
130 const char* title) { | 197 const char* title) { |
131 std::wstring js_script = ASCIIToWide(script); | 198 std::wstring js_script = ASCIIToWide(script); |
132 string16 expected_title(ASCIIToUTF16(title)); | 199 string16 expected_title(ASCIIToUTF16(title)); |
133 string16 error_title(ASCIIToUTF16("error")); | 200 string16 error_title(ASCIIToUTF16("error")); |
134 | 201 |
135 content::TitleWatcher title_watcher(web_contents, expected_title); | 202 content::TitleWatcher title_watcher(web_contents, expected_title); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 // The first two partitions will be used to set cookies and ensure they are | 242 // 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 | 243 // shared. The named partition is used to ensure that cookies are isolated |
177 // between partitions within the same app. | 244 // between partitions within the same app. |
178 content::WebContents* cookie_contents1; | 245 content::WebContents* cookie_contents1; |
179 content::WebContents* cookie_contents2; | 246 content::WebContents* cookie_contents2; |
180 content::WebContents* named_partition_contents1; | 247 content::WebContents* named_partition_contents1; |
181 content::WebContents* named_partition_contents2; | 248 content::WebContents* named_partition_contents2; |
182 | 249 |
183 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, | 250 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, |
184 &cookie_contents2, &named_partition_contents1, | 251 &cookie_contents2, &named_partition_contents1, |
185 &named_partition_contents2); | 252 &named_partition_contents2, NULL, NULL, NULL); |
186 | 253 |
187 EXPECT_TRUE(content::ExecuteJavaScript( | 254 EXPECT_TRUE(content::ExecuteJavaScript( |
188 cookie_contents1->GetRenderViewHost(), std::wstring(), cookie_script1)); | 255 cookie_contents1->GetRenderViewHost(), std::wstring(), cookie_script1)); |
189 EXPECT_TRUE(content::ExecuteJavaScript( | 256 EXPECT_TRUE(content::ExecuteJavaScript( |
190 cookie_contents2->GetRenderViewHost(), std::wstring(), cookie_script2)); | 257 cookie_contents2->GetRenderViewHost(), std::wstring(), cookie_script2)); |
191 | 258 |
192 int cookie_size; | 259 int cookie_size; |
193 std::string cookie_value; | 260 std::string cookie_value; |
194 | 261 |
195 // Test the regular browser context to ensure we have only one cookie. | 262 // Test the regular browser context to ensure we have only one cookie. |
(...skipping 16 matching lines...) Expand all Loading... | |
212 &cookie_size, &cookie_value); | 279 &cookie_size, &cookie_value); |
213 EXPECT_EQ("guest1=true; guest2=true", cookie_value); | 280 EXPECT_EQ("guest1=true; guest2=true", cookie_value); |
214 | 281 |
215 // The third tag should not have any cookies as it is in a separate partition. | 282 // The third tag should not have any cookies as it is in a separate partition. |
216 automation_util::GetCookies(GURL("http://localhost"), | 283 automation_util::GetCookies(GURL("http://localhost"), |
217 named_partition_contents1, | 284 named_partition_contents1, |
218 &cookie_size, &cookie_value); | 285 &cookie_size, &cookie_value); |
219 EXPECT_EQ("", cookie_value); | 286 EXPECT_EQ("", cookie_value); |
220 } | 287 } |
221 | 288 |
289 // This tests that in memory storage partitions are reset on browser restart, | |
nasko
2012/11/12 16:47:28
"in-memory" reads better than no dash.
awong
2012/11/12 21:36:16
Done.
| |
290 // but persistent ones maintain state for cookies and HTML5 storage. | |
291 IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) { | |
292 ASSERT_TRUE(StartTestServer()); | |
293 const std::wstring kExpire = | |
294 L"var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; | |
295 std::wstring cookie_script1(kExpire); | |
296 cookie_script1.append( | |
297 L"document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';"); | |
298 std::wstring cookie_script2(kExpire); | |
299 cookie_script2.append( | |
300 L"document.cookie = 'persist1=true; path=/; expires=' + expire + ';';"); | |
301 std::wstring cookie_script3(kExpire); | |
302 cookie_script3.append( | |
303 L"document.cookie = 'persist2=true; path=/; expires=' + expire + ';';"); | |
304 | |
305 GURL::Replacements replace_host; | |
306 std::string host_str("localhost"); // Must stay in scope with replace_host. | |
307 replace_host.SetHostStr(host_str); | |
nasko
2012/11/12 16:47:28
We don't seem to use replace_host in this function
awong
2012/11/12 21:36:16
Done.
| |
308 | |
309 // We don't care where the main browser is on this test. | |
310 GURL set_cookie_url("about:blank"); | |
nasko
2012/11/12 16:47:28
Why not call it "blank_url" if you aren't going to
awong
2012/11/12 21:36:16
Done.
| |
311 | |
312 // The first two partitions will be used to set cookies and ensure they are | |
313 // shared. The named partition is used to ensure that cookies are isolated | |
314 // between partitions within the same app. | |
315 content::WebContents* cookie_contents1; | |
316 content::WebContents* cookie_contents2; | |
317 content::WebContents* named_partition_contents1; | |
318 content::WebContents* named_partition_contents2; | |
319 content::WebContents* persistent_partition_contents1; | |
320 content::WebContents* persistent_partition_contents2; | |
321 content::WebContents* persistent_partition_contents3; | |
322 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, | |
323 &cookie_contents2, &named_partition_contents1, | |
324 &named_partition_contents2, | |
325 &persistent_partition_contents1, | |
326 &persistent_partition_contents2, | |
327 &persistent_partition_contents3); | |
328 | |
329 // Set the inmemory=true cookie for tags with inmemory partitions. | |
330 EXPECT_TRUE(content::ExecuteJavaScript( | |
331 cookie_contents1->GetRenderViewHost(), std::wstring(), | |
332 cookie_script1)); | |
333 EXPECT_TRUE(content::ExecuteJavaScript( | |
334 named_partition_contents1->GetRenderViewHost(), std::wstring(), | |
335 cookie_script1)); | |
336 | |
337 // For the two different persistent storage partitions, set the | |
338 // two different cookies so we can check that they aren't comingled below. | |
339 EXPECT_TRUE(content::ExecuteJavaScript( | |
340 persistent_partition_contents1->GetRenderViewHost(), std::wstring(), | |
341 cookie_script2)); | |
342 | |
343 EXPECT_TRUE(content::ExecuteJavaScript( | |
344 persistent_partition_contents3->GetRenderViewHost(), std::wstring(), | |
345 cookie_script3)); | |
346 | |
347 int cookie_size; | |
348 std::string cookie_value; | |
349 | |
350 // Check that all in-memory partitions have a cookie set. | |
351 automation_util::GetCookies(GURL("http://localhost"), | |
352 cookie_contents1, | |
353 &cookie_size, &cookie_value); | |
354 EXPECT_EQ("inmemory=true", cookie_value); | |
355 automation_util::GetCookies(GURL("http://localhost"), | |
356 cookie_contents2, | |
357 &cookie_size, &cookie_value); | |
358 EXPECT_EQ("inmemory=true", cookie_value); | |
359 automation_util::GetCookies(GURL("http://localhost"), | |
360 named_partition_contents1, | |
361 &cookie_size, &cookie_value); | |
362 EXPECT_EQ("inmemory=true", cookie_value); | |
363 automation_util::GetCookies(GURL("http://localhost"), | |
364 named_partition_contents2, | |
365 &cookie_size, &cookie_value); | |
366 EXPECT_EQ("inmemory=true", cookie_value); | |
367 | |
368 // Check that all persistent partitions kept their state. | |
369 automation_util::GetCookies(GURL("http://localhost"), | |
370 persistent_partition_contents1, | |
371 &cookie_size, &cookie_value); | |
372 EXPECT_EQ("persist1=true", cookie_value); | |
373 automation_util::GetCookies(GURL("http://localhost"), | |
374 persistent_partition_contents2, | |
375 &cookie_size, &cookie_value); | |
376 EXPECT_EQ("persist1=true", cookie_value); | |
377 automation_util::GetCookies(GURL("http://localhost"), | |
378 persistent_partition_contents3, | |
379 &cookie_size, &cookie_value); | |
380 EXPECT_EQ("persist2=true", cookie_value); | |
381 } | |
382 | |
383 IN_PROC_BROWSER_TEST_F(WebViewTest, StoragePersistence) { | |
nasko
2012/11/12 16:47:28
A comment that ties this test with the PRE_ will b
awong
2012/11/12 21:36:16
Done.
| |
384 ASSERT_TRUE(StartTestServer()); | |
385 const std::wstring kExpire = | |
386 L"var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; | |
387 std::wstring cookie_script1(kExpire); | |
388 cookie_script1.append( | |
389 L"document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';"); | |
390 std::wstring cookie_script2(kExpire); | |
391 cookie_script2.append( | |
nasko
2012/11/12 16:47:28
We don't need the above three, right?
awong
2012/11/12 21:36:16
Done.
| |
392 L"document.cookie = 'persist=true; path=/; expires=' + expire + ';';"); | |
393 | |
394 GURL::Replacements replace_host; | |
395 std::string host_str("localhost"); // Must stay in scope with replace_host. | |
396 replace_host.SetHostStr(host_str); | |
nasko
2012/11/12 16:47:28
Like in the previous test, this is not used in the
awong
2012/11/12 21:36:16
Done.
| |
397 | |
398 // We don't care where the main browser is on this test. | |
399 GURL set_cookie_url("about:blank"); | |
400 | |
401 // The first two partitions will be used to set cookies and ensure they are | |
402 // shared. The named partition is used to ensure that cookies are isolated | |
403 // between partitions within the same app. | |
404 content::WebContents* cookie_contents1; | |
405 content::WebContents* cookie_contents2; | |
406 content::WebContents* named_partition_contents1; | |
407 content::WebContents* named_partition_contents2; | |
408 content::WebContents* persistent_partition_contents1; | |
409 content::WebContents* persistent_partition_contents2; | |
410 content::WebContents* persistent_partition_contents3; | |
411 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, | |
412 &cookie_contents2, &named_partition_contents1, | |
413 &named_partition_contents2, | |
414 &persistent_partition_contents1, | |
415 &persistent_partition_contents2, | |
416 &persistent_partition_contents3); | |
417 | |
418 int cookie_size; | |
419 std::string cookie_value; | |
420 | |
421 // Check that all in-memory partitions lost their state. | |
422 automation_util::GetCookies(GURL("http://localhost"), | |
423 cookie_contents1, | |
424 &cookie_size, &cookie_value); | |
425 EXPECT_EQ("", cookie_value); | |
426 automation_util::GetCookies(GURL("http://localhost"), | |
427 cookie_contents2, | |
428 &cookie_size, &cookie_value); | |
429 EXPECT_EQ("", cookie_value); | |
430 automation_util::GetCookies(GURL("http://localhost"), | |
431 named_partition_contents1, | |
432 &cookie_size, &cookie_value); | |
433 EXPECT_EQ("", cookie_value); | |
434 automation_util::GetCookies(GURL("http://localhost"), | |
435 named_partition_contents2, | |
436 &cookie_size, &cookie_value); | |
437 EXPECT_EQ("", cookie_value); | |
438 | |
439 // Check that all persistent partitions kept their state. | |
440 automation_util::GetCookies(GURL("http://localhost"), | |
441 persistent_partition_contents1, | |
442 &cookie_size, &cookie_value); | |
443 EXPECT_EQ("persist1=true", cookie_value); | |
444 automation_util::GetCookies(GURL("http://localhost"), | |
445 persistent_partition_contents2, | |
446 &cookie_size, &cookie_value); | |
447 EXPECT_EQ("persist1=true", cookie_value); | |
448 automation_util::GetCookies(GURL("http://localhost"), | |
449 persistent_partition_contents3, | |
450 &cookie_size, &cookie_value); | |
451 EXPECT_EQ("persist2=true", cookie_value); | |
452 } | |
453 | |
222 // This tests DOM storage isolation for packaged apps with webview tags. It | 454 // 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 | 455 // 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 | 456 // entries, which the test checks to ensure proper storage isolation is |
225 // enforced. | 457 // enforced. |
226 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) { | 458 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) { |
227 ASSERT_TRUE(StartTestServer()); | 459 ASSERT_TRUE(StartTestServer()); |
228 GURL regular_url = test_server()->GetURL("files/title1.html"); | 460 GURL regular_url = test_server()->GetURL("files/title1.html"); |
229 | 461 |
230 std::string output; | 462 std::string output; |
231 std::wstring get_local_storage(L"window.domAutomationController.send(" | 463 std::wstring get_local_storage(L"window.domAutomationController.send(" |
232 L"window.localStorage.getItem('foo') || 'badval')"); | 464 L"window.localStorage.getItem('foo') || 'badval')"); |
233 std::wstring get_session_storage(L"window.domAutomationController.send(" | 465 std::wstring get_session_storage(L"window.domAutomationController.send(" |
234 L"window.sessionStorage.getItem('bar') || 'badval')"); | 466 L"window.sessionStorage.getItem('bar') || 'badval')"); |
235 | 467 |
236 content::WebContents* default_tag_contents1; | 468 content::WebContents* default_tag_contents1; |
237 content::WebContents* default_tag_contents2; | 469 content::WebContents* default_tag_contents2; |
238 content::WebContents* storage_contents1; | 470 content::WebContents* storage_contents1; |
239 content::WebContents* storage_contents2; | 471 content::WebContents* storage_contents2; |
240 | 472 |
241 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, | 473 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, |
242 &default_tag_contents2, &storage_contents1, | 474 &default_tag_contents2, &storage_contents1, |
243 &storage_contents2); | 475 &storage_contents2, NULL, NULL, NULL); |
244 | 476 |
245 // Initialize the storage for the first of the two tags that share a storage | 477 // Initialize the storage for the first of the two tags that share a storage |
246 // partition. | 478 // partition. |
247 EXPECT_TRUE(content::ExecuteJavaScript( | 479 EXPECT_TRUE(content::ExecuteJavaScript( |
248 storage_contents1->GetRenderViewHost(), std::wstring(), | 480 storage_contents1->GetRenderViewHost(), std::wstring(), |
249 L"initDomStorage('page1')")); | 481 L"initDomStorage('page1')")); |
250 | 482 |
251 // Let's test that the expected values are present in the first tag, as they | 483 // 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. | 484 // will be overwritten once we call the initDomStorage on the second tag. |
253 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 485 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 ASSERT_TRUE(StartTestServer()); | 546 ASSERT_TRUE(StartTestServer()); |
315 GURL regular_url = test_server()->GetURL("files/title1.html"); | 547 GURL regular_url = test_server()->GetURL("files/title1.html"); |
316 | 548 |
317 content::WebContents* default_tag_contents1; | 549 content::WebContents* default_tag_contents1; |
318 content::WebContents* default_tag_contents2; | 550 content::WebContents* default_tag_contents2; |
319 content::WebContents* storage_contents1; | 551 content::WebContents* storage_contents1; |
320 content::WebContents* storage_contents2; | 552 content::WebContents* storage_contents2; |
321 | 553 |
322 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, | 554 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, |
323 &default_tag_contents2, &storage_contents1, | 555 &default_tag_contents2, &storage_contents1, |
324 &storage_contents2); | 556 &storage_contents2, NULL, NULL, NULL); |
325 | 557 |
326 // Initialize the storage for the first of the two tags that share a storage | 558 // Initialize the storage for the first of the two tags that share a storage |
327 // partition. | 559 // partition. |
328 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created"); | 560 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created"); |
329 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')", | 561 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')", |
330 "addItemIDB complete"); | 562 "addItemIDB complete"); |
331 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", | 563 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", |
332 "readItemIDB complete"); | 564 "readItemIDB complete"); |
333 | 565 |
334 std::string output; | 566 std::string output; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 "indexedDB.open('isolation').onsuccess = function(e) {" | 617 "indexedDB.open('isolation').onsuccess = function(e) {" |
386 " if (e.target.result.version == 1)" | 618 " if (e.target.result.version == 1)" |
387 " document.title = 'db not found';" | 619 " document.title = 'db not found';" |
388 " else " | 620 " else " |
389 " document.title = 'error';" | 621 " document.title = 'error';" |
390 "}"; | 622 "}"; |
391 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0), | 623 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0), |
392 script, "db not found"); | 624 script, "db not found"); |
393 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); | 625 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); |
394 } | 626 } |
OLD | NEW |