Skip to content

Commit

Permalink
Consolidate set_test_context for cookie tests
Browse files Browse the repository at this point in the history
Now that we need this to be called in a third location, we should really
establish a helper function we can use. This was written in response to:
#32558

closes #32558

Change-Id: I41baf407d64a709f7c696d53562c184e9970d74c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3418519
Auto-Submit: Ari Chivukula <arichiv@chromium.org>
Reviewed-by: Mike Taylor <miketaylr@chromium.org>
Commit-Queue: Ari Chivukula <arichiv@chromium.org>
Cr-Commit-Position: refs/heads/main@{#963789}
  • Loading branch information
arichiv authored and chromium-wpt-export-bot committed Jan 27, 2022
1 parent 85ed979 commit bce83b4
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 10 deletions.
6 changes: 1 addition & 5 deletions cookies/attributes/resources/path-redirect-shared.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Note: this function has a dependency on testdriver.js. Any test files calling
// it should include testdriver.js and testdriver-vendor.js
window.addEventListener("message", (e) => {
let test_window = window.top;
while (test_window.opener && !test_window.opener.closed) {
test_window = test_window.opener.top;
}
test_driver.set_test_context(test_window);
setTestContextUsingRootWindow();
if (e.data == "getAndExpireCookiesForRedirectTest") {
const cookies = document.cookie;
test_driver.delete_all_cookies().then(() => {
Expand Down
1 change: 1 addition & 0 deletions cookies/attributes/resources/path.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/cookies/resources/cookie-test.js"></script>
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions cookies/attributes/resources/path/one.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/cookies/resources/cookie-test.js"></script>
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions cookies/attributes/resources/path/three.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/cookies/resources/cookie-test.js"></script>
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions cookies/attributes/resources/path/two.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/cookies/resources/cookie-test.js"></script>
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions cookies/attributes/resources/pathfakeout.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/cookies/resources/cookie-test.js"></script>
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions cookies/attributes/resources/pathfakeout/one.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/cookies/resources/cookie-test.js"></script>
<script src="/cookies/attributes/resources/path-redirect-shared.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions cookies/attributes/resources/secure-non-secure-child.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</head>
<body>
<script>
setTestContextUsingRootWindow();
// These tests are the non-secure analog to secure.https.html.
// They're not in the /cookies/attributes folder because they shouldn't
// be run by themselves. Instead, /cookies/attributes/secure.https.html
Expand Down
12 changes: 12 additions & 0 deletions cookies/resources/cookie-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,15 @@ function getCtlCharacters() {
function cookieStringWithNameAndValueLengths(nameLength, valueLength) {
return `${"t".repeat(nameLength)}=${"1".repeat(valueLength)}`;
}

// Finds the root window.top.opener and directs test_driver commands to it.
//
// If you see a message like: "Error: Tried to run in a non-testharness window
// without a call to set_test_context." then you probably need to call this.
function setTestContextUsingRootWindow() {
let test_window = window.top;
while (test_window.opener && !test_window.opener.closed) {
test_window = test_window.opener.top;
}
test_driver.set_test_context(test_window);
}
7 changes: 2 additions & 5 deletions cookies/resources/echo-cookie.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name=help href="http://tools.ietf.org/html/rfc6265#section-5.1.4">
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/cookies/resources/cookie-test.js"></script>
</head>
<body>
<script>
Expand All @@ -21,11 +22,7 @@
// Note: this function has a dependency on testdriver.js. Any test files calling
// it should include testdriver.js and testdriver-vendor.js
window.expireCookies = async () => {
let test_window = window.top;
while (test_window.opener && !test_window.opener.closed) {
test_window = test_window.opener.top;
}
test_driver.set_test_context(test_window);
setTestContextUsingRootWindow();
await test_driver.delete_all_cookies();
};
window.getCookies = () => document.cookie;
Expand Down

0 comments on commit bce83b4

Please sign in to comment.