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: fixed comments Created July 31, 2014, 12:13 p.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,95 @@
(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;
+ let defaultParent = require("appSupport").defaultToolbarPosition.parent;
+
+ let toolbox;
+ if (usingShim)
+ {
+ let toolbar = wnd.document.getElementById(defaultParent);
+ if (!toolbar)
+ return;
+ toolbox = toolbar.toolbox;
+ }
module("Icon position", {
setup: function()
{
- this.oldPosition = toolbox.getAttribute("abp-iconposition");
+ // Force default position
+ if (usingShim)
+ toolbox.removeAttribute("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");
+ UI.toggleToolbarIcon();
+ let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton");
+ ok(placement, "Button is visible");
+ if (placement)
+ equal(placement.area, defaultParent, "Button is at the right position");
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, defaultParent, "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't test");
+ 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