|
18 | 18 | #include "components/prefs/pref_service.h"
|
19 | 19 | #include "content/public/browser/notification_types.h"
|
20 | 20 | #include "content/public/browser/render_frame_host.h"
|
| 21 | +#include "content/public/browser/storage_partition.h" |
21 | 22 | #include "content/public/browser/web_contents.h"
|
22 | 23 | #include "content/public/test/browser_test.h"
|
23 | 24 | #include "content/public/test/test_navigation_observer.h"
|
@@ -449,3 +450,56 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest,
|
449 | 450 | EXPECT_EQ("", private_values.iframe_1.cookies);
|
450 | 451 | EXPECT_EQ("", private_values.iframe_2.cookies);
|
451 | 452 | }
|
| 453 | + |
| 454 | +IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, |
| 455 | + NavigationCookiesArePartitioned) { |
| 456 | + AllowAllCookies(); |
| 457 | + |
| 458 | + GURL a_site_set_cookie_url = https_server_.GetURL( |
| 459 | + "a.com", "/set-cookie?name=acom;path=/;SameSite=None;Secure"); |
| 460 | + GURL b_site_set_cookie_url = https_server_.GetURL( |
| 461 | + "b.com", "/set-cookie?name=bcom;path=/;SameSite=None;Secure"); |
| 462 | + |
| 463 | + ui_test_utils::NavigateToURL(browser(), a_site_set_cookie_url); |
| 464 | + ui_test_utils::NavigateToURL(browser(), b_site_set_cookie_url); |
| 465 | + ui_test_utils::NavigateToURL(browser(), a_site_ephemeral_storage_url_); |
| 466 | + |
| 467 | + std::string a_cookie = |
| 468 | + content::GetCookies(browser()->profile(), GURL("https://a.com/")); |
| 469 | + std::string b_cookie = |
| 470 | + content::GetCookies(browser()->profile(), GURL("https://b.com/")); |
| 471 | + EXPECT_EQ("name=acom", a_cookie); |
| 472 | + EXPECT_EQ("name=bcom", b_cookie); |
| 473 | + |
| 474 | + // The third-party iframe should not have the b.com cookie that was set on the |
| 475 | + // main frame. |
| 476 | + auto* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 477 | + RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 478 | + RenderFrameHost* iframe_a = content::ChildFrameAt(main_frame, 0); |
| 479 | + RenderFrameHost* iframe_b = content::ChildFrameAt(main_frame, 0); |
| 480 | + ASSERT_EQ("", GetCookiesInFrame(iframe_a)); |
| 481 | + ASSERT_EQ("", GetCookiesInFrame(iframe_b)); |
| 482 | + |
| 483 | + // Setting the cookie directly on the third-party iframe should only set the |
| 484 | + // cookie in the ephemeral storage area for that frame. |
| 485 | + GURL b_site_set_ephemeral_cookie_url = https_server_.GetURL( |
| 486 | + "b.com", "/set-cookie?name=bcom_ephemeral;path=/;SameSite=None;Secure"); |
| 487 | + NavigateIframeToURL(web_contents, "third_party_iframe_a", |
| 488 | + b_site_set_ephemeral_cookie_url); |
| 489 | + ASSERT_EQ("name=bcom_ephemeral", GetCookiesInFrame(iframe_a)); |
| 490 | + ASSERT_EQ("name=bcom_ephemeral", GetCookiesInFrame(iframe_b)); |
| 491 | + |
| 492 | + // The cookie set in the ephemeral area should not visible in the main |
| 493 | + // cookie storage. |
| 494 | + b_cookie = content::GetCookies(browser()->profile(), GURL("https://b.com/")); |
| 495 | + EXPECT_EQ("name=bcom", b_cookie); |
| 496 | + |
| 497 | + // Navigating to a new TLD should clear all ephemeral cookies. |
| 498 | + ui_test_utils::NavigateToURL(browser(), b_site_ephemeral_storage_url_); |
| 499 | + ui_test_utils::NavigateToURL(browser(), a_site_ephemeral_storage_url_); |
| 500 | + |
| 501 | + ValuesFromFrames values_after = GetValuesFromFrames(web_contents); |
| 502 | + EXPECT_EQ("name=acom", values_after.main_frame.cookies); |
| 503 | + EXPECT_EQ("", values_after.iframe_1.cookies); |
| 504 | + EXPECT_EQ("", values_after.iframe_2.cookies); |
| 505 | +} |
0 commit comments