blob: 968fdc5555efa38698dbe0bdf71bd2986c0450e6 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2020 The Chromium Authors
Brandon Maslen6134c852020-05-18 21:45:212// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_NET_STORAGE_TEST_UTILS_H_
6#define CHROME_BROWSER_NET_STORAGE_TEST_UTILS_H_
7
8#include <string>
9
Chris Fredrickson7cc8c392023-07-31 14:57:4210#include "base/location.h"
11
Shuran Huangae8c32822023-01-25 21:01:1012class GURL;
13
Brandon Maslen6134c852020-05-18 21:45:2114namespace content {
Brandon Maslen6134c852020-05-18 21:45:2115class RenderFrameHost;
16} // namespace content
17
Chris Fredricksone90c7a3c2023-03-09 19:40:1818namespace storage::test {
Brandon Maslen6134c852020-05-18 21:45:2119
Chris Fredricksonf39f87b2022-07-11 11:34:0420// Gets the text content of a given frame.
21std::string GetFrameContent(content::RenderFrameHost* frame);
Brandon Maslen6134c852020-05-18 21:45:2122
23// Helpers to set and check various types of storage on a given frame. Typically
24// used on page like //chrome/test/data/browsing_data/site_data.html
Chris Fredrickson7cc8c392023-07-31 14:57:4225void SetStorageForFrame(content::RenderFrameHost* frame,
26 bool include_cookies,
Jonathan Njeunjea63e3832023-10-03 11:58:0427 bool expected_to_be_set = true,
Chris Fredrickson7cc8c392023-07-31 14:57:4228 const base::Location& location = FROM_HERE);
29void SetStorageForWorker(content::RenderFrameHost* frame,
30 const base::Location& location = FROM_HERE);
31void ExpectStorageForFrame(content::RenderFrameHost* frame,
32 bool expected,
33 const base::Location& location = FROM_HERE);
34void ExpectStorageForWorker(content::RenderFrameHost* frame,
35 bool expected,
36 const base::Location& location = FROM_HERE);
Brandon Maslen6134c852020-05-18 21:45:2137
38// Helpers to set and check various types of cross tab info for a given frame.
39// Typically used on page like //chrome/test/data/browsing_data/site_data.html
Chris Fredrickson7cc8c392023-07-31 14:57:4240void SetCrossTabInfoForFrame(content::RenderFrameHost* frame,
41 const base::Location& location = FROM_HERE);
42void ExpectCrossTabInfoForFrame(content::RenderFrameHost* frame,
43 bool expected,
44 const base::Location& location = FROM_HERE);
Brandon Maslen6134c852020-05-18 21:45:2145
46// Helper to request storage access for a frame using
Chris Fredrickson9bb78a02023-06-08 18:06:5947// document.requestStorageAccess() and then get the value of
48// document.hasStorageAccess(). If either call rejects, this helper DCHECKs.
Chris Fredricksone90c7a3c2023-03-09 19:40:1849bool RequestAndCheckStorageAccessForFrame(content::RenderFrameHost* frame);
Matt Reichhoff70f539f52022-08-19 21:35:0150// Helper to request storage access with a site override for a frame using
Matt Reichhoffa0a390d2023-03-16 11:50:3051// document.requestStorageAccessFor(origin). Returns true if the promise
Matt Reichhoff70f539f52022-08-19 21:35:0152// resolves; false if it rejects.
Matt Reichhoffae4453f2022-09-26 22:39:3153bool RequestStorageAccessForOrigin(content::RenderFrameHost* frame,
54 const std::string& origin);
Chris Fredricksonf39f87b2022-07-11 11:34:0455// Helper to see if a frame currently has storage access using
56// document.hasStorageAccess(). Returns true if the promise resolves with a
57// value of true; false otherwise.
58bool HasStorageAccessForFrame(content::RenderFrameHost* frame);
Brandon Maslen6134c852020-05-18 21:45:2159
Shuran Huangae8c32822023-01-25 21:01:1060// Helper to see if a credentialed fetch has cookies access via top-level
61// storage access grants. Returns the content of the response if the promise
62// resolves. `cors_enabled` sets fetch RequestMode to be "cors" or "no-cors".
63std::string FetchWithCredentials(content::RenderFrameHost* frame,
64 const GURL& url,
65 const bool cors_enabled);
66
Chris Fredricksone90c7a3c2023-03-09 19:40:1867} // namespace storage::test
Brandon Maslen6134c852020-05-18 21:45:2168#endif // CHROME_BROWSER_NET_STORAGE_TEST_UTILS_H_