chrome/browser/extensions/web_view_browsertest.cc
// This tests DOM storage isolation for packaged apps with webview tags. It
// loads an app with multiple webview tags and each tag sets DOM storage
// entries, which the test checks to ensure proper storage isolation is
// enforced.
This tests DOM storage isolation for packaged apps with webview tags. It
loads an app with multiple webview tags and each tag sets DOM storage
entries, which the test checks to ensure proper storage isolation is
enforced.
This tests DOM storage isolation for packaged apps with webview tags . It loads an app with multiple webview tags and each tag sets DOM storage entries which the test checks to ensure proper storage isolation is enforced .
IN_PROC_BROWSER_TEST_F(WebViewTest, DOMStorageIsolation) {
  ASSERT_TRUE(StartTestServer());
  GURL regular_url = test_server()->GetURL("files/title1.html");
  std::string output;
  std::wstring get_local_storage(L"window.domAutomationController.send("
      L"window.localStorage.getItem('foo') || 'badval')");
  std::wstring get_session_storage(L"window.domAutomationController.send("
      L"window.sessionStorage.getItem('bar') || 'badval')");
  content::WebContents* default_tag_contents1;
  content::WebContents* default_tag_contents2;
  content::WebContents* storage_contents1;
  content::WebContents* storage_contents2;
  NavigateAndOpenAppForIsolation(regular_url, &default_tag_contents1,
                                 &default_tag_contents2, &storage_contents1,
                                 &storage_contents2, NULL, NULL, NULL);
  EXPECT_TRUE(content::ExecuteJavaScript(
      storage_contents1->GetRenderViewHost(), std::wstring(),
      L"initDomStorage('page1')"));
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents1->GetRenderViewHost(), std::wstring(),
      get_local_storage.c_str(), &output));
  EXPECT_STREQ("local-page1", output.c_str());
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents1->GetRenderViewHost(), std::wstring(),
      get_session_storage.c_str(), &output));
  EXPECT_STREQ("session-page1", output.c_str());
  EXPECT_TRUE(content::ExecuteJavaScript(
      storage_contents2->GetRenderViewHost(), std::wstring(),
      L"initDomStorage('page2')"));
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents1->GetRenderViewHost(), std::wstring(),
      get_local_storage.c_str(), &output));
  EXPECT_STREQ("local-page2", output.c_str());
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents2->GetRenderViewHost(), std::wstring(),
      get_local_storage.c_str(), &output));
  EXPECT_STREQ("local-page2", output.c_str());
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents1->GetRenderViewHost(), std::wstring(),
      get_session_storage.c_str(), &output));
  EXPECT_STREQ("session-page1", output.c_str());
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents2->GetRenderViewHost(), std::wstring(),
      get_session_storage.c_str(), &output));
  EXPECT_STREQ("session-page2", output.c_str());
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(),
      std::wstring(), get_local_storage.c_str(), &output));
  EXPECT_STREQ("badval", output.c_str());
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(),
      std::wstring(), get_session_storage.c_str(), &output));
  EXPECT_STREQ("badval", output.c_str());
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      default_tag_contents1->GetRenderViewHost(), std::wstring(),
      get_local_storage.c_str(), &output));
  EXPECT_STREQ("badval", output.c_str());
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      default_tag_contents1->GetRenderViewHost(), std::wstring(),
      get_session_storage.c_str(), &output));
  EXPECT_STREQ("badval", output.c_str());
}
IN_PROC_BROWSER_TEST_F ( WebViewTest , DOMStorageIsolation ) { ASSERT_TRUE ( StartTestServer ( ) ) ; GURL regular_url = test_server ( ) -> GetURL ( " " ) ; std :: string output ; std :: wstring get_local_storage ( L" " L" " ) ; std :: wstring get_session_storage ( L" " L" " ) ; content :: WebContents * default_tag_contents1 ; content :: WebContents * default_tag_contents2 ; content :: WebContents * storage_contents1 ; content :: WebContents * storage_contents2 ; NavigateAndOpenAppForIsolation ( regular_url , & default_tag_contents1 , & default_tag_contents2 , & storage_contents1 , & storage_contents2 , NULL , NULL , NULL ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( storage_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , L" " ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_local_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_session_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( storage_contents2 -> GetRenderViewHost ( ) , std :: wstring ( ) , L" " ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_local_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents2 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_local_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_session_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents2 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_session_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( chrome :: GetWebContentsAt ( browser ( ) , 0 ) -> GetRenderViewHost ( ) , std :: wstring ( ) , get_local_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( chrome :: GetWebContentsAt ( browser ( ) , 0 ) -> GetRenderViewHost ( ) , std :: wstring ( ) , get_session_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( default_tag_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_local_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( default_tag_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_session_storage . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; }
This tests DOM storage isolation for packaged apps with webview tags.
This tests DOM storage isolation for packaged apps with webview tags .
// Initialize the storage for the first of the two tags that share a storage // partition. // Let's test that the expected values are present in the first tag, as they // will be overwritten once we call the initDomStorage on the second tag. // Now, init the storage in the second tag in the same storage partition, // which will overwrite the shared localStorage. // The localStorage value now should reflect the one written through the // second tag. // Session storage is not shared though, as each webview tag has separate // instance, even if they are in the same storage partition. // Also, let's check that the main browser and another tag that doesn't share // the same partition don't have those values stored.