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