chrome/browser/extensions/web_view_browsertest.cc
// This tests IndexedDB isolation for packaged apps with webview tags. It loads
// an app with multiple webview tags and each tag creates an IndexedDB record,
// which the test checks to ensure proper storage isolation is enforced.
This tests IndexedDB isolation for packaged apps with webview tags. It loads
an app with multiple webview tags and each tag creates an IndexedDB record,
which the test checks to ensure proper storage isolation is enforced.
This tests IndexedDB isolation for packaged apps with webview tags . It loads an app with multiple webview tags and each tag creates an IndexedDB record which the test checks to ensure proper storage isolation is enforced .
IN_PROC_BROWSER_TEST_F(WebViewTest, IndexedDBIsolation) {
  ASSERT_TRUE(StartTestServer());
  GURL regular_url = test_server()->GetURL("files/title1.html");
  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);
  ExecuteScriptWaitForTitle(storage_contents1, "initIDB()", "idb created");
  ExecuteScriptWaitForTitle(storage_contents1, "addItemIDB(7, 'page1')",
                            "addItemIDB complete");
  ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
                            "readItemIDB complete");
  std::string output;
  std::wstring get_value(
      L"window.domAutomationController.send(getValueIDB() || 'badval')");
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents1->GetRenderViewHost(), std::wstring(),
      get_value.c_str(), &output));
  EXPECT_STREQ("page1", output.c_str());
  ExecuteScriptWaitForTitle(storage_contents2, "initIDB()", "idb open");
  ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
                            "readItemIDB complete");
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents2->GetRenderViewHost(), std::wstring(),
      get_value.c_str(), &output));
  EXPECT_STREQ("page1", output.c_str());
  ExecuteScriptWaitForTitle(storage_contents2, "addItemIDB(7, 'page2')",
                            "addItemIDB complete");
  ExecuteScriptWaitForTitle(storage_contents2, "readItemIDB(7)",
                            "readItemIDB complete");
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents2->GetRenderViewHost(), std::wstring(),
      get_value.c_str(), &output));
  EXPECT_STREQ("page2", output.c_str());
  EXPECT_TRUE(content::ExecuteJavaScript(
      storage_contents1->GetRenderViewHost(), std::wstring(),
      L"document.title = 'foo'"));
  ExecuteScriptWaitForTitle(storage_contents1, "readItemIDB(7)",
                            "readItemIDB complete");
  EXPECT_TRUE(ExecuteJavaScriptAndExtractString(
      storage_contents1->GetRenderViewHost(), std::wstring(),
      get_value.c_str(), &output));
  EXPECT_STREQ("page2", output.c_str());
  const char* script =
    "indexedDB.open('isolation').onsuccess = function(e) {"
    "  if (e.target.result.version == 1)"
    "    document.title = 'db not found';"
    "  else "
    "    document.title = 'error';"
    "}";
  ExecuteScriptWaitForTitle(chrome::GetWebContentsAt(browser(), 0),
                            script, "db not found");
  ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found");
}
IN_PROC_BROWSER_TEST_F ( WebViewTest , IndexedDBIsolation ) { ASSERT_TRUE ( StartTestServer ( ) ) ; GURL regular_url = test_server ( ) -> GetURL ( " " ) ; 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 ) ; ExecuteScriptWaitForTitle ( storage_contents1 , " " , " " ) ; ExecuteScriptWaitForTitle ( storage_contents1 , " " , " " ) ; ExecuteScriptWaitForTitle ( storage_contents1 , " " , " " ) ; std :: string output ; std :: wstring get_value ( L" " ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_value . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; ExecuteScriptWaitForTitle ( storage_contents2 , " " , " " ) ; ExecuteScriptWaitForTitle ( storage_contents2 , " " , " " ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents2 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_value . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; ExecuteScriptWaitForTitle ( storage_contents2 , " " , " " ) ; ExecuteScriptWaitForTitle ( storage_contents2 , " " , " " ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents2 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_value . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( storage_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , L" " ) ) ; ExecuteScriptWaitForTitle ( storage_contents1 , " " , " " ) ; EXPECT_TRUE ( ExecuteJavaScriptAndExtractString ( storage_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , get_value . c_str ( ) , & output ) ) ; EXPECT_STREQ ( " " , output . c_str ( ) ) ; const char * script = " " " " " " " " " " " " ; ExecuteScriptWaitForTitle ( chrome :: GetWebContentsAt ( browser ( ) , 0 ) , script , " " ) ; ExecuteScriptWaitForTitle ( default_tag_contents1 , script , " " ) ; }
This tests IndexedDB isolation for packaged apps with webview tags.
This tests IndexedDB isolation for packaged apps with webview tags .
// Initialize the storage for the first of the two tags that share a storage // partition. // Initialize the db in the second tag. // Since we share a partition, reading the value should return the existing // one. // Now write through the second tag and read it back. // Reset the document title, otherwise the next call will not see a change and // will hang waiting for it. // Read through the first tag to ensure we have the second value. // Now, let's confirm there is no database in the main browser and another // tag that doesn't share the same partition. Due to the IndexedDB API design, // open will succeed, but the version will be 1, since it creates the database // if it is not found. The two tags use database version 3, so we avoid // ambiguity.