Commit 87483a42 authored by cfredric's avatar cfredric Committed by Chromium LUCI CQ

Add browsertests for SameSite/SameParty HTTP cookie access.

Change-Id: I3f0c448a4ecb1e7a629db48954e50a5b3e0a9985
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2621672Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarLily Chen <chlily@chromium.org>
Commit-Queue: Chris Fredrickson <cfredric@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844313}
parent da020d47
This diff is collapsed.
......@@ -6,6 +6,7 @@
#include <stddef.h>
#include <cstdint>
#include <set>
#include <tuple>
#include <utility>
......@@ -1913,7 +1914,8 @@ std::vector<net::CanonicalCookie> GetCanonicalCookies(
bool SetCookie(BrowserContext* browser_context,
const GURL& url,
const std::string& value,
net::CookieOptions::SameSiteCookieContext context) {
net::CookieOptions::SameSiteCookieContext context,
net::CookieOptions::SamePartyCookieContextType party_context) {
bool result = false;
base::RunLoop run_loop;
mojo::Remote<network::mojom::CookieManager> cookie_manager;
......@@ -1927,6 +1929,7 @@ bool SetCookie(BrowserContext* browser_context,
net::CookieOptions options;
options.set_include_httponly();
options.set_same_site_cookie_context(context);
options.set_same_party_cookie_context_type(party_context);
cookie_manager->SetCanonicalCookie(
*cc.get(), url, options,
base::BindOnce(
......@@ -1940,6 +1943,29 @@ bool SetCookie(BrowserContext* browser_context,
return result;
}
uint32_t DeleteCookies(BrowserContext* browser_context,
network::mojom::CookieDeletionFilter filter) {
base::RunLoop run_loop;
mojo::Remote<network::mojom::CookieManager> cookie_manager;
BrowserContext::GetDefaultStoragePartition(browser_context)
->GetNetworkContext()
->GetCookieManager(cookie_manager.BindNewPipeAndPassReceiver());
uint32_t result = 0U;
cookie_manager->DeleteCookies(
network::mojom::CookieDeletionFilter::New(filter),
base::BindOnce(
[](uint32_t* result, base::RunLoop* run_loop,
uint32_t cookies_cleared) {
*result = cookies_cleared;
run_loop->Quit();
},
&result, &run_loop));
run_loop.Run();
return result;
}
void FetchHistogramsFromChildProcesses() {
// Wait for all the renderer processes to be initialized before fetching
// histograms for the first time.
......
......@@ -902,14 +902,21 @@ std::vector<net::CanonicalCookie> GetCanonicalCookies(
BrowserContext* browser_context,
const GURL& url);
// Sets a cookie for the given url. Uses an inclusive SameSiteCookieContext by
// default, which gets cookies regardless of their SameSite attribute. Returns
// true on success.
// Sets a cookie for the given url. Uses inclusive SameSiteCookieContext and
// SamePartyCookieContextType by default, which get cookies regardless of their
// SameSite and SameParty attributes. Returns true on success.
bool SetCookie(BrowserContext* browser_context,
const GURL& url,
const std::string& value,
net::CookieOptions::SameSiteCookieContext context =
net::CookieOptions::SameSiteCookieContext::MakeInclusive());
net::CookieOptions::SameSiteCookieContext::MakeInclusive(),
net::CookieOptions::SamePartyCookieContextType party_context =
net::CookieOptions::SamePartyCookieContextType::kSameParty);
// Deletes cookies matching the provided filter. Returns the number of cookies
// that were deleted.
uint32_t DeleteCookies(BrowserContext* browser_context,
network::mojom::CookieDeletionFilter filter);
// Fetch the histograms data from other processes. This should be called after
// the test code has been executed but before performing assertions.
......
......@@ -1074,6 +1074,7 @@ test("content_browsertests") {
"../browser/navigation_browsertest.cc",
"../browser/navigation_mhtml_browsertest.cc",
"../browser/net/accept_header_browsertest.cc",
"../browser/net/http_cookie_browsertest.cc",
"../browser/net/net_command_line_flags_browsertest.cc",
"../browser/net/network_field_trial_browsertest.cc",
"../browser/net/split_cache_browsertest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment