blob: b1ce9481685bdacd56f1b91372ec9eccd3ea7add [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,
27 const base::Location& location = FROM_HERE);
28void SetStorageForWorker(content::RenderFrameHost* frame,
29 const base::Location& location = FROM_HERE);
30void ExpectStorageForFrame(content::RenderFrameHost* frame,
31 bool expected,
32 const base::Location& location = FROM_HERE);
33void ExpectStorageForWorker(content::RenderFrameHost* frame,
34 bool expected,
35 const base::Location& location = FROM_HERE);
Brandon Maslen6134c852020-05-18 21:45:2136
37// Helpers to set and check various types of cross tab info for a given frame.
38// Typically used on page like //chrome/test/data/browsing_data/site_data.html
Chris Fredrickson7cc8c392023-07-31 14:57:4239void SetCrossTabInfoForFrame(content::RenderFrameHost* frame,
40 const base::Location& location = FROM_HERE);
41void ExpectCrossTabInfoForFrame(content::RenderFrameHost* frame,
42 bool expected,
43 const base::Location& location = FROM_HERE);
Brandon Maslen6134c852020-05-18 21:45:2144
45// Helper to request storage access for a frame using
Chris Fredrickson9bb78a02023-06-08 18:06:5946// document.requestStorageAccess() and then get the value of
47// document.hasStorageAccess(). If either call rejects, this helper DCHECKs.
Chris Fredricksone90c7a3c2023-03-09 19:40:1848bool RequestAndCheckStorageAccessForFrame(content::RenderFrameHost* frame);
Matt Reichhoff70f539f52022-08-19 21:35:0149// Helper to request storage access with a site override for a frame using
Matt Reichhoffa0a390d2023-03-16 11:50:3050// document.requestStorageAccessFor(origin). Returns true if the promise
Matt Reichhoff70f539f52022-08-19 21:35:0151// resolves; false if it rejects.
Matt Reichhoffae4453f2022-09-26 22:39:3152bool RequestStorageAccessForOrigin(content::RenderFrameHost* frame,
53 const std::string& origin);
Chris Fredricksonf39f87b2022-07-11 11:34:0454// Helper to see if a frame currently has storage access using
55// document.hasStorageAccess(). Returns true if the promise resolves with a
56// value of true; false otherwise.
57bool HasStorageAccessForFrame(content::RenderFrameHost* frame);
Brandon Maslen6134c852020-05-18 21:45:2158
Shuran Huangae8c32822023-01-25 21:01:1059// Helper to see if a credentialed fetch has cookies access via top-level
60// storage access grants. Returns the content of the response if the promise
61// resolves. `cors_enabled` sets fetch RequestMode to be "cors" or "no-cors".
62std::string FetchWithCredentials(content::RenderFrameHost* frame,
63 const GURL& url,
64 const bool cors_enabled);
65
Chris Fredricksone90c7a3c2023-03-09 19:40:1866} // namespace storage::test
Brandon Maslen6134c852020-05-18 21:45:2167#endif // CHROME_BROWSER_NET_STORAGE_TEST_UTILS_H_