michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const TEST_PAGE = "http://mochi.test:8888/browser/browser/components/customizableui/test/support/test_967000_charEncoding_page.html"; michael@0: let newTab = null; michael@0: michael@0: add_task(function() { michael@0: info("Check Character Encoding panel functionality"); michael@0: michael@0: // add the Character Encoding button to the panel michael@0: CustomizableUI.addWidgetToArea("characterencoding-button", michael@0: CustomizableUI.AREA_PANEL); michael@0: michael@0: newTab = gBrowser.addTab(TEST_PAGE); michael@0: yield promiseTabLoadEvent(gBrowser.selectedTab, TEST_PAGE); michael@0: michael@0: yield PanelUI.show(); michael@0: let charEncodingButton = document.getElementById("characterencoding-button"); michael@0: charEncodingButton.click(); michael@0: michael@0: let characterEncodingView = document.getElementById("PanelUI-characterEncodingView"); michael@0: let checkedButtons = characterEncodingView.querySelectorAll("toolbarbutton[checked='true']"); michael@0: let initialEncoding = checkedButtons[0]; michael@0: is(initialEncoding.getAttribute("label"), "Unicode", "The unicode encoding is initially selected"); michael@0: michael@0: // change the encoding michael@0: let encodings = characterEncodingView.querySelectorAll("toolbarbutton"); michael@0: let newEncoding = encodings[0].hasAttribute("checked") ? encodings[1] : encodings[0]; michael@0: let tabLoadPromise = promiseTabLoadEvent(gBrowser.selectedTab, TEST_PAGE); michael@0: newEncoding.click(); michael@0: yield tabLoadPromise; michael@0: michael@0: // check that the new encodng is applied michael@0: yield PanelUI.show(); michael@0: charEncodingButton.click(); michael@0: checkedButtons = characterEncodingView.querySelectorAll("toolbarbutton[checked='true']"); michael@0: let selectedEncodingName = checkedButtons[0].getAttribute("label"); michael@0: ok(selectedEncodingName != "Unicode", "The encoding was changed to " + selectedEncodingName); michael@0: michael@0: // reset the initial encoding michael@0: yield PanelUI.show(); michael@0: charEncodingButton.click(); michael@0: tabLoadPromise = promiseTabLoadEvent(gBrowser.selectedTab, TEST_PAGE); michael@0: initialEncoding.click(); michael@0: yield tabLoadPromise; michael@0: yield PanelUI.show(); michael@0: charEncodingButton.click(); michael@0: let checkedButtons = characterEncodingView.querySelectorAll("toolbarbutton[checked='true']"); michael@0: is(checkedButtons[0].getAttribute("label"), "Unicode", "The encoding was reset to Unicode"); michael@0: }); michael@0: michael@0: add_task(function asyncCleanup() { michael@0: // reset the panel to the default state michael@0: yield resetCustomization(); michael@0: ok(CustomizableUI.inDefaultState, "The UI is in default state again."); michael@0: michael@0: // remove the added tab michael@0: gBrowser.removeTab(newTab); michael@0: });