Bug 1509255 - Simulate 'orientationchange' event when RDM viewport is rotated. r=gl

Differential Revision: https://phabricator.services.mozilla.com/D29308

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Micah Tigley 2019-05-03 16:32:22 +00:00
Родитель a0bed7fa3e
Коммит 827e4e2e78
6 изменённых файлов: 72 добавлений и 0 удалений

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

@ -95,6 +95,18 @@ module.exports = {
* Rotate the viewport. * Rotate the viewport.
*/ */
rotateViewport(id) { rotateViewport(id) {
// TODO: Add `orientation` and `angle` properties to message data. See Bug 1357774.
// There is no window object to post to when ran on XPCShell as part of the unit
// tests and will immediately throw an error as a result.
try {
post(window, {
type: "viewport-orientation-change",
});
} catch (e) {
console.log("Unable to post message to window");
}
return { return {
type: ROTATE_VIEWPORT, type: ROTATE_VIEWPORT,
id, id,

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

@ -548,6 +548,9 @@ ResponsiveUI.prototype = {
case "remove-device-association": case "remove-device-association":
this.onRemoveDeviceAssociation(); this.onRemoveDeviceAssociation();
break; break;
case "viewport-orientation-change":
this.onRotateViewport(event);
break;
case "viewport-resize": case "viewport-resize":
this.onResizeViewport(event); this.onResizeViewport(event);
break; break;
@ -637,6 +640,18 @@ ResponsiveUI.prototype = {
}); });
}, },
async onRotateViewport(event) {
const targetFront = await this.client.mainRoot.getTab();
// Ensure that simulateScreenOrientationChange is supported.
if (await targetFront.actorHasMethod("emulation",
"simulateScreenOrientationChange")) {
// TODO: From event.data, pass orientation and angle as arguments.
// See Bug 1357774.
await this.emulationFront.simulateScreenOrientationChange();
}
},
/** /**
* Restores the previous state of RDM. * Restores the previous state of RDM.
*/ */

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

@ -49,6 +49,7 @@ tags = devtools webextensions
[browser_navigation.js] [browser_navigation.js]
skip-if = true # Bug 1413765 skip-if = true # Bug 1413765
[browser_network_throttling.js] [browser_network_throttling.js]
[browser_orientationchange_event.js]
[browser_page_state.js] [browser_page_state.js]
[browser_page_style.js] [browser_page_style.js]
[browser_permission_doorhanger.js] [browser_permission_doorhanger.js]

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

@ -0,0 +1,26 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that the "orientationchange" event is fired when the "rotate button" is clicked.
const TEST_URL = "data:text/html;charset=utf-8,";
addRDMTask(TEST_URL, async function({ ui }) {
info("Rotate viewport to trigger 'orientationchange' event.");
rotateViewport(ui);
await ContentTask.spawn(ui.getViewportBrowser(), {},
async function() {
const orientationChange = new Promise(resolve => {
content.window.addEventListener("orientationchange", () => {
ok(true, "'orientationchange' event fired");
resolve();
});
});
await orientationChange;
}
);
});

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

@ -351,6 +351,19 @@ const EmulationActor = protocol.ActorClassWithSpec(emulationSpec, {
this._printSimulationEnabled = state; this._printSimulationEnabled = state;
this.targetActor.docShell.contentViewer.stopEmulatingMedium(); this.targetActor.docShell.contentViewer.stopEmulatingMedium();
}, },
/**
* Simulates the "orientationchange" event when device screen is rotated.
*
* TODO: Update `window.screen.orientation` and `window.screen.angle` here.
* See Bug 1357774.
*/
simulateScreenOrientationChange() {
const win = this.docShell.chromeEventHandler.ownerGlobal;
const { CustomEvent } = win;
const orientationChangeEvent = new CustomEvent("orientationchange");
win.dispatchEvent(orientationChangeEvent);
},
}); });
exports.EmulationActor = EmulationActor; exports.EmulationActor = EmulationActor;

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

@ -149,6 +149,11 @@ const emulationSpec = generateActorSpec({
}, },
response: {}, response: {},
}, },
simulateScreenOrientationChange: {
request: {},
response: {},
},
}, },
}); });