| LEFT | RIGHT |
| 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; | 7 let CustomizableUI = null; |
| 8 let usingShim = false; |
| 8 try | 9 try |
| 9 { | 10 { |
| 10 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", nul
l); | 11 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", nul
l); |
| 11 } | 12 } |
| 12 catch (e) | 13 catch (e) |
| 13 { | 14 { |
| 14 return; | 15 usingShim = true; |
| 16 // No built-in CustomizableUI API, use our own implementation. |
| 17 ({CustomizableUI}) = require("customizableUI"); |
| 15 } | 18 } |
| 16 | 19 |
| 17 let wnd = Utils.getChromeWindow(window); | 20 let wnd = Utils.getChromeWindow(window); |
| 21 let defaultParent = require("appSupport").defaultToolbarPosition.parent; |
| 22 |
| 23 let toolbox; |
| 24 if (usingShim) |
| 25 { |
| 26 let toolbar = wnd.document.getElementById(defaultParent); |
| 27 if (!toolbar) |
| 28 return; |
| 29 toolbox = toolbar.toolbox; |
| 30 } |
| 18 | 31 |
| 19 module("Icon position", { | 32 module("Icon position", { |
| 20 setup: function() | 33 setup: function() |
| 21 { | 34 { |
| 35 // Force default position |
| 36 if (usingShim) |
| 37 toolbox.removeAttribute("abp-iconposition"); |
| 38 |
| 22 if (UI.isToolbarIconVisible(wnd)) | 39 if (UI.isToolbarIconVisible(wnd)) |
| 23 UI.toggleToolbarIcon(); | 40 UI.toggleToolbarIcon(); |
| 24 }, | 41 }, |
| 25 teardown: function() | 42 teardown: function() |
| 26 { | 43 { |
| 27 UI.toggleToolbarIcon(); | 44 UI.toggleToolbarIcon(); |
| 28 UI.toggleToolbarIcon(); | 45 UI.toggleToolbarIcon(); |
| 29 } | 46 } |
| 30 }); | 47 }); |
| 31 | 48 |
| 32 test("Put icon at default position", function() | 49 test("Put icon at default position", function() |
| 33 { | 50 { |
| 34 UI.toggleToolbarIcon(); | 51 UI.toggleToolbarIcon(); |
| 35 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); | 52 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 36 ok(placement, "Button is visible"); | 53 ok(placement, "Button is visible"); |
| 37 if (placement) | 54 if (placement) |
| 38 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at the right
position"); | 55 equal(placement.area, defaultParent, "Button is at the right position"); |
| 39 | 56 |
| 40 UI.toggleToolbarIcon(); | 57 UI.toggleToolbarIcon(); |
| 41 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); | 58 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 42 ok(!placement, "Button is invisible"); | 59 ok(!placement, "Button is invisible"); |
| 43 | 60 |
| 44 UI.toggleToolbarIcon(); | 61 UI.toggleToolbarIcon(); |
| 45 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); | 62 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 46 ok(placement, "Button is visible"); | 63 ok(placement, "Button is visible"); |
| 47 if (placement) | 64 if (placement) |
| 48 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at the right
position again"); | 65 equal(placement.area, defaultParent, "Button is at the right position agai
n"); |
| 49 }); | 66 }); |
| 50 | 67 |
| 51 test("Move icon into tabs bar and restore", function() | 68 test("Move icon into tabs bar and restore", function() |
| 52 { | 69 { |
| 70 // The shim doesn't have proper support for addToWidgetArea |
| 71 if (usingShim) { |
| 72 ok(true, "Can't test"); |
| 73 return; |
| 74 } |
| 75 |
| 53 UI.toggleToolbarIcon(); | 76 UI.toggleToolbarIcon(); |
| 54 | 77 |
| 55 CustomizableUI.addWidgetToArea("abp-toolbarbutton", CustomizableUI.AREA_TABS
TRIP); | 78 CustomizableUI.addWidgetToArea("abp-toolbarbutton", CustomizableUI.AREA_TABS
TRIP); |
| 56 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); | 79 let placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 57 ok(placement, "Button is visible"); | 80 ok(placement, "Button is visible"); |
| 58 if (placement) | 81 if (placement) |
| 59 equal(placement.area, CustomizableUI.AREA_TABSTRIP, "Button is in tabstrip
"); | 82 equal(placement.area, CustomizableUI.AREA_TABSTRIP, "Button is in tabstrip
"); |
| 60 | 83 |
| 61 UI.toggleToolbarIcon(); | 84 UI.toggleToolbarIcon(); |
| 62 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); | 85 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 63 ok(!placement, "Button is invisible"); | 86 ok(!placement, "Button is invisible"); |
| 64 | 87 |
| 65 UI.toggleToolbarIcon(); | 88 UI.toggleToolbarIcon(); |
| 66 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); | 89 placement = CustomizableUI.getPlacementOfWidget("abp-toolbarbutton"); |
| 67 ok(placement, "Button is visible"); | 90 ok(placement, "Button is visible"); |
| 68 if (placement) | 91 if (placement) |
| 69 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at default po
sition"); | 92 equal(placement.area, CustomizableUI.AREA_NAVBAR, "Button is at default po
sition"); |
| 70 }); | 93 }); |
| 71 | 94 |
| 72 })(); | 95 })(); |
| LEFT | RIGHT |