Bug 1652244 - P4. Fix test_third_party.html test failure r=timhuang

This testcase has:
top-level: mochi.test
1st-level: host (depend on the value in the test data)
2nd-level: mochi.test

This test run tests in the 2nd-level iframe, which is first-party with
respect to the top-level according to the new change.

The test is re-written to run tests in both 1st-level iframe and
2nd-level iframes.

Differential Revision: https://phabricator.services.mozilla.com/D86717
This commit is contained in:
Dimi Lee 2020-08-12 09:11:01 +00:00
parent fbc8bb1f4b
commit 8b5b04028f
3 changed files with 52 additions and 21 deletions

View file

@ -16,25 +16,21 @@
const BEHAVIOR_LIMITFOREIGN = 3;
const testData = [
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
{ host: "http://example.com", cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
{ host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_ACCEPT, expectedResult: true },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_ACCEPT, expectedResultFrame1: true, expectedResultFrame2: true },
{ host: "http://example.com", cookieBehavior: BEHAVIOR_ACCEPT, expectedResultFrame1: true, expectedResultFrame2: true },
{ host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_ACCEPT, expectedResultFrame1: true, expectedResultFrame2: true },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
{ host: "http://example.com", cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
{ host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECT, expectedResult: false },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECT, expectedResultFrame1: false, expectedResultFrame2: false },
{ host: "http://example.com", cookieBehavior: BEHAVIOR_REJECT, expectedResultFrame1: false, expectedResultFrame2: false },
{ host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECT, expectedResultFrame1: false, expectedResultFrame2: false },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: true },
{ host: "http://example.com", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: false },
{ host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: false },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResult: true },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResultFrame1: true, expectedResultFrame2: true },
{ host: "http://example.com", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResultFrame1: false, expectedResultFrame2: true },
{ host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_REJECTFOREIGN, expectedResultFrame1: false, expectedResultFrame2: true },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: true },
{ host: "http://example.com", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: false },
{ host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: false },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResult: true },
{ host: "http://" + window.location.host, cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResultFrame1: true, expectedResultFrame2: true },
{ host: "http://example.com", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResultFrame1: false, expectedResultFrame2: true },
{ host: "http://sub1.test2.example.org:8000", cookieBehavior: BEHAVIOR_LIMITFOREIGN, expectedResultFrame1: false, expectedResultFrame2: true },
];
const iframe1Path =
@ -67,6 +63,7 @@
});
}
let testFrames = ["iframe1", "iframe2"];
function messageListener(event) {
let message = JSON.parse(event.data);
@ -76,12 +73,26 @@
// automatically stringified.
let testContext = `testData[${testIndex}] == ${JSON.stringify(testData[testIndex])}`;
is(message.source, "iframe", `Good source for ${testContext}`);
is(message.result, testData[testIndex].expectedResult, `Good result for ${testContext}`);
let idx = testFrames.indexOf(message.source);
if (idx != -1) {
testFrames.splice(idx, 1);
if (message.source == "iframe1") {
is(message.result, testData[testIndex].expectedResultFrame1, `Good result for ${testContext} iframe1`);
} else if (message.source == "iframe2") {
is(message.result, testData[testIndex].expectedResultFrame2, `Good result for ${testContext} iframe2`);
}
} else {
ok(false, 'Test has already received a message from ${message.source}');
}
if (testFrames.length > 0) {
return;
}
openedWindow.close();
if (testIndex < testData.length - 1) {
testFrames = ["iframe1", "iframe2"];
testIndex++;
openWindow();
return;

View file

@ -13,15 +13,35 @@
if (message.source == "parent") {
document.getElementById("iframe2").src = message.href;
}
else if (message.source == "iframe") {
else if (message.source == "iframe2") {
parent.postMessage(event.data, "*");
}
}
function report(result) {
let message = { source: "iframe1" };
message.result = result;
window.parent.postMessage(JSON.stringify(message), "*");
}
function runIndexedDBTest() {
window.addEventListener('message', messageListener);
try {
let request = indexedDB.open(window.location.pathname, 1);
request.onsuccess = function(event) {
report(!!(event.target.result instanceof IDBDatabase));
};
}
catch (e) {
report(false);
}
}
</script>
</head>
<body onload="window.addEventListener('message', messageListener, false);">
<body onload="runIndexedDBTest();">
<iframe id="iframe2"></iframe>
</body>

View file

@ -8,7 +8,7 @@
<script type="text/javascript">
function report(result) {
let message = { source: "iframe" };
let message = { source: "iframe2" };
message.result = result;
window.parent.postMessage(JSON.stringify(message), "*");
}