mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 1687574 - Change test_zoom_restore_bfcache.html to use BroadcastChannel, r=smaug
Also, make sure that BFCachePreventionObserver does not fire events for elements that are part of an anonymous native tree. Differential Revision: https://phabricator.services.mozilla.com/D103812
This commit is contained in:
parent
d904bd0e21
commit
b6692a0ebd
@ -239,6 +239,9 @@ NS_IMPL_ISUPPORTS(BFCachePreventionObserver, nsIMutationObserver)
|
||||
|
||||
void BFCachePreventionObserver::CharacterDataChanged(
|
||||
nsIContent* aContent, const CharacterDataChangeInfo&) {
|
||||
if (aContent->IsInNativeAnonymousSubtree()) {
|
||||
return;
|
||||
}
|
||||
MutationHappened();
|
||||
}
|
||||
|
||||
@ -247,19 +250,31 @@ void BFCachePreventionObserver::AttributeChanged(Element* aElement,
|
||||
nsAtom* aAttribute,
|
||||
int32_t aModType,
|
||||
const nsAttrValue* aOldValue) {
|
||||
if (aElement->IsInNativeAnonymousSubtree()) {
|
||||
return;
|
||||
}
|
||||
MutationHappened();
|
||||
}
|
||||
|
||||
void BFCachePreventionObserver::ContentAppended(nsIContent* aFirstNewContent) {
|
||||
if (aFirstNewContent->IsInNativeAnonymousSubtree()) {
|
||||
return;
|
||||
}
|
||||
MutationHappened();
|
||||
}
|
||||
|
||||
void BFCachePreventionObserver::ContentInserted(nsIContent* aChild) {
|
||||
if (aChild->IsInNativeAnonymousSubtree()) {
|
||||
return;
|
||||
}
|
||||
MutationHappened();
|
||||
}
|
||||
|
||||
void BFCachePreventionObserver::ContentRemoved(nsIContent* aChild,
|
||||
nsIContent* aPreviousSibling) {
|
||||
if (aChild->IsInNativeAnonymousSubtree()) {
|
||||
return;
|
||||
}
|
||||
MutationHappened();
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,75 @@
|
||||
<!doctype html>
|
||||
<script>
|
||||
var bcName = "zoomRestoreBfcache" + window.location.search;
|
||||
var bc = new BroadcastChannel(bcName);
|
||||
if (window.location.search == "?2") {
|
||||
bc.onmessage = (msgEvent) => {
|
||||
var msg = msgEvent.data;
|
||||
var command = msg.command;
|
||||
dump(`Subpage ?2 received command=${command}\n`);
|
||||
switch (command) {
|
||||
case "case2sendData": {
|
||||
bc.postMessage({command: "case2data", devicePixelRatio: window.devicePixelRatio,
|
||||
frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio});
|
||||
break;
|
||||
}
|
||||
case "case2action": {
|
||||
SpecialPowers.spawnChrome([], () => {
|
||||
const FullZoom = this.browsingContext.embedderElement.ownerGlobal.FullZoom;
|
||||
FullZoom.setZoom(2.0);
|
||||
});
|
||||
SpecialPowers.setFullZoom(window, 2);
|
||||
window.requestAnimationFrame(() => window.requestAnimationFrame(() => {
|
||||
bc.postMessage({command: "case2dataAnimationFrame", devicePixelRatio: window.devicePixelRatio,
|
||||
frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio });
|
||||
}));
|
||||
break;
|
||||
}
|
||||
case "case2back": {
|
||||
bc.close();
|
||||
window.history.back();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bc.onmessage = (msgEvent) => {
|
||||
var msg = msgEvent.data;
|
||||
var command = msg.command;
|
||||
dump(`Subpage received command=${command}\n`);
|
||||
switch (command) {
|
||||
case "case1sendData": {
|
||||
bc.postMessage({command: "case1data", devicePixelRatio: window.devicePixelRatio});
|
||||
break;
|
||||
}
|
||||
case "case1click": {
|
||||
document.querySelector("a").click();
|
||||
// We are opening file_zoom_restore_bfcache.html?2, so the current
|
||||
// page is going into bfcache
|
||||
break;
|
||||
}
|
||||
case "case3sendData": {
|
||||
// We came back from bfcache
|
||||
bc.postMessage({command: "case3data", devicePixelRatio: window.devicePixelRatio,
|
||||
frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio});
|
||||
break;
|
||||
}
|
||||
case "close": {
|
||||
SpecialPowers.spawnChrome([], () => {
|
||||
const FullZoom = this.browsingContext.embedderElement.ownerGlobal.FullZoom;
|
||||
FullZoom.setZoom(1.0);
|
||||
});
|
||||
bc.postMessage({command: "closed"});
|
||||
bc.close();
|
||||
window.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener("pageshow", function(e) {
|
||||
window.opener.handlePageShow(e.persisted);
|
||||
bc.postMessage({command: "handlePageShow", eventPersisted: e.persisted});
|
||||
});
|
||||
</script>
|
||||
<a href="?1">This is a very interesting page</a>
|
||||
<a href="?2">This is a very interesting page</a>
|
||||
<iframe srcdoc="And this is a nested frame"></iframe>
|
||||
|
@ -7,34 +7,117 @@
|
||||
<script>
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
/**
|
||||
* - main page (this one) opens file_zoom_restore_bfcache.html
|
||||
* - file_zoom_restore_bfcache.html sends "handlePageShow" to main page
|
||||
* - main page sends file_zoom_restore_bfcache.html "case1sendData"
|
||||
* - file_zoom_restore_bfcache.html sends "case1data" to main page
|
||||
* - main page sends "case1click" to file_zoom_restore_bfcache.html
|
||||
* - file_zoom_restore_bfcache.html clicks on <a> element, navigating to uri
|
||||
* file_zoom_restore_bfcache.html?2, and gets bfcached
|
||||
* - file_zoom_restore_bfcache.html?2 sends "handlePageShow" to main page
|
||||
* - main page sends "case2sendData" to file_zoom_restore_bfcache.html?2
|
||||
* - file_zoom_restore_bfcache.html?2 sends "case2data" to main page
|
||||
* - main page sends "case2action" to file_zoom_restore_bfcache.html?2
|
||||
* - file_zoom_restore_bfcache.html?2 sends "case2dataAnimationFrame" to main page
|
||||
* - main page sends "case2back" to file_zoom_restore_bfcache.html?2
|
||||
* - file_zoom_restore_bfcache.html?2 navigates back to file_zoom_restore_bfcache.html
|
||||
* - file_zoom_restore_bfcache.html sends "handlePageShow" to main page
|
||||
* - main page sends "case3sendData to file_zoom_restore_bfcache.html
|
||||
* - file_zoom_restore_bfcache.html sends "case3data" to main page
|
||||
* - main page sends "close to file_zoom_restore_bfcache.html
|
||||
* - file_zoom_restore_bfcache.html closes bc and window and sends back "closed"
|
||||
**/
|
||||
|
||||
const originalDPR = window.devicePixelRatio;
|
||||
let loadCount = 0;
|
||||
let childWin;
|
||||
var bc = new BroadcastChannel("zoomRestoreBfcache");
|
||||
var bcPage2 = new BroadcastChannel("zoomRestoreBfcache?2");
|
||||
bc.onmessage = (msgEvent) => {
|
||||
var msg = msgEvent.data;
|
||||
var command = msg.command;
|
||||
info(`Main page, received command from normal bc=${command}`);
|
||||
switch (command) {
|
||||
case "handlePageShow": {
|
||||
handlePageShow(msgEvent.data.eventPersisted);
|
||||
break;
|
||||
}
|
||||
case "case1data": {
|
||||
is(loadCount, 1, "Case 1");
|
||||
is(msg.devicePixelRatio, originalDPR, "No zoom");
|
||||
bc.postMessage({command: "case1click"});
|
||||
// The end of case 1
|
||||
break;
|
||||
}
|
||||
case "case3data": {
|
||||
is(loadCount, 2, "Case 3");
|
||||
is(msg.devicePixelRatio, originalDPR * 2, "Should preserve zoom when restored");
|
||||
todo_is(msg.frameDevicePixelRatio, originalDPR * 2, "Should preserve zoom on frames too");
|
||||
bc.postMessage({command: "close"});
|
||||
// Now we wait for "closed"
|
||||
break;
|
||||
}
|
||||
case "closed": {
|
||||
is(loadCount, 2, "Case 3");
|
||||
bc.close();
|
||||
SimpleTest.finish();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ok(false, "should not receive extra messages via BroadcastChannel");
|
||||
}
|
||||
}
|
||||
bcPage2.onmessage = (msgEvent) => {
|
||||
var msg = msgEvent.data;
|
||||
var command = msg.command;
|
||||
info(`Main page, received command from bc?2=${command}`);
|
||||
switch (command) {
|
||||
case "handlePageShow": {
|
||||
handlePageShow(msgEvent.data.eventPersisted);
|
||||
break;
|
||||
}
|
||||
case "case2data": {
|
||||
is(loadCount, 2, "Case 2");
|
||||
is(msg.devicePixelRatio, originalDPR, "No zoom (yet)")
|
||||
is(msg.frameDevicePixelRatio, originalDPR, "No zoom on frame either");
|
||||
bcPage2.postMessage({command: "case2action"});
|
||||
// Now we wait for "case2dataAnimationFrame"
|
||||
break;
|
||||
}
|
||||
case "case2dataAnimationFrame": {
|
||||
is(loadCount, 2, "Case 2");
|
||||
is(msg.devicePixelRatio, originalDPR * 2, "Zoomed");
|
||||
is(msg.frameDevicePixelRatio, originalDPR * 2, "Zoomed iframe too");
|
||||
bcPage2.postMessage({command: "case2back"});
|
||||
bcPage2.close();
|
||||
// The end of case 2
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ok(false, "should not receive extra messages via BroadcastChannel");
|
||||
}
|
||||
}
|
||||
function handlePageShow(persisted) {
|
||||
ok(typeof persisted == "boolean", "Should get the persisted state from the pageshow event");
|
||||
is(persisted, loadCount == 2, "Should've gone into the bfcache after the back navigation");
|
||||
if (loadCount == 2) {
|
||||
ok(persisted, "Should've gone into the bfcache after the back navigation");
|
||||
} else {
|
||||
ok(!persisted, "Should NOT be retrieved from bfcache");
|
||||
}
|
||||
|
||||
if (loadCount == 0) {
|
||||
loadCount++;
|
||||
is(childWin.devicePixelRatio, originalDPR, "No zoom")
|
||||
childWin.document.querySelector("a").click(); // navigate away
|
||||
bc.postMessage({command: "case1sendData"});
|
||||
// Now we wait for the "case1data" message
|
||||
} else if (loadCount == 1) {
|
||||
loadCount++;
|
||||
is(childWin.devicePixelRatio, originalDPR, "No zoom (yet)")
|
||||
is(childWin.document.querySelector("iframe").contentWindow.devicePixelRatio, originalDPR, "No zoom on frame either");
|
||||
SpecialPowers.setFullZoom(childWin, 2);
|
||||
childWin.requestAnimationFrame(() => childWin.requestAnimationFrame(() => {
|
||||
is(childWin.devicePixelRatio, originalDPR * 2, "Zoomed");
|
||||
is(childWin.document.querySelector("iframe").contentWindow.devicePixelRatio, originalDPR * 2, "Zoomed iframe too");
|
||||
childWin.history.back();
|
||||
}));
|
||||
bcPage2.postMessage({command: "case2sendData"});
|
||||
// Now we wait for the "case2data" message
|
||||
} else {
|
||||
is(childWin.devicePixelRatio, originalDPR * 2, "Should preserve zoom when restored");
|
||||
todo_is(childWin.document.querySelector("iframe").contentWindow.devicePixelRatio, originalDPR * 2, "Should preserve zoom on frames too");
|
||||
childWin.close();
|
||||
SimpleTest.finish();
|
||||
bc.postMessage({command: "case3sendData"});
|
||||
// Now we wait for the "case3data" message
|
||||
}
|
||||
}
|
||||
|
||||
childWin = window.open('file_zoom_restore_bfcache.html', '_blank');
|
||||
window.open('file_zoom_restore_bfcache.html', '_blank', 'noopener');
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user