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