Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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 | |
michael@0 | 7 | function test() { |
michael@0 | 8 | runTests(); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | function cleanup() { |
michael@0 | 12 | let notificationBox = Browser.getNotificationBox(); |
michael@0 | 13 | notificationBox && notificationBox.removeAllNotifications(true); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | const XHTML_NS = "http://www.w3.org/1999/xhtml"; |
michael@0 | 17 | |
michael@0 | 18 | function createTestNotification(aLabel, aID) { |
michael@0 | 19 | let notificationBox = Browser.getNotificationBox(); |
michael@0 | 20 | let notn = notificationBox.appendNotification(aLabel || "some label", aID || "test-notification", |
michael@0 | 21 | "", notificationBox.PRIORITY_INFO_LOW, []); |
michael@0 | 22 | return notn; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | gTests.push({ |
michael@0 | 26 | desc: "Verify notification bindings are correct", |
michael@0 | 27 | run: function () { |
michael@0 | 28 | let notificationBox = Browser.getNotificationBox(); |
michael@0 | 29 | let notn = createTestNotification(); |
michael@0 | 30 | |
michael@0 | 31 | let binding = notn && getComputedStyle(notn).MozBinding; |
michael@0 | 32 | is(binding, |
michael@0 | 33 | "url(\"chrome://browser/content/bindings/notification.xml#notification\")", |
michael@0 | 34 | "notification has expected binding"); |
michael@0 | 35 | |
michael@0 | 36 | is(getComputedStyle(notificationBox).MozBinding, |
michael@0 | 37 | "url(\"chrome://browser/content/bindings/notification.xml#notificationbox\")", |
michael@0 | 38 | "notificationbox has expected binding"); |
michael@0 | 39 | }, |
michael@0 | 40 | tearDown: cleanup |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | gTests.push({ |
michael@0 | 44 | desc: "Check label property handling", |
michael@0 | 45 | run: function () { |
michael@0 | 46 | let notn = createTestNotification("the label"); |
michael@0 | 47 | is(notn.label, "the label"); |
michael@0 | 48 | |
michael@0 | 49 | let doc = notn.ownerDocument; |
michael@0 | 50 | let fragment = doc.createDocumentFragment(); |
michael@0 | 51 | try { |
michael@0 | 52 | let boldLabel = doc.createElementNS(XHTML_NS, "b"); |
michael@0 | 53 | boldLabel.innerHTML = 'The <span class="foo">label</span>'; |
michael@0 | 54 | fragment.appendChild(boldLabel); |
michael@0 | 55 | notn.label = fragment; |
michael@0 | 56 | } catch (ex) { |
michael@0 | 57 | ok(!ex, "Exception creating notification label with markup: "+ex.message); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | // expect to get a documentFragment back when the label has markup |
michael@0 | 61 | let labelNode = notn.label; |
michael@0 | 62 | is(labelNode.nodeType, |
michael@0 | 63 | Components.interfaces.nsIDOMNode.DOCUMENT_FRAGMENT_NODE, |
michael@0 | 64 | "notification label getter returns documentFragment nodeType "+Components.interfaces.nsIDOMNode.DOCUMENT_FRAGMENT_NODE+", when value contains markup"); |
michael@0 | 65 | ok(labelNode !== fragment, |
michael@0 | 66 | "label fragment is a newly created fragment, not the one we assigned in the setter"); |
michael@0 | 67 | ok(labelNode.querySelector("b > .foo"), |
michael@0 | 68 | "label fragment has the expected elements in it"); |
michael@0 | 69 | }, |
michael@0 | 70 | tearDown: cleanup |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | gTests.push({ |
michael@0 | 74 | desc: "Check adoptNotification does what we expect", |
michael@0 | 75 | setUp: function() { |
michael@0 | 76 | yield addTab("about:start"); |
michael@0 | 77 | yield addTab("about:mozilla"); |
michael@0 | 78 | }, |
michael@0 | 79 | run: function () { |
michael@0 | 80 | let browser = getBrowser(); |
michael@0 | 81 | let notn = createTestNotification("label", "adopt-notification"); |
michael@0 | 82 | let firstBox = Browser.getNotificationBox(); |
michael@0 | 83 | let nextTab = Browser.getNextTab(Browser.getTabForBrowser(browser)); |
michael@0 | 84 | let nextBox = Browser.getNotificationBox(nextTab.browser); |
michael@0 | 85 | |
michael@0 | 86 | ok(firstBox.getNotificationWithValue("adopt-notification"), "notificationbox has our notification intially"); |
michael@0 | 87 | nextBox.adoptNotification(notn); |
michael@0 | 88 | |
michael@0 | 89 | ok(!firstBox.getNotificationWithValue("adopt-notification"), "after adoptNotification, original notificationbox no longer has our notification"); |
michael@0 | 90 | ok(nextBox.getNotificationWithValue("adopt-notification"), "next notificationbox has our notification"); |
michael@0 | 91 | }, |
michael@0 | 92 | // leave browser in clean state for next tests |
michael@0 | 93 | tearDown: cleanUpOpenedTabs |
michael@0 | 94 | }); |
michael@0 | 95 |