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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 *persistent_partition_contents2 = source6->GetWebContents(); | 186 *persistent_partition_contents2 = source6->GetWebContents(); |
187 } | 187 } |
188 if (persistent_partition_contents3) { | 188 if (persistent_partition_contents3) { |
189 *persistent_partition_contents3 = source7->GetWebContents(); | 189 *persistent_partition_contents3 = source7->GetWebContents(); |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 void ExecuteScriptWaitForTitle(content::WebContents* web_contents, | 193 void ExecuteScriptWaitForTitle(content::WebContents* web_contents, |
194 const char* script, | 194 const char* script, |
195 const char* title) { | 195 const char* title) { |
196 std::wstring js_script = ASCIIToWide(script); | |
197 string16 expected_title(ASCIIToUTF16(title)); | 196 string16 expected_title(ASCIIToUTF16(title)); |
198 string16 error_title(ASCIIToUTF16("error")); | 197 string16 error_title(ASCIIToUTF16("error")); |
199 | 198 |
200 content::TitleWatcher title_watcher(web_contents, expected_title); | 199 content::TitleWatcher title_watcher(web_contents, expected_title); |
201 title_watcher.AlsoWaitForTitle(error_title); | 200 title_watcher.AlsoWaitForTitle(error_title); |
202 EXPECT_TRUE(content::ExecuteJavaScript(web_contents->GetRenderViewHost(), | 201 EXPECT_TRUE(content::ExecuteJavaScript(web_contents->GetRenderViewHost(), |
203 std::wstring(), js_script)); | 202 "", script)); |
204 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 203 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
205 } | 204 } |
206 }; | 205 }; |
207 | 206 |
208 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim) { | 207 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim) { |
209 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view")) << message_; | 208 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view")) << message_; |
210 } | 209 } |
211 | 210 |
212 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { | 211 IN_PROC_BROWSER_TEST_F(WebViewTest, ShimSrcAttribute) { |
213 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view_src_attribute")) | 212 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view_src_attribute")) |
214 << message_; | 213 << message_; |
215 } | 214 } |
216 | 215 |
217 // This tests cookie isolation for packaged apps with webview tags. It navigates | 216 // This tests cookie isolation for packaged apps with webview tags. It navigates |
218 // the main browser window to a page that sets a cookie and loads an app with | 217 // the main browser window to a page that sets a cookie and loads an app with |
219 // multiple webview tags. Each tag sets a cookie and the test checks the proper | 218 // multiple webview tags. Each tag sets a cookie and the test checks the proper |
220 // storage isolation is enforced. | 219 // storage isolation is enforced. |
221 IN_PROC_BROWSER_TEST_F(WebViewTest, CookieIsolation) { | 220 IN_PROC_BROWSER_TEST_F(WebViewTest, CookieIsolation) { |
222 ASSERT_TRUE(StartTestServer()); | 221 ASSERT_TRUE(StartTestServer()); |
223 const std::wstring kExpire = | 222 const std::string kExpire = |
224 L"var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; | 223 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; |
225 std::wstring cookie_script1(kExpire); | 224 std::string cookie_script1(kExpire); |
226 cookie_script1.append( | 225 cookie_script1.append( |
227 L"document.cookie = 'guest1=true; path=/; expires=' + expire + ';';"); | 226 "document.cookie = 'guest1=true; path=/; expires=' + expire + ';';"); |
228 std::wstring cookie_script2(kExpire); | 227 std::string cookie_script2(kExpire); |
229 cookie_script2.append( | 228 cookie_script2.append( |
230 L"document.cookie = 'guest2=true; path=/; expires=' + expire + ';';"); | 229 "document.cookie = 'guest2=true; path=/; expires=' + expire + ';';"); |
231 | 230 |
232 GURL::Replacements replace_host; | 231 GURL::Replacements replace_host; |
233 std::string host_str("localhost"); // Must stay in scope with replace_host. | 232 std::string host_str("localhost"); // Must stay in scope with replace_host. |
234 replace_host.SetHostStr(host_str); | 233 replace_host.SetHostStr(host_str); |
235 | 234 |
236 GURL set_cookie_url = test_server()->GetURL( | 235 GURL set_cookie_url = test_server()->GetURL( |
237 "files/extensions/platform_apps/isolation/set_cookie.html"); | 236 "files/extensions/platform_apps/isolation/set_cookie.html"); |
238 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); | 237 set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); |
239 | 238 |
240 // The first two partitions will be used to set cookies and ensure they are | 239 // The first two partitions will be used to set cookies and ensure they are |
241 // shared. The named partition is used to ensure that cookies are isolated | 240 // shared. The named partition is used to ensure that cookies are isolated |
242 // between partitions within the same app. | 241 // between partitions within the same app. |
243 content::WebContents* cookie_contents1; | 242 content::WebContents* cookie_contents1; |
244 content::WebContents* cookie_contents2; | 243 content::WebContents* cookie_contents2; |
245 content::WebContents* named_partition_contents1; | 244 content::WebContents* named_partition_contents1; |
246 content::WebContents* named_partition_contents2; | 245 content::WebContents* named_partition_contents2; |
247 | 246 |
248 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, | 247 NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1, |
249 &cookie_contents2, &named_partition_contents1, | 248 &cookie_contents2, &named_partition_contents1, |
250 &named_partition_contents2, NULL, NULL, NULL); | 249 &named_partition_contents2, NULL, NULL, NULL); |
251 | 250 |
252 EXPECT_TRUE(content::ExecuteJavaScript( | 251 EXPECT_TRUE(content::ExecuteJavaScript( |
253 cookie_contents1->GetRenderViewHost(), std::wstring(), cookie_script1)); | 252 cookie_contents1->GetRenderViewHost(), "", cookie_script1)); |
254 EXPECT_TRUE(content::ExecuteJavaScript( | 253 EXPECT_TRUE(content::ExecuteJavaScript( |
255 cookie_contents2->GetRenderViewHost(), std::wstring(), cookie_script2)); | 254 cookie_contents2->GetRenderViewHost(), "", cookie_script2)); |
256 | 255 |
257 int cookie_size; | 256 int cookie_size; |
258 std::string cookie_value; | 257 std::string cookie_value; |
259 | 258 |
260 // Test the regular browser context to ensure we have only one cookie. | 259 // Test the regular browser context to ensure we have only one cookie. |
261 automation_util::GetCookies(GURL("http://localhost"), | 260 automation_util::GetCookies(GURL("http://localhost"), |
262 chrome::GetWebContentsAt(browser(), 0), | 261 chrome::GetWebContentsAt(browser(), 0), |
263 &cookie_size, &cookie_value); | 262 &cookie_size, &cookie_value); |
264 EXPECT_EQ("testCookie=1", cookie_value); | 263 EXPECT_EQ("testCookie=1", cookie_value); |
265 | 264 |
(...skipping 15 matching lines...) Expand all Loading... |
281 automation_util::GetCookies(GURL("http://localhost"), | 280 automation_util::GetCookies(GURL("http://localhost"), |
282 named_partition_contents1, | 281 named_partition_contents1, |
283 &cookie_size, &cookie_value); | 282 &cookie_size, &cookie_value); |
284 EXPECT_EQ("", cookie_value); | 283 EXPECT_EQ("", cookie_value); |
285 } | 284 } |
286 | 285 |
287 // This tests that in-memory storage partitions are reset on browser restart, | 286 // This tests that in-memory storage partitions are reset on browser restart, |
288 // but persistent ones maintain state for cookies and HTML5 storage. | 287 // but persistent ones maintain state for cookies and HTML5 storage. |
289 IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) { | 288 IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) { |
290 ASSERT_TRUE(StartTestServer()); | 289 ASSERT_TRUE(StartTestServer()); |
291 const std::wstring kExpire = | 290 const std::string kExpire = |
292 L"var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; | 291 "var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);"; |
293 std::wstring cookie_script1(kExpire); | 292 std::string cookie_script1(kExpire); |
294 cookie_script1.append( | 293 cookie_script1.append( |
295 L"document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';"); | 294 "document.cookie = 'inmemory=true; path=/; expires=' + expire + ';';"); |
296 std::wstring cookie_script2(kExpire); | 295 std::string cookie_script2(kExpire); |
297 cookie_script2.append( | 296 cookie_script2.append( |
298 L"document.cookie = 'persist1=true; path=/; expires=' + expire + ';';"); | 297 "document.cookie = 'persist1=true; path=/; expires=' + expire + ';';"); |
299 std::wstring cookie_script3(kExpire); | 298 std::string cookie_script3(kExpire); |
300 cookie_script3.append( | 299 cookie_script3.append( |
301 L"document.cookie = 'persist2=true; path=/; expires=' + expire + ';';"); | 300 "document.cookie = 'persist2=true; path=/; expires=' + expire + ';';"); |
302 | 301 |
303 // We don't care where the main browser is on this test. | 302 // We don't care where the main browser is on this test. |
304 GURL blank_url("about:blank"); | 303 GURL blank_url("about:blank"); |
305 | 304 |
306 // The first two partitions will be used to set cookies and ensure they are | 305 // The first two partitions will be used to set cookies and ensure they are |
307 // shared. The named partition is used to ensure that cookies are isolated | 306 // shared. The named partition is used to ensure that cookies are isolated |
308 // between partitions within the same app. | 307 // between partitions within the same app. |
309 content::WebContents* cookie_contents1; | 308 content::WebContents* cookie_contents1; |
310 content::WebContents* cookie_contents2; | 309 content::WebContents* cookie_contents2; |
311 content::WebContents* named_partition_contents1; | 310 content::WebContents* named_partition_contents1; |
312 content::WebContents* named_partition_contents2; | 311 content::WebContents* named_partition_contents2; |
313 content::WebContents* persistent_partition_contents1; | 312 content::WebContents* persistent_partition_contents1; |
314 content::WebContents* persistent_partition_contents2; | 313 content::WebContents* persistent_partition_contents2; |
315 content::WebContents* persistent_partition_contents3; | 314 content::WebContents* persistent_partition_contents3; |
316 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1, | 315 NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1, |
317 &cookie_contents2, &named_partition_contents1, | 316 &cookie_contents2, &named_partition_contents1, |
318 &named_partition_contents2, | 317 &named_partition_contents2, |
319 &persistent_partition_contents1, | 318 &persistent_partition_contents1, |
320 &persistent_partition_contents2, | 319 &persistent_partition_contents2, |
321 &persistent_partition_contents3); | 320 &persistent_partition_contents3); |
322 | 321 |
323 // Set the inmemory=true cookie for tags with inmemory partitions. | 322 // Set the inmemory=true cookie for tags with inmemory partitions. |
324 EXPECT_TRUE(content::ExecuteJavaScript( | 323 EXPECT_TRUE(content::ExecuteJavaScript( |
325 cookie_contents1->GetRenderViewHost(), std::wstring(), | 324 cookie_contents1->GetRenderViewHost(), |
| 325 "", |
326 cookie_script1)); | 326 cookie_script1)); |
327 EXPECT_TRUE(content::ExecuteJavaScript( | 327 EXPECT_TRUE(content::ExecuteJavaScript( |
328 named_partition_contents1->GetRenderViewHost(), std::wstring(), | 328 named_partition_contents1->GetRenderViewHost(), |
| 329 "", |
329 cookie_script1)); | 330 cookie_script1)); |
330 | 331 |
331 // For the two different persistent storage partitions, set the | 332 // For the two different persistent storage partitions, set the |
332 // two different cookies so we can check that they aren't comingled below. | 333 // two different cookies so we can check that they aren't comingled below. |
333 EXPECT_TRUE(content::ExecuteJavaScript( | 334 EXPECT_TRUE(content::ExecuteJavaScript( |
334 persistent_partition_contents1->GetRenderViewHost(), std::wstring(), | 335 persistent_partition_contents1->GetRenderViewHost(), |
| 336 "", |
335 cookie_script2)); | 337 cookie_script2)); |
336 | 338 |
337 EXPECT_TRUE(content::ExecuteJavaScript( | 339 EXPECT_TRUE(content::ExecuteJavaScript( |
338 persistent_partition_contents3->GetRenderViewHost(), std::wstring(), | 340 persistent_partition_contents3->GetRenderViewHost(), |
| 341 "", |
339 cookie_script3)); | 342 cookie_script3)); |
340 | 343 |
341 int cookie_size; | 344 int cookie_size; |
342 std::string cookie_value; | 345 std::string cookie_value; |
343 | 346 |
344 // Check that all in-memory partitions have a cookie set. | 347 // Check that all in-memory partitions have a cookie set. |
345 automation_util::GetCookies(GURL("http://localhost"), | 348 automation_util::GetCookies(GURL("http://localhost"), |
346 cookie_contents1, | 349 cookie_contents1, |
347 &cookie_size, &cookie_value); | 350 &cookie_size, &cookie_value); |
348 EXPECT_EQ("inmemory=true", cookie_value); | 351 EXPECT_EQ("inmemory=true", cookie_value); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 | 440 |
438 // This tests DOM storage isolation for packaged apps with webview tags. It | 441 // This tests DOM storage isolation for packaged apps with webview tags. It |
439 // loads an app with multiple webview tags and each tag sets DOM storage | 442 // loads an app with multiple webview tags and each tag sets DOM storage |
440 // entries, which the test checks to ensure proper storage isolation is | 443 // entries, which the test checks to ensure proper storage isolation is |
441 // enforced. | 444 // enforced. |
442 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) { | 445 IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) { |
443 ASSERT_TRUE(StartTestServer()); | 446 ASSERT_TRUE(StartTestServer()); |
444 GURL regular_url = test_server()->GetURL("files/title1.html"); | 447 GURL regular_url = test_server()->GetURL("files/title1.html"); |
445 | 448 |
446 std::string output; | 449 std::string output; |
447 std::wstring get_local_storage(L"window.domAutomationController.send(" | 450 std::string get_local_storage("window.domAutomationController.send(" |
448 L"window.localStorage.getItem('foo') || 'badval')"); | 451 "window.localStorage.getItem('foo') || 'badval')"); |
449 std::wstring get_session_storage(L"window.domAutomationController.send(" | 452 std::string get_session_storage("window.domAutomationController.send(" |
450 L"window.sessionStorage.getItem('bar') || 'badval')"); | 453 "window.sessionStorage.getItem('bar') || 'badval')"); |
451 | 454 |
452 content::WebContents* default_tag_contents1; | 455 content::WebContents* default_tag_contents1; |
453 content::WebContents* default_tag_contents2; | 456 content::WebContents* default_tag_contents2; |
454 content::WebContents* storage_contents1; | 457 content::WebContents* storage_contents1; |
455 content::WebContents* storage_contents2; | 458 content::WebContents* storage_contents2; |
456 | 459 |
457 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, | 460 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, |
458 &default_tag_contents2, &storage_contents1, | 461 &default_tag_contents2, &storage_contents1, |
459 &storage_contents2, NULL, NULL, NULL); | 462 &storage_contents2, NULL, NULL, NULL); |
460 | 463 |
461 // Initialize the storage for the first of the two tags that share a storage | 464 // Initialize the storage for the first of the two tags that share a storage |
462 // partition. | 465 // partition. |
463 EXPECT_TRUE(content::ExecuteJavaScript( | 466 EXPECT_TRUE(content::ExecuteJavaScript( |
464 storage_contents1->GetRenderViewHost(), std::wstring(), | 467 storage_contents1->GetRenderViewHost(), |
465 L"initDomStorage('page1')")); | 468 "", |
| 469 "initDomStorage('page1')")); |
466 | 470 |
467 // Let's test that the expected values are present in the first tag, as they | 471 // Let's test that the expected values are present in the first tag, as they |
468 // will be overwritten once we call the initDomStorage on the second tag. | 472 // will be overwritten once we call the initDomStorage on the second tag. |
469 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 473 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
470 storage_contents1->GetRenderViewHost(), std::wstring(), | 474 storage_contents1->GetRenderViewHost(), |
471 get_local_storage.c_str(), &output)); | 475 "", |
| 476 get_local_storage.c_str(), |
| 477 &output)); |
472 EXPECT_STREQ("local-page1", output.c_str()); | 478 EXPECT_STREQ("local-page1", output.c_str()); |
473 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 479 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
474 storage_contents1->GetRenderViewHost(), std::wstring(), | 480 storage_contents1->GetRenderViewHost(), |
475 get_session_storage.c_str(), &output)); | 481 "", |
| 482 get_session_storage.c_str(), |
| 483 &output)); |
476 EXPECT_STREQ("session-page1", output.c_str()); | 484 EXPECT_STREQ("session-page1", output.c_str()); |
477 | 485 |
478 // Now, init the storage in the second tag in the same storage partition, | 486 // Now, init the storage in the second tag in the same storage partition, |
479 // which will overwrite the shared localStorage. | 487 // which will overwrite the shared localStorage. |
480 EXPECT_TRUE(content::ExecuteJavaScript( | 488 EXPECT_TRUE(content::ExecuteJavaScript( |
481 storage_contents2->GetRenderViewHost(), std::wstring(), | 489 storage_contents2->GetRenderViewHost(), |
482 L"initDomStorage('page2')")); | 490 "", |
| 491 "initDomStorage('page2')")); |
483 | 492 |
484 // The localStorage value now should reflect the one written through the | 493 // The localStorage value now should reflect the one written through the |
485 // second tag. | 494 // second tag. |
486 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 495 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
487 storage_contents1->GetRenderViewHost(), std::wstring(), | 496 storage_contents1->GetRenderViewHost(), |
488 get_local_storage.c_str(), &output)); | 497 "", |
| 498 get_local_storage.c_str(), |
| 499 &output)); |
489 EXPECT_STREQ("local-page2", output.c_str()); | 500 EXPECT_STREQ("local-page2", output.c_str()); |
490 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 501 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
491 storage_contents2->GetRenderViewHost(), std::wstring(), | 502 storage_contents2->GetRenderViewHost(), |
492 get_local_storage.c_str(), &output)); | 503 "", |
| 504 get_local_storage.c_str(), |
| 505 &output)); |
493 EXPECT_STREQ("local-page2", output.c_str()); | 506 EXPECT_STREQ("local-page2", output.c_str()); |
494 | 507 |
495 // Session storage is not shared though, as each webview tag has separate | 508 // Session storage is not shared though, as each webview tag has separate |
496 // instance, even if they are in the same storage partition. | 509 // instance, even if they are in the same storage partition. |
497 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 510 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
498 storage_contents1->GetRenderViewHost(), std::wstring(), | 511 storage_contents1->GetRenderViewHost(), |
499 get_session_storage.c_str(), &output)); | 512 "", |
| 513 get_session_storage.c_str(), |
| 514 &output)); |
500 EXPECT_STREQ("session-page1", output.c_str()); | 515 EXPECT_STREQ("session-page1", output.c_str()); |
501 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 516 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
502 storage_contents2->GetRenderViewHost(), std::wstring(), | 517 storage_contents2->GetRenderViewHost(), |
503 get_session_storage.c_str(), &output)); | 518 "", |
| 519 get_session_storage.c_str(), |
| 520 &output)); |
504 EXPECT_STREQ("session-page2", output.c_str()); | 521 EXPECT_STREQ("session-page2", output.c_str()); |
505 | 522 |
506 // Also, let's check that the main browser and another tag that doesn't share | 523 // Also, let's check that the main browser and another tag that doesn't share |
507 // the same partition don't have those values stored. | 524 // the same partition don't have those values stored. |
508 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 525 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
509 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), | 526 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), |
510 std::wstring(), get_local_storage.c_str(), &output)); | 527 "", |
| 528 get_local_storage.c_str(), |
| 529 &output)); |
511 EXPECT_STREQ("badval", output.c_str()); | 530 EXPECT_STREQ("badval", output.c_str()); |
512 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 531 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
513 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), | 532 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), |
514 std::wstring(), get_session_storage.c_str(), &output)); | 533 "", |
| 534 get_session_storage.c_str(), |
| 535 &output)); |
515 EXPECT_STREQ("badval", output.c_str()); | 536 EXPECT_STREQ("badval", output.c_str()); |
516 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 537 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
517 default_tag_contents1->GetRenderViewHost(), std::wstring(), | 538 default_tag_contents1->GetRenderViewHost(), |
518 get_local_storage.c_str(), &output)); | 539 "", |
| 540 get_local_storage.c_str(), |
| 541 &output)); |
519 EXPECT_STREQ("badval", output.c_str()); | 542 EXPECT_STREQ("badval", output.c_str()); |
520 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 543 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
521 default_tag_contents1->GetRenderViewHost(), std::wstring(), | 544 default_tag_contents1->GetRenderViewHost(), |
522 get_session_storage.c_str(), &output)); | 545 "", |
| 546 get_session_storage.c_str(), |
| 547 &output)); |
523 EXPECT_STREQ("badval", output.c_str()); | 548 EXPECT_STREQ("badval", output.c_str()); |
524 } | 549 } |
525 | 550 |
526 // This tests IndexedDB isolation for packaged apps with webview tags. It loads | 551 // This tests IndexedDB isolation for packaged apps with webview tags. It loads |
527 // an app with multiple webview tags and each tag creates an IndexedDB record, | 552 // an app with multiple webview tags and each tag creates an IndexedDB record, |
528 // which the test checks to ensure proper storage isolation is enforced. | 553 // which the test checks to ensure proper storage isolation is enforced. |
529 IN_PROC_BROWSER_TEST_F(WebViewTest, IndexedDBIsolation) { | 554 IN_PROC_BROWSER_TEST_F(WebViewTest, IndexedDBIsolation) { |
530 ASSERT_TRUE(StartTestServer()); | 555 ASSERT_TRUE(StartTestServer()); |
531 GURL regular_url = test_server()->GetURL("files/title1.html"); | 556 GURL regular_url = test_server()->GetURL("files/title1.html"); |
532 | 557 |
533 content::WebContents* default_tag_contents1; | 558 content::WebContents* default_tag_contents1; |
534 content::WebContents* default_tag_contents2; | 559 content::WebContents* default_tag_contents2; |
535 content::WebContents* storage_contents1; | 560 content::WebContents* storage_contents1; |
536 content::WebContents* storage_contents2; | 561 content::WebContents* storage_contents2; |
537 | 562 |
538 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, | 563 NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1, |
539 &default_tag_contents2, &storage_contents1, | 564 &default_tag_contents2, &storage_contents1, |
540 &storage_contents2, NULL, NULL, NULL); | 565 &storage_contents2, NULL, NULL, NULL); |
541 | 566 |
542 // Initialize the storage for the first of the two tags that share a storage | 567 // Initialize the storage for the first of the two tags that share a storage |
543 // partition. | 568 // partition. |
544 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created"); | 569 ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created"); |
545 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')", | 570 ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')", |
546 "addItemIDB complete"); | 571 "addItemIDB complete"); |
547 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", | 572 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", |
548 "readItemIDB complete"); | 573 "readItemIDB complete"); |
549 | 574 |
550 std::string output; | 575 std::string output; |
551 std::wstring get_value( | 576 std::string get_value( |
552 L"window.domAutomationController.send(getValueIDB() || 'badval')"); | 577 "window.domAutomationController.send(getValueIDB() || 'badval')"); |
553 | 578 |
554 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 579 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
555 storage_contents1->GetRenderViewHost(), std::wstring(), | 580 storage_contents1->GetRenderViewHost(), |
| 581 "", |
556 get_value.c_str(), &output)); | 582 get_value.c_str(), &output)); |
557 EXPECT_STREQ("page1", output.c_str()); | 583 EXPECT_STREQ("page1", output.c_str()); |
558 | 584 |
559 // Initialize the db in the second tag. | 585 // Initialize the db in the second tag. |
560 ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open"); | 586 ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open"); |
561 | 587 |
562 // Since we share a partition, reading the value should return the existing | 588 // Since we share a partition, reading the value should return the existing |
563 // one. | 589 // one. |
564 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", | 590 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", |
565 "readItemIDB complete"); | 591 "readItemIDB complete"); |
566 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 592 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
567 storage_contents2->GetRenderViewHost(), std::wstring(), | 593 storage_contents2->GetRenderViewHost(), |
| 594 "", |
568 get_value.c_str(), &output)); | 595 get_value.c_str(), &output)); |
569 EXPECT_STREQ("page1", output.c_str()); | 596 EXPECT_STREQ("page1", output.c_str()); |
570 | 597 |
571 // Now write through the second tag and read it back. | 598 // Now write through the second tag and read it back. |
572 ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')", | 599 ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')", |
573 "addItemIDB complete"); | 600 "addItemIDB complete"); |
574 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", | 601 ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)", |
575 "readItemIDB complete"); | 602 "readItemIDB complete"); |
576 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 603 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
577 storage_contents2->GetRenderViewHost(), std::wstring(), | 604 storage_contents2->GetRenderViewHost(), |
| 605 "", |
578 get_value.c_str(), &output)); | 606 get_value.c_str(), &output)); |
579 EXPECT_STREQ("page2", output.c_str()); | 607 EXPECT_STREQ("page2", output.c_str()); |
580 | 608 |
581 // Reset the document title, otherwise the next call will not see a change and | 609 // Reset the document title, otherwise the next call will not see a change and |
582 // will hang waiting for it. | 610 // will hang waiting for it. |
583 EXPECT_TRUE(content::ExecuteJavaScript( | 611 EXPECT_TRUE(content::ExecuteJavaScript( |
584 storage_contents1->GetRenderViewHost(), std::wstring(), | 612 storage_contents1->GetRenderViewHost(), |
585 L"document.title = 'foo'")); | 613 "", |
| 614 "document.title = 'foo'")); |
586 | 615 |
587 // Read through the first tag to ensure we have the second value. | 616 // Read through the first tag to ensure we have the second value. |
588 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", | 617 ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)", |
589 "readItemIDB complete"); | 618 "readItemIDB complete"); |
590 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( | 619 EXPECT_TRUE(ExecuteJavaScriptAndExtractString( |
591 storage_contents1->GetRenderViewHost(), std::wstring(), | 620 storage_contents1->GetRenderViewHost(), |
592 get_value.c_str(), &output)); | 621 "", |
| 622 get_value.c_str(), |
| 623 &output)); |
593 EXPECT_STREQ("page2", output.c_str()); | 624 EXPECT_STREQ("page2", output.c_str()); |
594 | 625 |
595 // Now, let's confirm there is no database in the main browser and another | 626 // Now, let's confirm there is no database in the main browser and another |
596 // tag that doesn't share the same partition. Due to the IndexedDB API design, | 627 // tag that doesn't share the same partition. Due to the IndexedDB API design, |
597 // open will succeed, but the version will be 1, since it creates the database | 628 // open will succeed, but the version will be 1, since it creates the database |
598 // if it is not found. The two tags use database version 3, so we avoid | 629 // if it is not found. The two tags use database version 3, so we avoid |
599 // ambiguity. | 630 // ambiguity. |
600 const char* script = | 631 const char* script = |
601 "indexedDB.open('isolation').onsuccess = function(e) {" | 632 "indexedDB.open('isolation').onsuccess = function(e) {" |
602 " if (e.target.result.version == 1)" | 633 " if (e.target.result.version == 1)" |
603 " document.title = 'db not found';" | 634 " document.title = 'db not found';" |
604 " else " | 635 " else " |
605 " document.title = 'error';" | 636 " document.title = 'error';" |
606 "}"; | 637 "}"; |
607 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0), | 638 ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0), |
608 script, "db not found"); | 639 script, "db not found"); |
609 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); | 640 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); |
610 } | 641 } |
OLD | NEW |