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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/tests/ui/icon_position.js
===================================================================
--- a/chrome/content/tests/ui/icon_position.js
+++ b/chrome/content/tests/ui/icon_position.js
@@ -1,196 +1,83 @@
(function()
{
let {application} = require("info");
if (application != "firefox")
return;
+ let CustomizableUI = null;
+ let usingShim = false;
+ try
+ {
+ ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null);
+ }
+ catch (e)
+ {
+ usingShim = true;
+ // No built-in CustomizableUI API, use our own implementation.
+ ({CustomizableUI}) = require("customizableUI");
+ }
+
let wnd = Utils.getChromeWindow(window);
- let toolbox = wnd.document.getElementById("navigator-toolbox");
- if (!toolbox)
- return;
module("Icon position", {
setup: function()
{
- this.oldPosition = toolbox.getAttribute("abp-iconposition");
if (UI.isToolbarIconVisible(wnd))
UI.toggleToolbarIcon();
},
teardown: function()
{
- toolbox.setAttribute("abp-iconposition", this.oldPosition);
- toolbox.ownerDocument.persist(toolbox.id, "abp-iconposition");
UI.toggleToolbarIcon();
UI.toggleToolbarIcon();
}
});
- test("Put icon before add-on bar close button", function()
+ test("Put icon at default position", function()
{
- toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,addonbar-closebutton");
+ const AREA_NAVBAR = usingShim ? "PersonalToolbar" : CustomizableUI.AREA_NAVBAR;
Wladimir Palant 2014/07/31 10:40:36 Personal toolbar, seriously? I think this should b
UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(button.nextSibling, "Has next sibling");
- if (button.nextSibling)
- equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID");
- equal(button.parentNode.id, "addon-bar", "Parent ID");
+ let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
+ ok(placement, "Button is visible");
+ if (placement)
+ equal(placement.area, AREA_NAVBAR, "Button is at the right position");
+
+ UI.toggleToolbarIcon();
+ placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
+ ok(!placement, "Button is invisible");
+
+ UI.toggleToolbarIcon();
+ placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
+ ok(placement, "Button is visible");
+ if (placement)
+ equal(placement.area, AREA_NAVBAR, "Button is at the right position again");
+ });
+
+ test("Move icon into tabs bar and restore", function()
+ {
+ // The shim doesn't have proper support for addToWidgetArea
+ if (usingShim) {
+ ok(true, "Can not test");
Wladimir Palant 2014/07/31 10:40:36 Nit: this should be "Cannot"
+ return;
}
UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(!button, "Button removed");
+
+ CustomizableUI.addWidgetToArea("abp-toolbarbutton", CustomizableUI.AREA_TABSTRIP);
+ let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
+ ok(placement, "Button is visible");
+ if (placement)
+ equal(placement.area, CustomizableUI.AREA_TABSTRIP, "Button is in tabstrip");
UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(button.nextSibling, "Has next sibling");
- if (button.nextSibling)
- equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID");
- equal(button.parentNode.id, "addon-bar", "Parent ID");
- }
+ placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
+ ok(!placement, "Button is invisible");
+
+ UI.toggleToolbarIcon();
+ placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
+ ok(placement, "Button is visible");
+ if (placement)
+ equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at default position");
});
- test("Put icon at the end of the add-on bar", function()
- {
- toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,");
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(!button.nextSibling, "No next sibling");
- equal(button.parentNode.id, "addon-bar", "Parent ID");
- }
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(!button, "Button removed");
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(!button.nextSibling, "No next sibling");
- equal(button.parentNode.id, "addon-bar", "Parent ID");
- }
- });
-
- test("Put icon into navigation toolbar", function()
- {
- toolbox.setAttribute("abp-iconposition", "hidden,nav-bar,home-button");
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(button.nextSibling, "Has next sibling");
- if (button.nextSibling)
- equal(button.nextSibling.id, "home-button", "Next sibling ID");
- equal(button.parentNode.id, "nav-bar", "Parent ID");
- }
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(!button, "Button removed");
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(button.nextSibling, "Has next sibling");
- if (button.nextSibling)
- equal(button.nextSibling.id, "home-button", "Next sibling ID");
- equal(button.parentNode.id, "nav-bar", "Parent ID");
- }
- });
-
- test("Put icon before an invalid element", function()
- {
- toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,navigator-toolbox");
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(!button.nextSibling, "No next sibling");
- equal(button.parentNode.id, "addon-bar", "Parent ID");
- }
- equal(toolbox.getAttribute("abp-iconposition"), "visible,addon-bar,", "New saved position");
- });
-
- test("Put icon before an unknown element", function()
- {
- toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,foobarelement");
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(!button.nextSibling, "No next sibling");
- equal(button.parentNode.id, "addon-bar", "Parent ID");
- }
- equal(toolbox.getAttribute("abp-iconposition"), "visible,addon-bar,", "New saved position");
- });
-
- test("Default icon position", function()
- {
- toolbox.removeAttribute("abp-iconposition");
-
- UI.toggleToolbarIcon();
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(button.nextSibling, "Has next sibling");
- if (button.nextSibling)
- equal(button.nextSibling.id, "addonbar-closebutton", "Next sibling ID");
- equal(button.parentNode.id, "addon-bar", "Parent ID");
- }
- });
-
- test("Recover legacy position", function()
- {
- toolbox.setAttribute("abp-iconposition", "hidden,addon-bar,");
- UI.toggleToolbarIcon();
- let icon = wnd.document.getElementById("abp-toolbarbutton");
- UI.toggleToolbarIcon();
-
- toolbox.removeAttribute("abp-iconposition");
- let addonBar = wnd.document.getElementById("addon-bar");
- let currentset = addonBar.getAttribute("currentset");
- currentset = currentset.replace(/,abp-toolbarbutton/g, "");
- currentset = currentset.replace(/abp-toolbarbutton,/g, "");
- addonBar.setAttribute("currentset", currentset);
-
- let navBar = wnd.document.getElementById("nav-bar");
- currentset = navBar.getAttribute("currentset");
- currentset = currentset.replace(/,abp-toolbarbutton/g, "");
- currentset = currentset.replace(/abp-toolbarbutton,/g, "");
- currentset = currentset.replace(/,home-button/, ",abp-toolbarbutton,home-button");
- navBar.setAttribute("currentset", currentset);
-
- UI.restoreToolbarIcon(toolbox, icon);
-
- let button = wnd.document.getElementById("abp-toolbarbutton");
- ok(button, "Button added");
- if (button)
- {
- ok(button.nextSibling, "Has next sibling");
- if (button.nextSibling)
- equal(button.nextSibling.id, "home-button", "Next sibling ID");
- equal(button.parentNode.id, "nav-bar", "Parent ID");
- }
- });
})();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld