Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: chrome/content/tests/ui/icon_position.js

Issue 5390879414026240: Issue 101 - Fix icon tests (Closed)
Patch Set: reverted wrong change, sorry! Created July 31, 2014, 11:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 let {application} = require("info"); 3 let {application} = require("info");
4 if (application != "firefox") 4 if (application != "firefox")
5 return; 5 return;
6 6
7 let CustomizableUI = null;
8 let usingShim = false;
9 try
10 {
11 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", nul l);
12 }
13 catch (e)
14 {
15 usingShim = true;
16 // No built-in CustomizableUI API, use our own implementation.
17 ({CustomizableUI}) = require("customizableUI");
18 }
19
7 let wnd = Utils.getChromeWindow(window); 20 let wnd = Utils.getChromeWindow(window);
8 let toolbox = wnd.document.getElementById("navigator-toolbox"); 21 let toolbox = wnd.document.getElementById("navigator-toolbox");
9 if (!toolbox) 22 if (!toolbox)
10 return; 23 return;
Wladimir Palant 2014/07/31 11:36:15 This is only relevant when we are using the shim -
11 24
12 module("Icon position", { 25 module("Icon position", {
13 setup: function() 26 setup: function()
14 { 27 {
15 this.oldPosition = toolbox.getAttribute("abp-iconposition"); 28 // Force default position
29 if (usingShim)
30 toolbox.removeAttribute("abp-iconposition");
31
16 if (UI.isToolbarIconVisible(wnd)) 32 if (UI.isToolbarIconVisible(wnd))
17 UI.toggleToolbarIcon(); 33 UI.toggleToolbarIcon();
18 }, 34 },
19 teardown: function() 35 teardown: function()
20 { 36 {
21 toolbox.setAttribute("abp-iconposition", this.oldPosition);
22 toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition");
23 UI.toggleToolbarIcon(); 37 UI.toggleToolbarIcon();
24 UI.toggleToolbarIcon(); 38 UI.toggleToolbarIcon();
25 } 39 }
26 }); 40 });
27 41
28 test("Put icon before add-on bar close button", function() 42 test("Put icon at default position", function()
29 { 43 {
30 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,addonbar-closebut ton"); 44 const DEFUALT = require("appSupport").defaultToolbarPosition.parent;
Wladimir Palant 2014/07/31 11:36:15 This is misspelled. Still, I would prefer a proper
31 45
32 UI.toggleToolbarIcon(); 46 UI.toggleToolbarIcon();
33 let button = wnd.document.getElementById("abp-toolbarbutton"); 47 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
34 ok(button, "Button added"); 48 ok(placement, "Button is visible");
35 if (button) 49 if (placement)
36 { 50 equal(placement.area, DEFUALT, "Button is at the right position");
37 ok(button.nextSibling, "Has next sibling"); 51
38 if (button.nextSibling) 52 UI.toggleToolbarIcon();
39 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); 53 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
40 equal(button.parentNode.id, "addon-bar", "Parent ID"); 54 ok(!placement, "Button is invisible");
55
56 UI.toggleToolbarIcon();
57 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
58 ok(placement, "Button is visible");
59 if (placement)
60 equal(placement.area, DEFUALT, "Button is at the right position again");
61 });
62
63 test("Move icon into tabs bar and restore", function()
64 {
65 // The shim doesn't have proper support for addToWidgetArea
66 if (usingShim) {
67 ok(true, "Can't test");
68 return;
41 } 69 }
42 70
43 UI.toggleToolbarIcon(); 71 UI.toggleToolbarIcon();
44 let button = wnd.document.getElementById("abp-toolbarbutton"); 72
45 ok(!button, "Button removed"); 73 CustomizableUI.addWidgetToArea("abp-toolbarbutton", CustomizableUI.AREA_TABS TRIP);
74 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
75 ok(placement, "Button is visible");
76 if (placement)
77 equal(placement.area, CustomizableUI.AREA_TABSTRIP, "Button is in tabstrip ");
46 78
47 UI.toggleToolbarIcon(); 79 UI.toggleToolbarIcon();
48 let button = wnd.document.getElementById("abp-toolbarbutton"); 80 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
49 ok(button, "Button added"); 81 ok(!placement, "Button is invisible");
50 if (button) 82
51 { 83 UI.toggleToolbarIcon();
52 ok(button.nextSibling, "Has next sibling"); 84 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
53 if (button.nextSibling) 85 ok(placement, "Button is visible");
54 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); 86 if (placement)
55 equal(button.parentNode.id, "addon-bar", "Parent ID"); 87 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at default po sition");
56 }
57 }); 88 });
58 89
59 test("Put icon at the end of the add-on bar", function()
60 {
61 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,");
62
63 UI.toggleToolbarIcon();
64 let button = wnd.document.getElementById("abp-toolbarbutton");
65 ok(button, "Button added");
66 if (button)
67 {
68 ok(!button.nextSibling, "No next sibling");
69 equal(button.parentNode.id, "addon-bar", "Parent ID");
70 }
71
72 UI.toggleToolbarIcon();
73 let button = wnd.document.getElementById("abp-toolbarbutton");
74 ok(!button, "Button removed");
75
76 UI.toggleToolbarIcon();
77 let button = wnd.document.getElementById("abp-toolbarbutton");
78 ok(button, "Button added");
79 if (button)
80 {
81 ok(!button.nextSibling, "No next sibling");
82 equal(button.parentNode.id, "addon-bar", "Parent ID");
83 }
84 });
85
86 test("Put icon into navigation toolbar", function()
87 {
88 toolbox.setAttribute("abp-iconposition", "hidden,nav-bar,home-button");
89
90 UI.toggleToolbarIcon();
91 let button = wnd.document.getElementById("abp-toolbarbutton");
92 ok(button, "Button added");
93 if (button)
94 {
95 ok(button.nextSibling, "Has next sibling");
96 if (button.nextSibling)
97 equal(button.nextSibling.id, "home-button", "Next sibling ID");
98 equal(button.parentNode.id, "nav-bar", "Parent ID");
99 }
100
101 UI.toggleToolbarIcon();
102 let button = wnd.document.getElementById("abp-toolbarbutton");
103 ok(!button, "Button removed");
104
105 UI.toggleToolbarIcon();
106 let button = wnd.document.getElementById("abp-toolbarbutton");
107 ok(button, "Button added");
108 if (button)
109 {
110 ok(button.nextSibling, "Has next sibling");
111 if (button.nextSibling)
112 equal(button.nextSibling.id, "home-button", "Next sibling ID");
113 equal(button.parentNode.id, "nav-bar", "Parent ID");
114 }
115 });
116
117 test("Put icon before an invalid element", function()
118 {
119 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,navigator-toolbox ");
120
121 UI.toggleToolbarIcon();
122 let button = wnd.document.getElementById("abp-toolbarbutton");
123 ok(button, "Button added");
124 if (button)
125 {
126 ok(!button.nextSibling, "No next sibling");
127 equal(button.parentNode.id, "addon-bar", "Parent ID");
128 }
129 equal(toolbox.getAttribute("abp-iconposition"), "visible,addon-bar,", "New s aved position");
130 });
131
132 test("Put icon before an unknown element", function()
133 {
134 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,foobarelement");
135
136 UI.toggleToolbarIcon();
137 let button = wnd.document.getElementById("abp-toolbarbutton");
138 ok(button, "Button added");
139 if (button)
140 {
141 ok(!button.nextSibling, "No next sibling");
142 equal(button.parentNode.id, "addon-bar", "Parent ID");
143 }
144 equal(toolbox.getAttribute("abp-iconposition"), "visible,addon-bar,", "New s aved position");
145 });
146
147 test("Default icon position", function()
148 {
149 toolbox.removeAttribute("abp-iconposition");
150
151 UI.toggleToolbarIcon();
152 let button = wnd.document.getElementById("abp-toolbarbutton");
153 ok(button, "Button added");
154 if (button)
155 {
156 ok(button.nextSibling, "Has next sibling");
157 if (button.nextSibling)
158 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID");
159 equal(button.parentNode.id, "addon-bar", "Parent ID");
160 }
161 });
162
163 test("Recover legacy position", function()
164 {
165 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,");
166 UI.toggleToolbarIcon();
167 let icon = wnd.document.getElementById("abp-toolbarbutton");
168 UI.toggleToolbarIcon();
169
170 toolbox.removeAttribute("abp-iconposition");
171 let addonBar = wnd.document.getElementById("addon-bar");
172 let currentset = addonBar.getAttribute("currentset");
173 currentset = currentset.replace(/,abp-toolbarbutton/g, "");
174 currentset = currentset.replace(/abp-toolbarbutton,/g, "");
175 addonBar.setAttribute("currentset", currentset);
176
177 let navBar = wnd.document.getElementById("nav-bar");
178 currentset = navBar.getAttribute("currentset");
179 currentset = currentset.replace(/,abp-toolbarbutton/g, "");
180 currentset = currentset.replace(/abp-toolbarbutton,/g, "");
181 currentset = currentset.replace(/,home-button/, ",abp-toolbarbutton,home-but ton");
182 navBar.setAttribute("currentset", currentset);
183
184 UI.restoreToolbarIcon(toolbox, icon);
185
186 let button = wnd.document.getElementById("abp-toolbarbutton");
187 ok(button, "Button added");
188 if (button)
189 {
190 ok(button.nextSibling, "Has next sibling");
191 if (button.nextSibling)
192 equal(button.nextSibling.id, "home-button", "Next sibling ID");
193 equal(button.parentNode.id, "nav-bar", "Parent ID");
194 }
195 });
196 })(); 90 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld