Skip to content

Commit 1df91fa

Browse files
committed
Bug 1974167 - [devtools] Use "setOrientationOverride" method instead "setRDMPaneOrientation" for screen orientation emulation. r=devtools-reviewers,jdescottes,devtools-backward-compat-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D263098
1 parent e6e4456 commit 1df91fa

File tree

7 files changed

+120
-72
lines changed

7 files changed

+120
-72
lines changed

devtools/client/responsive/components/App.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,17 @@ class App extends PureComponent {
176176
this.props.dispatch(changeUserAgent(userAgent));
177177
}
178178

179-
onChangeViewportOrientation(id, type, angle, isViewportRotated = false) {
179+
onChangeViewportOrientation(id, type, angle) {
180180
window.postMessage(
181181
{
182182
type: "viewport-orientation-change",
183183
orientationType: type,
184184
angle,
185-
isViewportRotated,
186185
},
187186
"*"
188187
);
189188

190-
if (isViewportRotated) {
191-
this.props.dispatch(changeViewportAngle(id, angle));
192-
}
189+
this.props.dispatch(changeViewportAngle(id, angle));
193190
}
194191

195192
onDeviceListUpdate(devices) {

devtools/client/responsive/test/browser/browser_orientationchange_event.js

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
// Test that the "orientationchange" event is fired when the "rotate button" is clicked.
77

8-
// TODO: This test should also check that the orientation is set properly on the iframe.
9-
// This is currently not working and should be worked on in Bug 1704830.
10-
118
const TEST_DOCUMENT = `doc_with_remote_iframe_and_isolated_cross_origin_capabilities.sjs`;
129
const TEST_COM_URL = URL_ROOT_COM_SSL + TEST_DOCUMENT;
1310

@@ -45,11 +42,20 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
4542
info(
4643
"Check that rotating the viewport does trigger an orientationchange event"
4744
);
45+
let iframeBrowsingContext =
46+
ui.getViewportBrowser().browsingContext.children[0];
47+
4848
let waitForOrientationChangeEvent = isOrientationChangeEventEmitted(
4949
ui.getViewportBrowser()
5050
);
5151
let waitForScreenOrientationChangeEvent =
5252
isWindowScreenOrientationChangeEventEmitted(ui.getViewportBrowser());
53+
54+
let waitForOrientationChangeEventInIframe = isOrientationChangeEventEmitted(
55+
iframeBrowsingContext
56+
);
57+
let waitForScreenOrientationChangeEventInIframe =
58+
isWindowScreenOrientationChangeEventEmitted(iframeBrowsingContext);
5359
rotateViewport(ui);
5460
is(
5561
await waitForOrientationChangeEvent,
@@ -62,6 +68,17 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
6268
"'change' event fired on window.screen.orientation"
6369
);
6470

71+
is(
72+
await waitForOrientationChangeEventInIframe,
73+
true,
74+
"'orientationchange' event fired in iframe"
75+
);
76+
is(
77+
await waitForScreenOrientationChangeEventInIframe,
78+
true,
79+
"'change' event fired on window.screen.orientation in iframe"
80+
);
81+
6582
is(
6683
await getScreenOrientationType(ui.getViewportBrowser()),
6784
"landscape-primary",
@@ -74,8 +91,21 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
7491
"Orientation angle was updated to 90 degrees"
7592
);
7693

94+
is(
95+
await getScreenOrientationType(iframeBrowsingContext),
96+
"landscape-primary",
97+
"Orientation state in iframe was updated to landscape-primary"
98+
);
99+
100+
is(
101+
await getScreenOrientationAngle(iframeBrowsingContext),
102+
90,
103+
"Orientation angle in iframe was updated to 90 degrees"
104+
);
105+
77106
info("Check that the viewport orientation values persist after reload");
78107
await reloadBrowser();
108+
iframeBrowsingContext = ui.getViewportBrowser().browsingContext.children[0];
79109

80110
is(
81111
await getScreenOrientationType(ui.getViewportBrowser()),
@@ -98,6 +128,17 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
98128
"orientation angle was set on the page early in its lifecycle"
99129
);
100130

131+
is(
132+
await getScreenOrientationType(iframeBrowsingContext),
133+
"landscape-primary",
134+
"Orientation is still landscape-primary in iframe"
135+
);
136+
is(
137+
await getScreenOrientationAngle(iframeBrowsingContext),
138+
90,
139+
"Orientation angle is still 90 in iframe"
140+
);
141+
101142
info(
102143
"Check that the viewport orientation values persist after navigating to a page that forces the creation of a new browsing context"
103144
);
@@ -110,6 +151,7 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
110151
URL_ROOT_ORG_SSL + TEST_DOCUMENT + "?crossOriginIsolated=true"
111152
);
112153
await waitForReload();
154+
iframeBrowsingContext = ui.getViewportBrowser().browsingContext.children[0];
113155

114156
isnot(
115157
browser.browsingContext.id,
@@ -138,6 +180,23 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
138180
"orientation angle was set on the page early in its lifecycle"
139181
);
140182

183+
is(
184+
await getScreenOrientationType(iframeBrowsingContext),
185+
"landscape-primary",
186+
"Orientation in iframe is still landscape-primary after navigating to a new browsing context"
187+
);
188+
is(
189+
await getScreenOrientationAngle(iframeBrowsingContext),
190+
90,
191+
"Orientation angle in iframe is still 90 after navigating to a new browsing context"
192+
);
193+
194+
waitForOrientationChangeEvent = isOrientationChangeEventEmitted(
195+
ui.getViewportBrowser()
196+
);
197+
rotateViewport(ui);
198+
await waitForOrientationChangeEvent;
199+
141200
info(
142201
"Check the orientationchange event is not dispatched when changing devices."
143202
);
@@ -147,6 +206,12 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
147206
waitForScreenOrientationChangeEvent =
148207
isWindowScreenOrientationChangeEventEmitted(ui.getViewportBrowser());
149208

209+
waitForOrientationChangeEventInIframe = isOrientationChangeEventEmitted(
210+
iframeBrowsingContext
211+
);
212+
waitForScreenOrientationChangeEventInIframe =
213+
isWindowScreenOrientationChangeEventEmitted(iframeBrowsingContext);
214+
150215
await selectDevice(ui, testDevice.name);
151216
is(
152217
await waitForOrientationChangeEvent,
@@ -159,6 +224,17 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
159224
"on window.screen.orientation, change event was not dispatched when changing devices"
160225
);
161226

227+
is(
228+
await waitForOrientationChangeEventInIframe,
229+
false,
230+
"orientationchange event was not dispatched in iframe when changing devices"
231+
);
232+
is(
233+
await waitForScreenOrientationChangeEventInIframe,
234+
false,
235+
"on window.screen.orientation, change event was not dispatched in iframe when changing devices"
236+
);
237+
162238
info("Check the new orientation values after selecting device.");
163239
is(
164240
await getScreenOrientationType(ui.getViewportBrowser()),
@@ -172,6 +248,18 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
172248
"Orientation angle is 0"
173249
);
174250

251+
is(
252+
await getScreenOrientationType(iframeBrowsingContext),
253+
"portrait-primary",
254+
"New orientation type in iframe is portrait-primary"
255+
);
256+
257+
is(
258+
await getScreenOrientationAngle(iframeBrowsingContext),
259+
0,
260+
"Orientation angle in iframe is 0"
261+
);
262+
175263
info(
176264
"Check the orientationchange event is not dispatched when calling the command with the same orientation."
177265
);
@@ -181,12 +269,17 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
181269
waitForScreenOrientationChangeEvent =
182270
isWindowScreenOrientationChangeEventEmitted(ui.getViewportBrowser());
183271

272+
waitForOrientationChangeEventInIframe = isOrientationChangeEventEmitted(
273+
iframeBrowsingContext
274+
);
275+
waitForScreenOrientationChangeEventInIframe =
276+
isWindowScreenOrientationChangeEventEmitted(iframeBrowsingContext);
277+
184278
// We're directly calling the command here as there's no way to do such action from the UI.
185279
await ui.commands.targetConfigurationCommand.updateConfiguration({
186280
rdmPaneOrientation: {
187281
type: "portrait-primary",
188282
angle: 0,
189-
isViewportRotated: true,
190283
},
191284
});
192285
is(
@@ -199,6 +292,17 @@ addRDMTask(TEST_COM_URL, async function ({ ui }) {
199292
false,
200293
"on window.screen.orientation, change event was not dispatched after trying to set the same orientation again"
201294
);
295+
296+
is(
297+
await waitForOrientationChangeEventInIframe,
298+
false,
299+
"orientationchange event was not dispatched in iframe after trying to set the same orientation again"
300+
);
301+
is(
302+
await waitForScreenOrientationChangeEventInIframe,
303+
false,
304+
"on window.screen.orientation, change event was not dispatched in iframe after trying to set the same orientation again"
305+
);
202306
});
203307

204308
function getScreenOrientationType(browserOrBrowsingContext) {

devtools/client/responsive/ui.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ class ResponsiveUI {
717717
}
718718

719719
async onRotateViewport(event) {
720-
const { orientationType: type, angle, isViewportRotated } = event.data;
721-
await this.updateScreenOrientation(type, angle, isViewportRotated);
720+
const { orientationType: type, angle } = event.data;
721+
await this.updateScreenOrientation(type, angle);
722722
}
723723

724724
async onScreenshot() {
@@ -953,21 +953,12 @@ class ResponsiveUI {
953953
* The orientation type to update the current device screen to.
954954
* @param {Number} angle
955955
* The rotation angle to update the current device screen to.
956-
* @param {Boolean} isViewportRotated
957-
* Whether or not the reason for updating the screen orientation is a result
958-
* of actually rotating the device via the RDM toolbar. If true, then an
959-
* "orientationchange" event is simulated. Otherwise, the screen orientation is
960-
* updated because of changing devices, opening RDM, or the page has been
961-
* reloaded/navigated to, so we should not be simulating "orientationchange".
962956
*/
963-
async updateScreenOrientation(type, angle, isViewportRotated = false) {
964-
await this.commands.targetConfigurationCommand.simulateScreenOrientationChange(
965-
{
966-
type,
967-
angle,
968-
isViewportRotated,
969-
}
970-
);
957+
async updateScreenOrientation(type, angle) {
958+
// We need to call the method on the parent process
959+
await this.commands.targetConfigurationCommand.updateConfiguration({
960+
rdmPaneOrientation: { type, angle },
961+
});
971962
}
972963

973964
/**

devtools/server/actors/emulation/responsive.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,6 @@ class ResponsiveActor extends Actor {
6969
setElementPickerState(state, pickerType) {
7070
this.targetActor.touchSimulator.setElementPickerState(state, pickerType);
7171
}
72-
73-
/**
74-
* Dispatches an "orientationchange" event and an "change" event
75-
* on `window.screen.orientation`.
76-
*/
77-
async dispatchOrientationChangeEvent() {
78-
const { CustomEvent } = this.win;
79-
const orientationChangeEvent = new CustomEvent("orientationchange");
80-
this.win.dispatchEvent(orientationChangeEvent);
81-
this.win.screen.orientation.dispatchEvent(new CustomEvent("change"));
82-
}
8372
}
8473

8574
exports.ResponsiveActor = ResponsiveActor;

devtools/server/actors/target-configuration.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@ class TargetConfigurationActor extends Actor {
476476
* @param {Number} options.angle: The rotated angle of the device.
477477
*/
478478
_setRDMPaneOrientation({ type, angle }) {
479-
this._browsingContext.setRDMPaneOrientation(type, angle);
479+
if (this._browsingContext.inRDMPane) {
480+
this._browsingContext.setOrientationOverride(type, angle);
481+
}
480482
}
481483

482484
/**

devtools/shared/commands/target-configuration/target-configuration-command.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,6 @@ class TargetConfigurationCommand {
8888
const front = await this.getFront();
8989
return !!front.traits.supportedOptions[configurationKey];
9090
}
91-
92-
/**
93-
* Change orientation type and angle (that can be accessed through screen.orientation in
94-
* the content page) and simulates the "orientationchange" event when the device screen
95-
* was rotated.
96-
* Note that this will only be effective if the Responsive Design Mode is enabled.
97-
*
98-
* @param {Object} options
99-
* @param {String} options.type: The orientation type of the rotated device.
100-
* @param {Number} options.angle: The rotated angle of the device.
101-
* @param {Boolean} options.isViewportRotated: Whether or not screen orientation change
102-
* is a result of rotating the viewport. If true, an "orientationchange"
103-
* event will be dispatched in the content window.
104-
*/
105-
async simulateScreenOrientationChange({ type, angle, isViewportRotated }) {
106-
// We need to call the method on the parent process
107-
await this.updateConfiguration({
108-
rdmPaneOrientation: { type, angle },
109-
});
110-
111-
// Don't dispatch the "orientationchange" event if orientation change is a result
112-
// of switching to a new device, location change, or opening RDM.
113-
if (!isViewportRotated) {
114-
return;
115-
}
116-
117-
const responsiveFront =
118-
await this._commands.targetCommand.targetFront.getFront("responsive");
119-
await responsiveFront.dispatchOrientationChangeEvent();
120-
}
12191
}
12292

12393
module.exports = TargetConfigurationCommand;

devtools/shared/specs/responsive.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ const responsiveSpec = generateActorSpec({
2929
},
3030
response: {},
3131
},
32-
33-
dispatchOrientationChangeEvent: {
34-
request: {},
35-
response: {},
36-
},
3732
},
3833
});
3934

0 commit comments

Comments
 (0)