summaryrefslogtreecommitdiffstats
path: root/devtools/client/responsivedesign/test/browser_responsiveuiaddcustompreset.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/responsivedesign/test/browser_responsiveuiaddcustompreset.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/responsivedesign/test/browser_responsiveuiaddcustompreset.js')
-rw-r--r--devtools/client/responsivedesign/test/browser_responsiveuiaddcustompreset.js121
1 files changed, 121 insertions, 0 deletions
diff --git a/devtools/client/responsivedesign/test/browser_responsiveuiaddcustompreset.js b/devtools/client/responsivedesign/test/browser_responsiveuiaddcustompreset.js
new file mode 100644
index 000000000..3ab54b601
--- /dev/null
+++ b/devtools/client/responsivedesign/test/browser_responsiveuiaddcustompreset.js
@@ -0,0 +1,121 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(function* () {
+ let tab = yield addTab("data:text/html;charset=utf8,Test RDM custom presets");
+
+ let { rdm, manager } = yield openRDM(tab);
+
+ let oldPrompt = Services.prompt;
+ Services.prompt = {
+ value: "",
+ returnBool: true,
+ prompt: function (parent, dialogTitle, text, value, checkMsg, checkState) {
+ value.value = this.value;
+ return this.returnBool;
+ }
+ };
+
+ registerCleanupFunction(() => {
+ Services.prompt = oldPrompt;
+ });
+
+ // Is it open?
+ let container = gBrowser.getBrowserContainer();
+ is(container.getAttribute("responsivemode"), "true",
+ "Should be in responsive mode.");
+
+ ok(rdm, "RDM instance should be attached to the tab.");
+
+ // Tries to add a custom preset and cancel the prompt
+ let idx = rdm.menulist.selectedIndex;
+ let presetCount = rdm.presets.length;
+
+ Services.prompt.value = "";
+ Services.prompt.returnBool = false;
+ rdm.addbutton.doCommand();
+
+ is(idx, rdm.menulist.selectedIndex,
+ "selected item shouldn't change after add preset and cancel");
+ is(presetCount, rdm.presets.length,
+ "number of presets shouldn't change after add preset and cancel");
+
+ // Adds the custom preset with "Testing preset"
+ Services.prompt.value = "Testing preset";
+ Services.prompt.returnBool = true;
+
+ let resized = once(manager, "content-resize");
+ let customHeight = 123, customWidth = 456;
+ rdm.startResizing({});
+ rdm.setViewportSize({
+ width: customWidth,
+ height: customHeight,
+ });
+ rdm.stopResizing({});
+
+ rdm.addbutton.doCommand();
+ yield resized;
+
+ yield closeRDM(rdm);
+
+ ({rdm} = yield openRDM(tab));
+ is(container.getAttribute("responsivemode"), "true",
+ "Should be in responsive mode.");
+
+ let presetLabel = "456" + "\u00D7" + "123 (Testing preset)";
+ let customPresetIndex = yield getPresetIndex(rdm, manager, presetLabel);
+ ok(customPresetIndex >= 0, "(idx = " + customPresetIndex + ") should be the" +
+ " previously added preset in the list of items");
+
+ yield setPresetIndex(rdm, manager, customPresetIndex);
+
+ let browser = gBrowser.selectedBrowser;
+ yield ContentTask.spawn(browser, null, function* () {
+ let {innerWidth, innerHeight} = content;
+ Assert.equal(innerWidth, 456, "Selecting preset should change the width");
+ Assert.equal(innerHeight, 123, "Selecting preset should change the height");
+ });
+
+ info(`menulist count: ${rdm.menulist.itemCount}`);
+
+ rdm.removebutton.doCommand();
+
+ yield setPresetIndex(rdm, manager, 2);
+ let deletedPresetA = rdm.menulist.selectedItem.getAttribute("label");
+ rdm.removebutton.doCommand();
+
+ yield setPresetIndex(rdm, manager, 2);
+ let deletedPresetB = rdm.menulist.selectedItem.getAttribute("label");
+ rdm.removebutton.doCommand();
+
+ yield closeRDM(rdm);
+ ({rdm} = yield openRDM(tab));
+
+ customPresetIndex = yield getPresetIndex(rdm, manager, deletedPresetA);
+ is(customPresetIndex, -1,
+ "Deleted preset " + deletedPresetA + " should not be in the list anymore");
+
+ customPresetIndex = yield getPresetIndex(rdm, manager, deletedPresetB);
+ is(customPresetIndex, -1,
+ "Deleted preset " + deletedPresetB + " should not be in the list anymore");
+
+ yield closeRDM(rdm);
+});
+
+var getPresetIndex = Task.async(function* (rdm, manager, presetLabel) {
+ var testOnePreset = Task.async(function* (c) {
+ if (c == 0) {
+ return -1;
+ }
+ yield setPresetIndex(rdm, manager, c);
+
+ let item = rdm.menulist.firstChild.childNodes[c];
+ if (item.getAttribute("label") === presetLabel) {
+ return c;
+ }
+ return testOnePreset(c - 1);
+ });
+ return testOnePreset(rdm.menulist.firstChild.childNodes.length - 4);
+});