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: I tested this with Firefox 24. I think Seamonkey should behave the same. Created July 31, 2014, 10:29 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");
9 if (!toolbox)
10 return;
11 21
12 module("Icon position", { 22 module("Icon position", {
13 setup: function() 23 setup: function()
14 { 24 {
15 this.oldPosition = toolbox.getAttribute("abp-iconposition");
16 if (UI.isToolbarIconVisible(wnd)) 25 if (UI.isToolbarIconVisible(wnd))
17 UI.toggleToolbarIcon(); 26 UI.toggleToolbarIcon();
18 }, 27 },
19 teardown: function() 28 teardown: function()
20 { 29 {
21 toolbox.setAttribute("abp-iconposition", this.oldPosition);
22 toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition");
23 UI.toggleToolbarIcon(); 30 UI.toggleToolbarIcon();
24 UI.toggleToolbarIcon(); 31 UI.toggleToolbarIcon();
25 } 32 }
26 }); 33 });
27 34
28 test("Put icon before add-on bar close button", function() 35 test("Put icon at default position", function()
29 { 36 {
30 toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,addonbar-closebut ton"); 37 const AREA_NAVBAR = usingShim ? "PersonalToolbar" : CustomizableUI.AREA_NAVB AR;
Wladimir Palant 2014/07/31 10:40:36 Personal toolbar, seriously? I think this should b
31 38
32 UI.toggleToolbarIcon(); 39 UI.toggleToolbarIcon();
33 let button = wnd.document.getElementById("abp-toolbarbutton"); 40 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
34 ok(button, "Button added"); 41 ok(placement, "Button is visible");
35 if (button) 42 if (placement)
36 { 43 equal(placement.area, AREA_NAVBAR, "Button is at the right position");
37 ok(button.nextSibling, "Has next sibling"); 44
38 if (button.nextSibling) 45 UI.toggleToolbarIcon();
39 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); 46 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
40 equal(button.parentNode.id, "addon-bar", "Parent ID"); 47 ok(!placement, "Button is invisible");
48
49 UI.toggleToolbarIcon();
50 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
51 ok(placement, "Button is visible");
52 if (placement)
53 equal(placement.area, AREA_NAVBAR, "Button is at the right position again" );
54 });
55
56 test("Move icon into tabs bar and restore", function()
57 {
58 // The shim doesn't have proper support for addToWidgetArea
59 if (usingShim) {
60 ok(true, "Can not test");
Wladimir Palant 2014/07/31 10:40:36 Nit: this should be "Cannot"
61 return;
41 } 62 }
42 63
43 UI.toggleToolbarIcon(); 64 UI.toggleToolbarIcon();
44 let button = wnd.document.getElementById("abp-toolbarbutton"); 65
45 ok(!button, "Button removed"); 66 CustomizableUI.addWidgetToArea("abp-toolbarbutton", CustomizableUI.AREA_TABS TRIP);
67 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
68 ok(placement, "Button is visible");
69 if (placement)
70 equal(placement.area, CustomizableUI.AREA_TABSTRIP, "Button is in tabstrip ");
46 71
47 UI.toggleToolbarIcon(); 72 UI.toggleToolbarIcon();
48 let button = wnd.document.getElementById("abp-toolbarbutton"); 73 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
49 ok(button, "Button added"); 74 ok(!placement, "Button is invisible");
50 if (button) 75
51 { 76 UI.toggleToolbarIcon();
52 ok(button.nextSibling, "Has next sibling"); 77 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
53 if (button.nextSibling) 78 ok(placement, "Button is visible");
54 equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID"); 79 if (placement)
55 equal(button.parentNode.id, "addon-bar", "Parent ID"); 80 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at default po sition");
56 }
57 }); 81 });
58 82
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 })(); 83 })();
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