Skip to content

Commit

Permalink
Attempt de-flaking of requestStorageAccess WPT tests
Browse files Browse the repository at this point in the history
Analysis of the `nested-same-origin-frame` test indicated it sometimes
reported having user activation, and a call to requestStorageAccess()
would then pass when it was expected to fail. The belief is that this
is an artifact of interleaving of iframe loads with the simulated
click on the page, so we instead wait for the iframe tests to complete
before simulating activation.

Bug: 1054577,1229084
Change-Id: I3f9294bbdafc92ff95e20f82e60d09f27f5e7a45
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3846044
Reviewed-by: Brandon Maslen <[email protected]>
Commit-Queue: Matt Reichhoff <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1038771}
  • Loading branch information
mreichhoff authored and chromium-wpt-export-bot committed Aug 24, 2022
1 parent 8af9a10 commit 595d0a1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 18 deletions.
10 changes: 10 additions & 0 deletions storage-access-api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
function RunTestsInIFrame(sourceURL) {
let frame = document.createElement('iframe');
frame.src = sourceURL;
let result = new Promise((resolve, reject) => {
frame.onload = resolve;
frame.onerror = reject;
});
document.body.appendChild(frame);
fetch_tests_from_window(frame.contentWindow);
return result;
}

function RunTestsInNestedIFrame(sourceURL) {
let nestedFrame = document.createElement('iframe');
document.body.appendChild(nestedFrame);
let result = new Promise((resolve, reject) => {
nestedFrame.onload = resolve;
nestedFrame.onerror = reject;
});
let content = `
<script src="/resources/testharness.js"></script>
<script src="helpers.js"></script>
Expand All @@ -22,6 +31,7 @@ function RunTestsInNestedIFrame(sourceURL) {
nestedFrame.contentDocument.write(content);
nestedFrame.contentDocument.close();
fetch_tests_from_window(nestedFrame.contentWindow);
return result;
}

let g_clickID = 0;
Expand Down
55 changes: 37 additions & 18 deletions storage-access-api/requestStorageAccess.sub.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,48 @@ if (topLevelDocument) {
// of various iFrames

// Create a test with a single-child same-origin iframe.
RunTestsInIFrame("resources/requestStorageAccess-iframe.html?testCase=same-origin-frame&rootdocument=false");
let sameOriginFramePromise = RunTestsInIFrame(
'resources/requestStorageAccess-iframe.html?testCase=same-origin-frame&rootdocument=false');

// Create a test with a single-child cross-origin iframe.
RunTestsInIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/resources/requestStorageAccess-iframe.html?testCase=cross-origin-frame&rootdocument=false");
let crossOriginFramePromise = RunTestsInIFrame(
'http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/resources/requestStorageAccess-iframe.html?testCase=cross-origin-frame&rootdocument=false');

// Validate the nested-iframe scenario where the same-origin frame containing
// the tests is not the first child.
RunTestsInNestedIFrame("resources/requestStorageAccess-iframe.html?testCase=nested-same-origin-frame&rootdocument=false");
// Validate the nested-iframe scenario where the same-origin frame
// containing the tests is not the first child.
let nestedSameOriginFramePromise = RunTestsInNestedIFrame(
'resources/requestStorageAccess-iframe.html?testCase=nested-same-origin-frame&rootdocument=false');

// Validate the nested-iframe scenario where the cross-origin frame containing
// the tests is not the first child.
RunTestsInNestedIFrame("http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/resources/requestStorageAccess-iframe.html?testCase=nested-cross-origin-frame&rootdocument=false");
// Validate the nested-iframe scenario where the cross-origin frame
// containing the tests is not the first child.
let nestedCrossOriginFramePromise = RunTestsInNestedIFrame(
'http://{{domains[www]}}:{{ports[http][0]}}/storage-access-api/resources/requestStorageAccess-iframe.html?testCase=nested-cross-origin-frame&rootdocument=false')

promise_test(async t => {
await test_driver.set_permission({ name: 'storage-access' }, 'granted');
// Because the iframe tests expect no user activation, and because they
// load asynchronously, we want to first run those tests before simulating
// clicks on the page.
Promise
.all([
sameOriginFramePromise,
crossOriginFramePromise,
nestedSameOriginFramePromise,
nestedCrossOriginFramePromise,
])
.then(x => {
promise_test(
async t => {
await test_driver.set_permission(
{name: 'storage-access'}, 'granted');

var access_promise;
let testMethod = function() {
access_promise = document.requestStorageAccess();
};
await ClickButtonWithGesture(testMethod);

return access_promise;
}, "[" + testPrefix + "] document.requestStorageAccess() should be resolved when called properly with a user gesture");
var access_promise;
let testMethod = function() {
access_promise = document.requestStorageAccess();
};
await ClickButtonWithGesture(testMethod);

return access_promise;
},
'[' + testPrefix +
'] document.requestStorageAccess() should be resolved when called properly with a user gesture');
});
}

0 comments on commit 595d0a1

Please sign in to comment.