chrome/browser/extensions/web_view_browsertest.cc
// This tests cookie isolation for packaged apps with webview tags. It navigates
// the main browser window to a page that sets a cookie and loads an app with
// multiple webview tags. Each tag sets a cookie and the test checks the proper
// storage isolation is enforced.
This tests cookie isolation for packaged apps with webview tags. It navigates
the main browser window to a page that sets a cookie and loads an app with
multiple webview tags. Each tag sets a cookie and the test checks the proper
storage isolation is enforced.
This tests cookie isolation for packaged apps with webview tags . It navigates the main browser window to a page that sets a cookie and loads an app with multiple webview tags . Each tag sets a cookie and the test checks the proper storage isolation is enforced .
IN_PROC_BROWSER_TEST_F(WebViewTest, CookieIsolation) {
  ASSERT_TRUE(StartTestServer());
  const std::wstring kExpire =
      L"var expire = new Date(Date.now() + 24 * 60 * 60 * 1000);";
  std::wstring cookie_script1(kExpire);
  cookie_script1.append(
      L"document.cookie = 'guest1=true; path=/; expires=' + expire + ';';");
  std::wstring cookie_script2(kExpire);
  cookie_script2.append(
      L"document.cookie = 'guest2=true; path=/; expires=' + expire + ';';");
  GURL::Replacements replace_host;
  std::string host_str("localhost");  
  replace_host.SetHostStr(host_str);
  GURL set_cookie_url = test_server()->GetURL(
      "files/extensions/platform_apps/isolation/set_cookie.html");
  set_cookie_url = set_cookie_url.ReplaceComponents(replace_host);
  content::WebContents* cookie_contents1;
  content::WebContents* cookie_contents2;
  content::WebContents* named_partition_contents1;
  content::WebContents* named_partition_contents2;
  NavigateAndOpenAppForIsolation(set_cookie_url, &cookie_contents1,
                                 &cookie_contents2, &named_partition_contents1,
                                 &named_partition_contents2, NULL, NULL, NULL);
  EXPECT_TRUE(content::ExecuteJavaScript(
      cookie_contents1->GetRenderViewHost(), std::wstring(), cookie_script1));
  EXPECT_TRUE(content::ExecuteJavaScript(
      cookie_contents2->GetRenderViewHost(), std::wstring(), cookie_script2));
  int cookie_size;
  std::string cookie_value;
  automation_util::GetCookies(GURL("http://localhost"),
                              chrome::GetWebContentsAt(browser(), 0),
                              &cookie_size, &cookie_value);
  EXPECT_EQ("testCookie=1", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              cookie_contents1,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("guest1=true; guest2=true", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              cookie_contents2,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("guest1=true; guest2=true", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              named_partition_contents1,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("", cookie_value);
}
IN_PROC_BROWSER_TEST_F ( WebViewTest , CookieIsolation ) { ASSERT_TRUE ( StartTestServer ( ) ) ; const std :: wstring kExpire = L" " ; std :: wstring cookie_script1 ( kExpire ) ; cookie_script1 . append ( L" " ) ; std :: wstring cookie_script2 ( kExpire ) ; cookie_script2 . append ( L" " ) ; GURL :: Replacements replace_host ; std :: string host_str ( " " ) ; replace_host . SetHostStr ( host_str ) ; GURL set_cookie_url = test_server ( ) -> GetURL ( " " ) ; set_cookie_url = set_cookie_url . ReplaceComponents ( replace_host ) ; content :: WebContents * cookie_contents1 ; content :: WebContents * cookie_contents2 ; content :: WebContents * named_partition_contents1 ; content :: WebContents * named_partition_contents2 ; NavigateAndOpenAppForIsolation ( set_cookie_url , & cookie_contents1 , & cookie_contents2 , & named_partition_contents1 , & named_partition_contents2 , NULL , NULL , NULL ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( cookie_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , cookie_script1 ) ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( cookie_contents2 -> GetRenderViewHost ( ) , std :: wstring ( ) , cookie_script2 ) ) ; int cookie_size ; std :: string cookie_value ; automation_util :: GetCookies ( GURL ( " " ) , chrome :: GetWebContentsAt ( browser ( ) , 0 ) , & cookie_size , & cookie_value ) ; EXPECT_EQ ( " " , cookie_value ) ; automation_util :: GetCookies ( GURL ( " " ) , cookie_contents1 , & cookie_size , & cookie_value ) ; EXPECT_EQ ( " " , cookie_value ) ; automation_util :: GetCookies ( GURL ( " " ) , cookie_contents2 , & cookie_size , & cookie_value ) ; EXPECT_EQ ( " " , cookie_value ) ; automation_util :: GetCookies ( GURL ( " " ) , named_partition_contents1 , & cookie_size , & cookie_value ) ; EXPECT_EQ ( " " , cookie_value ) ; }
This tests cookie isolation for packaged apps with webview tags.
This tests cookie isolation for packaged apps with webview tags .
// Must stay in scope with replace_host. // The first two partitions will be used to set cookies and ensure they are // shared. The named partition is used to ensure that cookies are isolated // between partitions within the same app. // Test the regular browser context to ensure we have only one cookie. // The default behavior is to combine webview tags with no explicit partition // declaration into the same in-memory partition. Test the webview tags to // ensure we have properly set the cookies and we have both cookies in both // tags. // The third tag should not have any cookies as it is in a separate partition.