chrome/browser/extensions/web_view_browsertest.cc
// This tests that in-memory storage partitions are reset on browser restart,
// but persistent ones maintain state for cookies and HTML5 storage.
This tests that in-memory storage partitions are reset on browser restart,
but persistent ones maintain state for cookies and HTML5 storage.
This tests that in - memory storage partitions are reset on browser restart but persistent ones maintain state for cookies and HTML5 storage .
IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_StoragePersistence) {
  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 = 'inmemory=true; path=/; expires=' + expire + ';';");
  std::wstring cookie_script2(kExpire);
  cookie_script2.append(
      L"document.cookie = 'persist1=true; path=/; expires=' + expire + ';';");
  std::wstring cookie_script3(kExpire);
  cookie_script3.append(
      L"document.cookie = 'persist2=true; path=/; expires=' + expire + ';';");
  GURL blank_url("about:blank");
  content::WebContents* cookie_contents1;
  content::WebContents* cookie_contents2;
  content::WebContents* named_partition_contents1;
  content::WebContents* named_partition_contents2;
  content::WebContents* persistent_partition_contents1;
  content::WebContents* persistent_partition_contents2;
  content::WebContents* persistent_partition_contents3;
  NavigateAndOpenAppForIsolation(blank_url, &cookie_contents1,
                                 &cookie_contents2, &named_partition_contents1,
                                 &named_partition_contents2,
                                 &persistent_partition_contents1,
                                 &persistent_partition_contents2,
                                 &persistent_partition_contents3);
  EXPECT_TRUE(content::ExecuteJavaScript(
      cookie_contents1->GetRenderViewHost(), std::wstring(),
      cookie_script1));
  EXPECT_TRUE(content::ExecuteJavaScript(
      named_partition_contents1->GetRenderViewHost(), std::wstring(),
      cookie_script1));
  EXPECT_TRUE(content::ExecuteJavaScript(
      persistent_partition_contents1->GetRenderViewHost(), std::wstring(),
      cookie_script2));
  EXPECT_TRUE(content::ExecuteJavaScript(
      persistent_partition_contents3->GetRenderViewHost(), std::wstring(),
      cookie_script3));
  int cookie_size;
  std::string cookie_value;
  automation_util::GetCookies(GURL("http://localhost"),
                              cookie_contents1,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("inmemory=true", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              cookie_contents2,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("inmemory=true", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              named_partition_contents1,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("inmemory=true", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              named_partition_contents2,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("inmemory=true", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              persistent_partition_contents1,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("persist1=true", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              persistent_partition_contents2,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("persist1=true", cookie_value);
  automation_util::GetCookies(GURL("http://localhost"),
                              persistent_partition_contents3,
                              &cookie_size, &cookie_value);
  EXPECT_EQ("persist2=true", cookie_value);
}
IN_PROC_BROWSER_TEST_F ( WebViewTest , PRE_StoragePersistence ) { 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" " ) ; std :: wstring cookie_script3 ( kExpire ) ; cookie_script3 . append ( L" " ) ; GURL blank_url ( " " ) ; content :: WebContents * cookie_contents1 ; content :: WebContents * cookie_contents2 ; content :: WebContents * named_partition_contents1 ; content :: WebContents * named_partition_contents2 ; content :: WebContents * persistent_partition_contents1 ; content :: WebContents * persistent_partition_contents2 ; content :: WebContents * persistent_partition_contents3 ; NavigateAndOpenAppForIsolation ( blank_url , & cookie_contents1 , & cookie_contents2 , & named_partition_contents1 , & named_partition_contents2 , & persistent_partition_contents1 , & persistent_partition_contents2 , & persistent_partition_contents3 ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( cookie_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , cookie_script1 ) ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( named_partition_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , cookie_script1 ) ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( persistent_partition_contents1 -> GetRenderViewHost ( ) , std :: wstring ( ) , cookie_script2 ) ) ; EXPECT_TRUE ( content :: ExecuteJavaScript ( persistent_partition_contents3 -> GetRenderViewHost ( ) , std :: wstring ( ) , cookie_script3 ) ) ; int cookie_size ; std :: string 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 ) ; automation_util :: GetCookies ( GURL ( " " ) , named_partition_contents2 , & cookie_size , & cookie_value ) ; EXPECT_EQ ( " " , cookie_value ) ; automation_util :: GetCookies ( GURL ( " " ) , persistent_partition_contents1 , & cookie_size , & cookie_value ) ; EXPECT_EQ ( " " , cookie_value ) ; automation_util :: GetCookies ( GURL ( " " ) , persistent_partition_contents2 , & cookie_size , & cookie_value ) ; EXPECT_EQ ( " " , cookie_value ) ; automation_util :: GetCookies ( GURL ( " " ) , persistent_partition_contents3 , & cookie_size , & cookie_value ) ; EXPECT_EQ ( " " , cookie_value ) ; }
This tests that in-memory storage partitions are reset on browser restart,
but persistent ones maintain state for cookies and HTML5 storage.
This tests that in - memory storage partitions are reset on browser restart but persistent ones maintain state for cookies and HTML5 storage .
// We don't care where the main browser is on this test. // 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. // Set the inmemory=true cookie for tags with inmemory partitions. // For the two different persistent storage partitions, set the // two different cookies so we can check that they aren't comingled below. // Check that all in-memory partitions have a cookie set. // Check that all persistent partitions kept their state.