Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 2 | // 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 Fredrickson | 7cc8c39 | 2023-07-31 14:57:42 | [diff] [blame] | 10 | #include "base/location.h" |
| 11 | |
Shuran Huang | ae8c3282 | 2023-01-25 21:01:10 | [diff] [blame] | 12 | class GURL; |
| 13 | |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 14 | namespace content { |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 15 | class RenderFrameHost; |
| 16 | } // namespace content |
| 17 | |
Chris Fredrickson | e90c7a3c | 2023-03-09 19:40:18 | [diff] [blame] | 18 | namespace storage::test { |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 19 | |
Chris Fredrickson | f39f87b | 2022-07-11 11:34:04 | [diff] [blame] | 20 | // Gets the text content of a given frame. |
| 21 | std::string GetFrameContent(content::RenderFrameHost* frame); |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 22 | |
| 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 Fredrickson | 7cc8c39 | 2023-07-31 14:57:42 | [diff] [blame] | 25 | void SetStorageForFrame(content::RenderFrameHost* frame, |
| 26 | bool include_cookies, |
Jonathan Njeunje | a63e383 | 2023-10-03 11:58:04 | [diff] [blame] | 27 | bool expected_to_be_set = true, |
Chris Fredrickson | 7cc8c39 | 2023-07-31 14:57:42 | [diff] [blame] | 28 | const base::Location& location = FROM_HERE); |
| 29 | void SetStorageForWorker(content::RenderFrameHost* frame, |
| 30 | const base::Location& location = FROM_HERE); |
| 31 | void ExpectStorageForFrame(content::RenderFrameHost* frame, |
| 32 | bool expected, |
| 33 | const base::Location& location = FROM_HERE); |
| 34 | void ExpectStorageForWorker(content::RenderFrameHost* frame, |
| 35 | bool expected, |
| 36 | const base::Location& location = FROM_HERE); |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 37 | |
| 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 Fredrickson | 7cc8c39 | 2023-07-31 14:57:42 | [diff] [blame] | 40 | void SetCrossTabInfoForFrame(content::RenderFrameHost* frame, |
| 41 | const base::Location& location = FROM_HERE); |
| 42 | void ExpectCrossTabInfoForFrame(content::RenderFrameHost* frame, |
| 43 | bool expected, |
| 44 | const base::Location& location = FROM_HERE); |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 45 | |
| 46 | // Helper to request storage access for a frame using |
Chris Fredrickson | 9bb78a0 | 2023-06-08 18:06:59 | [diff] [blame] | 47 | // document.requestStorageAccess() and then get the value of |
| 48 | // document.hasStorageAccess(). If either call rejects, this helper DCHECKs. |
Chris Fredrickson | b374a93 | 2024-01-30 19:33:20 | [diff] [blame] | 49 | bool RequestAndCheckStorageAccessForFrame(content::RenderFrameHost* frame, |
| 50 | bool omit_user_gesture = false); |
Ari Chivukula | 56f1cde | 2024-07-03 19:37:38 | [diff] [blame] | 51 | // Helper to request storage access for a frame using |
| 52 | // document.requestStorageAccess({estimate: true}) and then check the |
| 53 | // functionality of the handle. |
| 54 | bool RequestAndCheckStorageAccessBeyondCookiesForFrame( |
| 55 | content::RenderFrameHost* frame); |
Matt Reichhoff | 70f539f5 | 2022-08-19 21:35:01 | [diff] [blame] | 56 | // Helper to request storage access with a site override for a frame using |
Matt Reichhoff | a0a390d | 2023-03-16 11:50:30 | [diff] [blame] | 57 | // document.requestStorageAccessFor(origin). Returns true if the promise |
Matt Reichhoff | 70f539f5 | 2022-08-19 21:35:01 | [diff] [blame] | 58 | // resolves; false if it rejects. |
Matt Reichhoff | ae4453f | 2022-09-26 22:39:31 | [diff] [blame] | 59 | bool RequestStorageAccessForOrigin(content::RenderFrameHost* frame, |
Chris Fredrickson | eed8117 | 2024-01-12 18:31:00 | [diff] [blame] | 60 | const std::string& origin, |
| 61 | bool omit_user_gesture = false); |
Chris Fredrickson | f39f87b | 2022-07-11 11:34:04 | [diff] [blame] | 62 | // 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. |
| 65 | bool HasStorageAccessForFrame(content::RenderFrameHost* frame); |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 66 | |
Shuran Huang | ae8c3282 | 2023-01-25 21:01:10 | [diff] [blame] | 67 | // 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". |
| 70 | std::string FetchWithCredentials(content::RenderFrameHost* frame, |
| 71 | const GURL& url, |
| 72 | const bool cors_enabled); |
| 73 | |
Chris Fredrickson | e90c7a3c | 2023-03-09 19:40:18 | [diff] [blame] | 74 | } // namespace storage::test |
Brandon Maslen | 6134c85 | 2020-05-18 21:45:21 | [diff] [blame] | 75 | #endif // CHROME_BROWSER_NET_STORAGE_TEST_UTILS_H_ |