Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit e85ab31

Browse files
committed
add test
1 parent 36ab9e6 commit e85ab31

File tree

5 files changed

+85
-5
lines changed

5 files changed

+85
-5
lines changed

‎bin/ci/run-tests.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22

33
node ./bin/copy-assets.js --mc firefox
4-
yarn mochi
4+
./node_modules/.bin/mochii --mc ./firefox --default-test-path devtools/client/debugger/new
55
exit $?

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"remark -u devtools-linters/markdown/preset -qf *.md src configs docs",
3131
"lint-fix": "yarn lint-js -- --fix",
3232
"mochi":
33-
"mochii --mc ./firefox --default-test-path devtools/client/debugger/new",
33+
"mochii --mc ./firefox --interactive --default-test-path devtools/client/debugger/new",
3434
"mochid": "yarn mochi -- --jsdebugger --",
3535
"mochir": "yarn mochi -- --repeat 10 --",
3636
"mochih": "yarn mochi -- --setenv MOZ_HEADLESS=1 --",

‎src/components/App.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ class App extends Component {
190190
}
191191

192192
onLayoutChange() {
193+
const orientation = verticalLayoutBreakpoint.matches
194+
? "horizontal"
195+
: "vertical";
193196
if (isVisible()) {
194-
this.props.setOrientation(
195-
verticalLayoutBreakpoint.matches ? "horizontal" : "vertical"
196-
);
197+
this.props.setOrientation(orientation);
197198
}
198199
}
199200

‎src/test/mochitest/browser.ini‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ skip-if = debug # bug 1374187
8585
[browser_dbg_keyboard_navigation.js]
8686
[browser_dbg_keyboard-shortcuts.js]
8787
skip-if = os == "linux" # bug 1351952
88+
[browser_dbg-layout-changes.js]
8889
[browser_dbg-pause-exceptions.js]
8990
skip-if = true # Bug 1393121
9091
[browser_dbg-navigation.js]
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Any copyright is dedicated to the Public Domain.
2+
* http://creativecommons.org/publicdomain/zero/1.0/ */
3+
4+
/**
5+
* This if the debugger's layout is correctly modified when the toolbox's
6+
* host changes.
7+
*/
8+
9+
"use strict";
10+
11+
var gDefaultHostType = Services.prefs.getCharPref("devtools.toolbox.host");
12+
13+
add_task(async function() {
14+
// test is too slow on some platforms due to the number of test cases
15+
requestLongerTimeout(2);
16+
17+
const dbg = await initDebugger("doc-iframes.html");
18+
19+
const layouts = [
20+
["horizontal", "bottom"],
21+
["vertical", "side"],
22+
["horizontal", "window:big"],
23+
["vertical", "window:small"]
24+
]
25+
26+
for (let layout of layouts) {
27+
const [orientation, host] = layout;
28+
await testLayout(dbg, orientation, host)
29+
}
30+
31+
ok(true, "Orientations are correct")
32+
});
33+
34+
async function testLayout(dbg, orientation, host) {
35+
const { panel, toolbox } = dbg;
36+
info(`Switching to ${host} ${orientation}.`);
37+
38+
await switchHost(dbg, host);
39+
await resizeToolboxWindow(dbg, host);
40+
return waitForState(dbg, state => dbg.selectors.getOrientation(state) == orientation)
41+
}
42+
43+
function getHost(host) {
44+
if (host.indexOf("window") == 0) {
45+
return "window";
46+
}
47+
return host;
48+
}
49+
50+
async function switchHost(dbg, hostType) {
51+
const { toolbox } = dbg;
52+
await toolbox.switchHost(getHost(hostType));
53+
}
54+
55+
function resizeToolboxWindow(dbg, host) {
56+
const { panel, toolbox } = dbg;
57+
let sizeOption = host.split(":")[1];
58+
let win = toolbox.win.parent;
59+
60+
let breakpoint = 700;
61+
if (sizeOption == "big" && win.outerWidth <= breakpoint) {
62+
return resizeWindow(dbg, breakpoint + 300);
63+
} else if (sizeOption == "small" && win.outerWidth >= breakpoint) {
64+
return resizeWindow(dbg, breakpoint - 300);
65+
}
66+
}
67+
68+
function resizeWindow(dbg, width) {
69+
const { panel, toolbox } = dbg;
70+
let win = toolbox.win.parent;
71+
const currentWidth = win.screen.width;
72+
win.resizeTo(width, window.screen.availHeight);
73+
}
74+
75+
registerCleanupFunction(function() {
76+
Services.prefs.setCharPref("devtools.toolbox.host", gDefaultHostType);
77+
gDefaultHostType = null;
78+
});

0 commit comments

Comments
 (0)