diff --git a/browser/components/customizableui/test/browser.ini b/browser/components/customizableui/test/browser.ini index c049ba87afd..7026b861f4d 100644 --- a/browser/components/customizableui/test/browser.ini +++ b/browser/components/customizableui/test/browser.ini @@ -65,6 +65,19 @@ skip-if = e10s # Bug ?????? - test uses promiseTabLoadEvent() which isn't e10s f [browser_943683_migration_test.js] [browser_944887_destroyWidget_should_destroy_in_palette.js] [browser_945739_showInPrivateBrowsing_customize_mode.js] +[browser_947914_button_addons.js] +[browser_947914_button_copy.js] +[browser_947914_button_cut.js] +[browser_947914_button_find.js] +[browser_947914_button_history.js] +[browser_947914_button_newPrivateWindow.js] +[browser_947914_button_newWindow.js] +[browser_947914_button_paste.js] +[browser_947914_button_print.js] +[browser_947914_button_savePage.js] +[browser_947914_button_zoomIn.js] +[browser_947914_button_zoomOut.js] +[browser_947914_button_zoomReset.js] [browser_947987_removable_default.js] [browser_948985_non_removable_defaultArea.js] [browser_952963_areaType_getter_no_area.js] diff --git a/browser/components/customizableui/test/browser_947914_button_addons.js b/browser/components/customizableui/test/browser_947914_button_addons.js new file mode 100644 index 00000000000..9ee8d27a6a2 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_addons.js @@ -0,0 +1,34 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check addons button existence and functionality"); + + let initialLocation = gBrowser.currentURI.spec; + + yield PanelUI.show(); + + let addonsButton = document.getElementById("add-ons-button"); + ok(addonsButton, "Add-ons button exists in Panel Menu"); + addonsButton.click(); + + yield waitForCondition(function() gBrowser.currentURI && + gBrowser.currentURI.spec == "about:addons"); + + let addonsPage = gBrowser.selectedBrowser.contentWindow.document. + getElementById("addons-page"); + ok(addonsPage, "Add-ons page was opened"); + + // close the add-ons tab + if(gBrowser.tabs.length > 1) { + gBrowser.removeTab(gBrowser.selectedTab); + } + else { + var tabToRemove = gBrowser.selectedTab; + gBrowser.addTab(initialLocation); + gBrowser.removeTab(tabToRemove); + } +}); diff --git a/browser/components/customizableui/test/browser_947914_button_copy.js b/browser/components/customizableui/test/browser_947914_button_copy.js new file mode 100644 index 00000000000..dde2391ebb8 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_copy.js @@ -0,0 +1,51 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check copy button existence and functionality"); + + var testText = "copy text test"; + let initialLocation = gBrowser.currentURI.spec; + + yield PanelUI.show(); + + let copyButton = document.getElementById("copy-button"); + ok(copyButton, "Copy button exists in Panel Menu"); + is(copyButton.getAttribute("disabled"), "true", "Copy button is initially disabled"); + + // copy text from URL bar + gURLBar.value = testText; + gURLBar.focus(); + gURLBar.select(); + yield PanelUI.show(); + + ok(!copyButton.hasAttribute("disabled"), "Copy button gets enabled"); + + copyButton.click(); + is(gURLBar.value, testText, "Selected text is unaltered when clicking copy"); + + // check that the text was added to the clipboard + let clipboard = Services.clipboard; + let transferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable); + const globalClipboard = clipboard.kGlobalClipboard; + + transferable.init(null); + transferable.addDataFlavor("text/unicode"); + clipboard.getData(transferable, globalClipboard); + let str = {}, strLength = {}; + transferable.getTransferData("text/unicode", str, strLength); + let clipboardValue = ""; + + if (str.value) { + str.value.QueryInterface(Ci.nsISupportsString); + clipboardValue = str.value.data; + } + is(clipboardValue, testText, "Data was copied to the clipboard."); + + // restore the tab location and clear the clipboard + Services.clipboard.emptyClipboard(globalClipboard); + gURLBar.value = initialLocation; +}); diff --git a/browser/components/customizableui/test/browser_947914_button_cut.js b/browser/components/customizableui/test/browser_947914_button_cut.js new file mode 100644 index 00000000000..cc404e514a6 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_cut.js @@ -0,0 +1,50 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check cut button existence and functionality"); + + var testText = "cut text test"; + let initialLocation = gBrowser.currentURI.spec; + + yield PanelUI.show(); + + let cutButton = document.getElementById("cut-button"); + ok(cutButton, "Cut button exists in Panel Menu"); + ok(cutButton.getAttribute("disabled"), "Cut button is disabled"); + + // cut text from URL bar + gURLBar.value = testText; + gURLBar.focus(); + gURLBar.select(); + yield PanelUI.show(); + + ok(!cutButton.hasAttribute("disabled"), "Cut button gets enabled"); + cutButton.click(); + is(gURLBar.value, "", "Selected text is removed from source when clicking on cut"); + + // check that the text was added to the clipboard + let clipboard = Services.clipboard; + let transferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable); + const globalClipboard = clipboard.kGlobalClipboard; + + transferable.init(null); + transferable.addDataFlavor("text/unicode"); + clipboard.getData(transferable, globalClipboard); + let str = {}, strLength = {}; + transferable.getTransferData("text/unicode", str, strLength); + let clipboardValue = ""; + + if (str.value) { + str.value.QueryInterface(Ci.nsISupportsString); + clipboardValue = str.value.data; + } + is(clipboardValue, testText, "Data was copied to the clipboard."); + + // restore the tab location and clear the clipboard + gBrowser.value = initialLocation; + Services.clipboard.emptyClipboard(globalClipboard); +}); diff --git a/browser/components/customizableui/test/browser_947914_button_find.js b/browser/components/customizableui/test/browser_947914_button_find.js new file mode 100644 index 00000000000..8c766bb5fe8 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_find.js @@ -0,0 +1,20 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check find button existence and functionality"); + + yield PanelUI.show(); + + let findButton = document.getElementById("find-button"); + ok(findButton, "Find button exists in Panel Menu"); + + findButton.click(); + ok(!gFindBar.hasAttribute("hidden"), "Findbar opened successfully"); + + // close find bar + gFindBar.close(); +}); diff --git a/browser/components/customizableui/test/browser_947914_button_history.js b/browser/components/customizableui/test/browser_947914_button_history.js new file mode 100644 index 00000000000..e286ab4273e --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_history.js @@ -0,0 +1,22 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check history button existence and functionality"); + + yield PanelUI.show(); + + let historyButton = document.getElementById("history-panelmenu"); + ok(historyButton, "History button appears in Panel Menu"); + + historyButton.click(); + let historyPanel = document.getElementById("PanelUI-history"); + ok(historyPanel.getAttribute("current"), "History Panel is in view"); + + let panelHiddenPromise = promisePanelHidden(window); + PanelUI.hide(); + yield panelHiddenPromise +}); diff --git a/browser/components/customizableui/test/browser_947914_button_newPrivateWindow.js b/browser/components/customizableui/test/browser_947914_button_newPrivateWindow.js new file mode 100644 index 00000000000..a4e9e10e67a --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_newPrivateWindow.js @@ -0,0 +1,45 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check private browsing button existence and functionality"); + yield PanelUI.show(); + + var windowWasHandled = false; + let privateWindow = null; + + let observerWindowOpened = { + observe: function(aSubject, aTopic, aData) { + if (aTopic == "domwindowopened") { + privateWindow = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); + privateWindow.addEventListener("load", function newWindowHandler() { + privateWindow.removeEventListener("load", newWindowHandler, false); + is(privateWindow.location.href, "chrome://browser/content/browser.xul", + "A new browser window was opened"); + ok(PrivateBrowsingUtils.isWindowPrivate(privateWindow), "Window is private"); + windowWasHandled = true; + }, false); + } + } + } + + Services.ww.registerNotification(observerWindowOpened); + + let privateBrowsingButton = document.getElementById("privatebrowsing-button"); + ok(privateBrowsingButton, "Private browsing button exists in Panel Menu"); + privateBrowsingButton.click(); + + try{ + yield waitForCondition(() => windowWasHandled); + yield promiseWindowClosed(privateWindow); + } + catch(e) { + ok(false, "The new private browser window was not properly handled"); + } + finally { + Services.ww.unregisterNotification(observerWindowOpened); + } +}); diff --git a/browser/components/customizableui/test/browser_947914_button_newWindow.js b/browser/components/customizableui/test/browser_947914_button_newWindow.js new file mode 100644 index 00000000000..57c2581740c --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_newWindow.js @@ -0,0 +1,45 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check new window button existence and functionality"); + yield PanelUI.show(); + + var windowWasHandled = false; + var newWindow = null; + + let observerWindowOpened = { + observe: function(aSubject, aTopic, aData) { + if (aTopic == "domwindowopened") { + newWindow = aSubject.QueryInterface(Components.interfaces.nsIDOMWindow); + newWindow.addEventListener("load", function newWindowHandler() { + newWindow.removeEventListener("load", newWindowHandler, false); + is(newWindow.location.href, "chrome://browser/content/browser.xul", + "A new browser window was opened"); + ok(!PrivateBrowsingUtils.isWindowPrivate(newWindow), "Window is not private"); + windowWasHandled = true; + }, false); + } + } + } + + Services.ww.registerNotification(observerWindowOpened); + + let newWindowButton = document.getElementById("new-window-button"); + ok(newWindowButton, "New Window button exists in Panel Menu"); + newWindowButton.click(); + + try{ + yield waitForCondition(() => windowWasHandled); + yield promiseWindowClosed(newWindow); + } + catch(e) { + ok(false, "The new browser window was not properly handled"); + } + finally { + Services.ww.unregisterNotification(observerWindowOpened); + } +}); diff --git a/browser/components/customizableui/test/browser_947914_button_paste.js b/browser/components/customizableui/test/browser_947914_button_paste.js new file mode 100644 index 00000000000..8895c812ab5 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_paste.js @@ -0,0 +1,35 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check paste button existence and functionality"); + + let initialLocation = gBrowser.currentURI.spec; + let clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].getService(Ci.nsIClipboardHelper); + const globalClipboard = Services.clipboard.kGlobalClipboard; + + yield PanelUI.show(); + + let pasteButton = document.getElementById("paste-button"); + ok(pasteButton, "Paste button exists in Panel Menu"); + + // add text to clipboard + var text = "Sample text for testing"; + clipboard.copyString(text); + + // test paste button by pasting text to URL bar + gURLBar.focus(); + yield PanelUI.show(); + + ok(!pasteButton.hasAttribute("disabled"), "Paste button is enabled"); + pasteButton.click(); + + is(gURLBar.value, text, "Text pasted successfully"); + + // clear the clipboard and restore the tab location as it was at the begining of the test + Services.clipboard.emptyClipboard(globalClipboard); + gURLBar.value = initialLocation; +}); diff --git a/browser/components/customizableui/test/browser_947914_button_print.js b/browser/components/customizableui/test/browser_947914_button_print.js new file mode 100644 index 00000000000..e4b7e9dac33 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_print.js @@ -0,0 +1,32 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const isOSX = (Services.appinfo.OS === "Darwin"); + +add_task(function() { + info("Check print button existence and functionality"); + + yield PanelUI.show(); + + let printButton = document.getElementById("print-button"); + ok(printButton, "Print button exists in Panel Menu"); + + if(isOSX) { + let panelHiddenPromise = promisePanelHidden(window); + PanelUI.hide(); + yield panelHiddenPromise; + } + else { + printButton.click(); + yield waitForCondition(() => window.gInPrintPreviewMode); + + ok(window.gInPrintPreviewMode, "Entered print preview mode"); + + // close print preview + PrintUtils.exitPrintPreview(); + yield waitForCondition(() => !window.gInPrintPreviewMode); + } +}); diff --git a/browser/components/customizableui/test/browser_947914_button_savePage.js b/browser/components/customizableui/test/browser_947914_button_savePage.js new file mode 100644 index 00000000000..4cc7de86fc6 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_savePage.js @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check save page button existence"); + + yield PanelUI.show(); + + let savePageButton = document.getElementById("save-page-button"); + ok(savePageButton, "Save Page button exists in Panel Menu"); + + let panelHiddenPromise = promisePanelHidden(window); + PanelUI.hide(); + yield panelHiddenPromise; +}); diff --git a/browser/components/customizableui/test/browser_947914_button_zoomIn.js b/browser/components/customizableui/test/browser_947914_button_zoomIn.js new file mode 100644 index 00000000000..9ec48646ca8 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_zoomIn.js @@ -0,0 +1,31 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check zoom in button existence and functionality"); + + let initialPageZoom = ZoomManager.zoom; + is(initialPageZoom, 1, "Initial zoom factor should be 1"); + + yield PanelUI.show(); + + let zoomInButton = document.getElementById("zoom-in-button"); + ok(zoomInButton, "Zoom in button exists in Panel Menu"); + + zoomInButton.click(); + let pageZoomLevel = parseInt(ZoomManager.zoom * 100); + let zoomResetButton = document.getElementById("zoom-reset-button"); + let expectedZoomLevel = parseInt(zoomResetButton.getAttribute("label"), 10); + ok(pageZoomLevel > 100 && pageZoomLevel == expectedZoomLevel, "Page zoomed in correctly"); + + // close the Panel + let panelHiddenPromise = promisePanelHidden(window); + PanelUI.hide(); + yield panelHiddenPromise; + + // reset zoom level + ZoomManager.zoom = initialPageZoom; +}); diff --git a/browser/components/customizableui/test/browser_947914_button_zoomOut.js b/browser/components/customizableui/test/browser_947914_button_zoomOut.js new file mode 100644 index 00000000000..468874b2190 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_zoomOut.js @@ -0,0 +1,32 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check zoom out button existence and functionality"); + + let initialPageZoom = ZoomManager.zoom; + is(initialPageZoom, 1, "Initial zoom factor should be 1"); + + yield PanelUI.show(); + + let zoomOutButton = document.getElementById("zoom-out-button"); + ok(zoomOutButton, "Zoom out button exists in Panel Menu"); + + zoomOutButton.click(); + let pageZoomLevel = Math.round(ZoomManager.zoom*100); + + let zoomResetButton = document.getElementById("zoom-reset-button"); + let expectedZoomLevel = parseInt(zoomResetButton.getAttribute("label"), 10); + ok(pageZoomLevel < 100 && pageZoomLevel == expectedZoomLevel, "Page zoomed out correctly"); + + // close the panel + let panelHiddenPromise = promisePanelHidden(window); + PanelUI.hide(); + yield panelHiddenPromise; + + // reset zoom level + ZoomManager.zoom = initialPageZoom; +}); diff --git a/browser/components/customizableui/test/browser_947914_button_zoomReset.js b/browser/components/customizableui/test/browser_947914_button_zoomReset.js new file mode 100644 index 00000000000..8898f4fb990 --- /dev/null +++ b/browser/components/customizableui/test/browser_947914_button_zoomReset.js @@ -0,0 +1,30 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +add_task(function() { + info("Check zoom reset button existence and functionality"); + + let initialPageZoom = ZoomManager.zoom; + is(initialPageZoom, 1, "Initial zoom factor should be 1"); + ZoomManager.zoom = 0.5; + yield PanelUI.show(); + + let zoomResetButton = document.getElementById("zoom-reset-button"); + ok(zoomResetButton, "Zoom reset button exists in Panel Menu"); + + zoomResetButton.click(); + let pageZoomLevel = parseInt(ZoomManager.zoom * 100); + let expectedZoomLevel = parseInt(zoomResetButton.getAttribute("label"), 10); + ok(pageZoomLevel == expectedZoomLevel && pageZoomLevel == 100, "Page zoom reset correctly"); + + // close the panel + let panelHiddenPromise = promisePanelHidden(window); + PanelUI.hide(); + yield panelHiddenPromise; + + //reset the zoom level + ZoomManager.zoom = initialPageZoom; +});