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: function test() { michael@0: runTests(); michael@0: } michael@0: michael@0: function cleanup() { michael@0: let notificationBox = Browser.getNotificationBox(); michael@0: notificationBox && notificationBox.removeAllNotifications(true); michael@0: } michael@0: michael@0: const XHTML_NS = "http://www.w3.org/1999/xhtml"; michael@0: michael@0: function createTestNotification(aLabel, aID) { michael@0: let notificationBox = Browser.getNotificationBox(); michael@0: let notn = notificationBox.appendNotification(aLabel || "some label", aID || "test-notification", michael@0: "", notificationBox.PRIORITY_INFO_LOW, []); michael@0: return notn; michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "Verify notification bindings are correct", michael@0: run: function () { michael@0: let notificationBox = Browser.getNotificationBox(); michael@0: let notn = createTestNotification(); michael@0: michael@0: let binding = notn && getComputedStyle(notn).MozBinding; michael@0: is(binding, michael@0: "url(\"chrome://browser/content/bindings/notification.xml#notification\")", michael@0: "notification has expected binding"); michael@0: michael@0: is(getComputedStyle(notificationBox).MozBinding, michael@0: "url(\"chrome://browser/content/bindings/notification.xml#notificationbox\")", michael@0: "notificationbox has expected binding"); michael@0: }, michael@0: tearDown: cleanup michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Check label property handling", michael@0: run: function () { michael@0: let notn = createTestNotification("the label"); michael@0: is(notn.label, "the label"); michael@0: michael@0: let doc = notn.ownerDocument; michael@0: let fragment = doc.createDocumentFragment(); michael@0: try { michael@0: let boldLabel = doc.createElementNS(XHTML_NS, "b"); michael@0: boldLabel.innerHTML = 'The label'; michael@0: fragment.appendChild(boldLabel); michael@0: notn.label = fragment; michael@0: } catch (ex) { michael@0: ok(!ex, "Exception creating notification label with markup: "+ex.message); michael@0: } michael@0: michael@0: // expect to get a documentFragment back when the label has markup michael@0: let labelNode = notn.label; michael@0: is(labelNode.nodeType, michael@0: Components.interfaces.nsIDOMNode.DOCUMENT_FRAGMENT_NODE, michael@0: "notification label getter returns documentFragment nodeType "+Components.interfaces.nsIDOMNode.DOCUMENT_FRAGMENT_NODE+", when value contains markup"); michael@0: ok(labelNode !== fragment, michael@0: "label fragment is a newly created fragment, not the one we assigned in the setter"); michael@0: ok(labelNode.querySelector("b > .foo"), michael@0: "label fragment has the expected elements in it"); michael@0: }, michael@0: tearDown: cleanup michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Check adoptNotification does what we expect", michael@0: setUp: function() { michael@0: yield addTab("about:start"); michael@0: yield addTab("about:mozilla"); michael@0: }, michael@0: run: function () { michael@0: let browser = getBrowser(); michael@0: let notn = createTestNotification("label", "adopt-notification"); michael@0: let firstBox = Browser.getNotificationBox(); michael@0: let nextTab = Browser.getNextTab(Browser.getTabForBrowser(browser)); michael@0: let nextBox = Browser.getNotificationBox(nextTab.browser); michael@0: michael@0: ok(firstBox.getNotificationWithValue("adopt-notification"), "notificationbox has our notification intially"); michael@0: nextBox.adoptNotification(notn); michael@0: michael@0: ok(!firstBox.getNotificationWithValue("adopt-notification"), "after adoptNotification, original notificationbox no longer has our notification"); michael@0: ok(nextBox.getNotificationWithValue("adopt-notification"), "next notificationbox has our notification"); michael@0: }, michael@0: // leave browser in clean state for next tests michael@0: tearDown: cleanUpOpenedTabs michael@0: }); michael@0: