blob: 2f2d3a1a6d12d29d8e27668e739122bb7e811db2 [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 Fredricksonb374a932024-01-30 19:33:2049bool RequestAndCheckStorageAccessForFrame(content::RenderFrameHost* frame,
50 bool omit_user_gesture = false);
Ari Chivukula56f1cde2024-07-03 19:37:3851// Helper to request storage access for a frame using
52// document.requestStorageAccess({estimate: true}) and then check the
53// functionality of the handle.
54bool RequestAndCheckStorageAccessBeyondCookiesForFrame(
55 content::RenderFrameHost* frame);
Matt Reichhoff70f539f52022-08-19 21:35:0156// Helper to request storage access with a site override for a frame using
Matt Reichhoffa0a390d2023-03-16 11:50:3057// document.requestStorageAccessFor(origin). Returns true if the promise
Matt Reichhoff70f539f52022-08-19 21:35:0158// resolves; false if it rejects.
Matt Reichhoffae4453f2022-09-26 22:39:3159bool RequestStorageAccessForOrigin(content::RenderFrameHost* frame,
Chris Fredricksoneed81172024-01-12 18:31:0060 const std::string& origin,
61 bool omit_user_gesture = false);
Chris Fredricksonf39f87b2022-07-11 11:34:0462// Helper to see if a frame currently has storage access using
63// document.hasStorageAccess(). Returns true if the promise resolves with a
64// value of true; false otherwise.
65bool HasStorageAccessForFrame(content::RenderFrameHost* frame);
Brandon Maslen6134c852020-05-18 21:45:2166
Shuran Huangae8c32822023-01-25 21:01:1067// Helper to see if a credentialed fetch has cookies access via top-level
68// storage access grants. Returns the content of the response if the promise
69// resolves. `cors_enabled` sets fetch RequestMode to be "cors" or "no-cors".
70std::string FetchWithCredentials(content::RenderFrameHost* frame,
71 const GURL& url,
72 const bool cors_enabled);
73
Chris Fredricksone90c7a3c2023-03-09 19:40:1874} // namespace storage::test
Brandon Maslen6134c852020-05-18 21:45:2175#endif // CHROME_BROWSER_NET_STORAGE_TEST_UTILS_H_