browser/components/customizableui/test/browser_981418-widget-onbeforecreated-handler.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6 const kWidgetId = 'test-981418-widget-onbeforecreated';
michael@0 7
michael@0 8 // Should be able to add broken view widget
michael@0 9 add_task(function testAddOnBeforeCreatedWidget() {
michael@0 10 let viewShownDeferred = Promise.defer();
michael@0 11 let onBeforeCreatedCalled = false;
michael@0 12 let widgetSpec = {
michael@0 13 id: kWidgetId,
michael@0 14 type: 'view',
michael@0 15 viewId: kWidgetId + 'idontexistyet',
michael@0 16 onBeforeCreated: function(doc) {
michael@0 17 let view = doc.createElement("panelview");
michael@0 18 view.id = kWidgetId + 'idontexistyet';
michael@0 19 let label = doc.createElement("label");
michael@0 20 label.setAttribute("value", "Hello world");
michael@0 21 label.className = 'panel-subview-header';
michael@0 22 view.appendChild(label);
michael@0 23 document.getElementById("PanelUI-multiView").appendChild(view);
michael@0 24 onBeforeCreatedCalled = true;
michael@0 25 },
michael@0 26 onViewShowing: function() {
michael@0 27 viewShownDeferred.resolve();
michael@0 28 }
michael@0 29 };
michael@0 30
michael@0 31 let noError = true;
michael@0 32 try {
michael@0 33 CustomizableUI.createWidget(widgetSpec);
michael@0 34 CustomizableUI.addWidgetToArea(kWidgetId, CustomizableUI.AREA_NAVBAR);
michael@0 35 } catch (ex) {
michael@0 36 Cu.reportError(ex);
michael@0 37 noError = false;
michael@0 38 }
michael@0 39 ok(noError, "Should not throw an exception trying to add the widget.");
michael@0 40 ok(onBeforeCreatedCalled, "onBeforeCreated should have been called");
michael@0 41
michael@0 42 let widgetNode = document.getElementById(kWidgetId);
michael@0 43 ok(widgetNode, "Widget should exist");
michael@0 44 if (widgetNode) {
michael@0 45 try {
michael@0 46 widgetNode.click();
michael@0 47
michael@0 48 let shownTimeout = setTimeout(() => viewShownDeferred.reject("Panel not shown within 20s"), 20000);
michael@0 49 yield viewShownDeferred.promise;
michael@0 50 clearTimeout(shownTimeout);
michael@0 51 ok(true, "Found view shown");
michael@0 52
michael@0 53 let tempPanel = document.getElementById("customizationui-widget-panel");
michael@0 54 let panelHiddenPromise = promisePanelElementHidden(window, tempPanel);
michael@0 55 tempPanel.hidePopup();
michael@0 56 yield panelHiddenPromise;
michael@0 57
michael@0 58 CustomizableUI.addWidgetToArea(kWidgetId, CustomizableUI.AREA_PANEL);
michael@0 59 yield PanelUI.show();
michael@0 60
michael@0 61 viewShownDeferred = Promise.defer();
michael@0 62 widgetNode.click();
michael@0 63
michael@0 64 shownTimeout = setTimeout(() => viewShownDeferred.reject("Panel not shown within 20s"), 20000);
michael@0 65 yield viewShownDeferred.promise;
michael@0 66 clearTimeout(shownTimeout);
michael@0 67 ok(true, "Found view shown");
michael@0 68
michael@0 69 let panelHidden = promisePanelHidden(window);
michael@0 70 PanelUI.hide();
michael@0 71 yield panelHidden;
michael@0 72 } catch (ex) {
michael@0 73 ok(false, "Unexpected exception (like a timeout for one of the yields) " +
michael@0 74 "when testing view widget.");
michael@0 75 }
michael@0 76 }
michael@0 77
michael@0 78 noError = true;
michael@0 79 try {
michael@0 80 CustomizableUI.destroyWidget(kWidgetId);
michael@0 81 } catch (ex) {
michael@0 82 Cu.reportError(ex);
michael@0 83 noError = false;
michael@0 84 }
michael@0 85 ok(noError, "Should not throw an exception trying to remove the broken view widget.");
michael@0 86 });
michael@0 87
michael@0 88 add_task(function asyncCleanup() {
michael@0 89 yield resetCustomization();
michael@0 90 });

mercurial