1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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);
});
|