Bug 1656768 - Add a test to ensure sessionStorage is propagated from non-cross-origin-isolated to cross-origin-isolated window and vice versa; r=nika

Differential Revision: https://phabricator.services.mozilla.com/D97763
This commit is contained in:
Tom Tung 2020-11-30 08:56:42 +00:00
Родитель 2da514629e
Коммит bc86e6cbe8
4 изменённых файлов: 93 добавлений и 7 удалений

Просмотреть файл

@ -80,6 +80,8 @@ support-files =
[browser_sessionStorage_navigation.js]
support-files =
file_empty.html
file_coop_coep.html
file_coop_coep.html^headers^
[browser_test_focus_after_modal_state.js]
skip-if = verify
support-files =

Просмотреть файл

@ -6,10 +6,11 @@ const DIRPATH = getRootDirectory(gTestPath).replace(
);
const PATH = DIRPATH + "file_empty.html";
const ORIGIN1 = "http://example.com";
const ORIGIN2 = "http://example.org";
const ORIGIN1 = "https://example.com";
const ORIGIN2 = "https://example.org";
const URL1 = `${ORIGIN1}/${PATH}`;
const URL2 = `${ORIGIN2}/${PATH}`;
const URL1_WITH_COOP_COEP = `${ORIGIN1}/${DIRPATH}file_coop_coep.html`;
add_task(async function() {
await BrowserTestUtils.withNewTab(URL1, async function(browser) {
@ -34,8 +35,8 @@ add_task(async function() {
is(
value1,
null,
`SessionStroage for ${key} in ${content.window.origin} is null since` +
` it's the first visit`
`SessionStorage for ${key} in ${content.window.origin} is null ` +
`since it's the first visit`
);
content.window.sessionStorage.setItem(key, value);
@ -44,7 +45,8 @@ add_task(async function() {
is(
value2,
value,
`SessionStorage for ${key} in ${content.window.origin} is set correctly`
`SessionStorage for ${key} in ${content.window.origin} is set ` +
`correctly`
);
}
);
@ -62,7 +64,7 @@ add_task(async function() {
is(
value1,
null,
`SessionStroage for ${key} in ${content.window.origin} is null ` +
`SessionStorage for ${key} in ${content.window.origin} is null ` +
`since it's the first visit`
);
}
@ -116,7 +118,8 @@ add_task(async function() {
is(
value1,
value,
`SessionStorage for ${key} in ${content.window.origin} is preserved`
`SessionStorage for ${key} in ${content.window.origin} is ` +
`preserved`
);
}
);
@ -164,5 +167,84 @@ add_task(async function() {
);
}
);
info(
`Verifying the sessionStorage for a tab shares between ` +
`cross-origin-isolated and non cross-origin-isolated environments`
);
const anotherKey = `anotherKey`;
const anotherValue = `anotherValue;`;
BrowserTestUtils.loadURI(browser, URL1_WITH_COOP_COEP);
await BrowserTestUtils.browserLoaded(browser);
await SpecialPowers.spawn(
browser,
[ORIGIN1, key, value, anotherKey, anotherValue],
async (ORIGIN, key, value, anotherKey, anotherValue) => {
is(content.window.origin, ORIGIN, `Navigate to ${ORIGIN} as expected`);
ok(
content.window.crossOriginIsolated,
`The window is cross-origin-isolated.`
);
let value1 = content.window.sessionStorage.getItem(key);
is(
value1,
value,
`SessionStorage for ${key} in ${content.window.origin} was ` +
`propagated to COOP+COEP process correctly.`
);
let value2 = content.window.sessionStorage.getItem(anotherKey);
is(
value2,
null,
`SessionStorage for ${anotherKey} in ${content.window.origin} ` +
`hasn't been set yet.`
);
content.window.sessionStorage.setItem(anotherKey, anotherValue);
let value3 = content.window.sessionStorage.getItem(anotherKey);
is(
value3,
anotherValue,
`SessionStorage for ${anotherKey} in ${content.window.origin} ` +
`was set as expected.`
);
}
);
BrowserTestUtils.loadURI(browser, URL1);
await BrowserTestUtils.browserLoaded(browser);
await SpecialPowers.spawn(
browser,
[ORIGIN1, key, value, anotherKey, anotherValue],
async (ORIGIN, key, value, anotherKey, anotherValue) => {
is(content.window.origin, ORIGIN, `Navigate to ${ORIGIN} as expected`);
ok(
!content.window.crossOriginIsolated,
`The window is not cross-origin-isolated.`
);
let value1 = content.window.sessionStorage.getItem(key);
is(
value1,
value,
`SessionStorage for ${key} in ${content.window.origin} is ` +
`preserved.`
);
let value2 = content.window.sessionStorage.getItem(anotherKey);
is(
value2,
anotherValue,
`SessionStorage for ${anotherKey} in ${content.window.origin} was ` +
`propagated to non-COOP+COEP process correctly.`
);
}
);
});
});

Просмотреть файл

Просмотреть файл

@ -0,0 +1,2 @@
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp