Add test to verify cache with GetCookiesOnSet feature enabled
A previous CL introduced functionality to update the cookie jar cache on set: http://crrev.com/c/6048964 This CL adds a test to verify that the cache is invalidated if devtools restriction is toggled between operations. This is done simply by getting a cookie with and without devtools enabled to verify a Get->Get flow. We also set a cookie without devtools, turn on devtools, then get the cookie to verify the Set->Get flow. Bug: 380864710 Change-Id: I2798037562a44ef957fdced655011240f53a61a2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6386640 Reviewed-by: Camille Lamy <clamy@chromium.org> Commit-Queue: Joshua Thomas <masnoble@chromium.org> Reviewed-by: Aldo Culquicondor <acondor@chromium.org> Cr-Commit-Position: refs/heads/main@{#1438084}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
9e2d70b5c7
commit
140083668b
@@ -31,6 +31,7 @@
|
||||
#include "content/public/test/content_browser_test.h"
|
||||
#include "content/public/test/content_browser_test_content_browser_client.h"
|
||||
#include "content/public/test/content_browser_test_utils.h"
|
||||
#include "content/public/test/test_devtools_protocol_client.h"
|
||||
#include "content/public/test/test_utils.h"
|
||||
#include "content/shell/browser/shell.h"
|
||||
#include "content/test/content_browser_test_utils_internal.h"
|
||||
@@ -58,6 +59,17 @@ namespace content {
|
||||
|
||||
namespace {
|
||||
|
||||
void EnableDevtoolsThirdPartyCookieRestriction(
|
||||
TestDevToolsProtocolClient& frame_devtools_client) {
|
||||
base::Value::Dict command_params;
|
||||
frame_devtools_client.SendCommandSync("Network.enable");
|
||||
command_params.Set("enableThirdPartyCookieRestriction", true);
|
||||
command_params.Set("disableThirdPartyCookieMetadata", false);
|
||||
command_params.Set("disableThirdPartyCookieHeuristics", false);
|
||||
frame_devtools_client.SendCommandAsync("Network.setCookieControls",
|
||||
std::move(command_params));
|
||||
}
|
||||
|
||||
void SetCookieFromJS(RenderFrameHost* frame, std::string cookie) {
|
||||
EvalJsResult result = EvalJs(frame, "document.cookie = '" + cookie + "'");
|
||||
EXPECT_TRUE(result.error.empty()) << result.error;
|
||||
@@ -321,6 +333,67 @@ IN_PROC_BROWSER_TEST_P(CookieBrowserTest, SameSiteCookies) {
|
||||
EXPECT_EQ("none=1", GetCookieFromJS(b_iframe));
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_P(CookieBrowserTest,
|
||||
CookieJarInvalidatesCacheWithNewDevtoolsControls) {
|
||||
// Must use HTTPS because SameSite=None cookies must be Secure.
|
||||
net::EmbeddedTestServer server(net::EmbeddedTestServer::TYPE_HTTPS);
|
||||
server.SetSSLConfig(net::EmbeddedTestServer::CERT_TEST_NAMES);
|
||||
server.AddDefaultHandlers(GetTestDataFilePath());
|
||||
SetupCrossSiteRedirector(&server);
|
||||
ASSERT_TRUE(server.Start());
|
||||
|
||||
// Set a single cookie that we'll access from a third-party context
|
||||
std::string cookies_to_set =
|
||||
"/set-cookie?none=1;SameSite=None;Secure"; // SameSite=None must be
|
||||
// Secure
|
||||
|
||||
GURL url = server.GetURL("b.test", cookies_to_set);
|
||||
EXPECT_TRUE(NavigateToURL(shell(), url));
|
||||
|
||||
WebContentsImpl* web_contents =
|
||||
static_cast<WebContentsImpl*>(shell()->web_contents());
|
||||
// Turn on third-party cookie restriction from devtools. This needs to happen
|
||||
// from a top level client
|
||||
TestDevToolsProtocolClient devtools_client;
|
||||
devtools_client.AttachToWebContents(web_contents);
|
||||
EnableDevtoolsThirdPartyCookieRestriction(devtools_client);
|
||||
|
||||
url = server.GetURL("a.test",
|
||||
"/cross_site_iframe_factory.html?a.test(b.test())");
|
||||
EXPECT_TRUE(NavigateToURL(shell(), url));
|
||||
|
||||
RenderFrameHost* oop_iframe = web_contents->GetPrimaryFrameTree()
|
||||
.root()
|
||||
->child_at(0)
|
||||
->current_frame_host();
|
||||
|
||||
// Attach devtools client to the sub frame, but disable the controls at first
|
||||
devtools_client.DetachProtocolClient();
|
||||
devtools_client.AttachToFrameTreeHost(oop_iframe);
|
||||
devtools_client.SendCommandSync("Network.disable");
|
||||
|
||||
// Check Get->Get
|
||||
// Overrides should not apply after disabling the controls
|
||||
EXPECT_EQ("none=1", GetCookieFromJS(oop_iframe));
|
||||
|
||||
// Confirm cache is invalidated by observing new value from document.cookie
|
||||
// when re-enabling devtools
|
||||
devtools_client.SendCommandSync("Network.enable");
|
||||
EXPECT_EQ("", GetCookieFromJS(oop_iframe));
|
||||
|
||||
// Check Set->Get
|
||||
// Set a cookie with devtools disabled
|
||||
devtools_client.SendCommandSync("Network.disable");
|
||||
SetCookieFromJS(oop_iframe, "none=2; SameSite=None; Secure");
|
||||
|
||||
// Confirm cache is invalidated by observing no cookie from document.cookie
|
||||
// when re-enabling devtools
|
||||
devtools_client.SendCommandSync("Network.enable");
|
||||
EXPECT_EQ("", GetCookieFromJS(oop_iframe));
|
||||
|
||||
devtools_client.DetachProtocolClient();
|
||||
}
|
||||
|
||||
IN_PROC_BROWSER_TEST_P(CookieBrowserTest, CookieTruncatingCharFromJavascript) {
|
||||
ASSERT_TRUE(embedded_test_server()->Start());
|
||||
|
||||
|
Reference in New Issue
Block a user