browser/metro/base/tests/mochitest/browser_notifications.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/tests/mochitest/browser_notifications.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +function test() {
    1.11 +  runTests();
    1.12 +}
    1.13 +
    1.14 +function cleanup() {
    1.15 +  let notificationBox = Browser.getNotificationBox();
    1.16 +  notificationBox && notificationBox.removeAllNotifications(true);
    1.17 +}
    1.18 +
    1.19 +const XHTML_NS = "http://www.w3.org/1999/xhtml";
    1.20 +
    1.21 +function createTestNotification(aLabel, aID) {
    1.22 +    let notificationBox = Browser.getNotificationBox();
    1.23 +    let notn = notificationBox.appendNotification(aLabel || "some label", aID || "test-notification",
    1.24 +                                                  "", notificationBox.PRIORITY_INFO_LOW, []);
    1.25 +    return notn;
    1.26 +}
    1.27 +
    1.28 +gTests.push({
    1.29 +  desc: "Verify notification bindings are correct",
    1.30 +  run: function () {
    1.31 +    let notificationBox = Browser.getNotificationBox();
    1.32 +    let notn = createTestNotification();
    1.33 +
    1.34 +    let binding = notn && getComputedStyle(notn).MozBinding;
    1.35 +    is(binding,
    1.36 +       "url(\"chrome://browser/content/bindings/notification.xml#notification\")",
    1.37 +       "notification has expected binding");
    1.38 +
    1.39 +    is(getComputedStyle(notificationBox).MozBinding,
    1.40 +       "url(\"chrome://browser/content/bindings/notification.xml#notificationbox\")",
    1.41 +       "notificationbox has expected binding");
    1.42 +  },
    1.43 +  tearDown: cleanup
    1.44 +});
    1.45 +
    1.46 +gTests.push({
    1.47 +  desc: "Check label property handling",
    1.48 +  run: function () {
    1.49 +    let notn = createTestNotification("the label");
    1.50 +    is(notn.label, "the label");
    1.51 +
    1.52 +    let doc = notn.ownerDocument;
    1.53 +    let fragment = doc.createDocumentFragment();
    1.54 +    try {
    1.55 +      let boldLabel = doc.createElementNS(XHTML_NS, "b");
    1.56 +      boldLabel.innerHTML = 'The <span class="foo">label</span>';
    1.57 +      fragment.appendChild(boldLabel);
    1.58 +      notn.label = fragment;
    1.59 +    } catch (ex) {
    1.60 +      ok(!ex, "Exception creating notification label with markup: "+ex.message);
    1.61 +    }
    1.62 +
    1.63 +    // expect to get a documentFragment back when the label has markup
    1.64 +    let labelNode = notn.label;
    1.65 +    is(labelNode.nodeType,
    1.66 +       Components.interfaces.nsIDOMNode.DOCUMENT_FRAGMENT_NODE,
    1.67 +       "notification label getter returns documentFragment nodeType "+Components.interfaces.nsIDOMNode.DOCUMENT_FRAGMENT_NODE+", when value contains markup");
    1.68 +    ok(labelNode !== fragment,
    1.69 +       "label fragment is a newly created fragment, not the one we assigned in the setter");
    1.70 +    ok(labelNode.querySelector("b > .foo"),
    1.71 +       "label fragment has the expected elements in it");
    1.72 +  },
    1.73 +  tearDown: cleanup
    1.74 +});
    1.75 +
    1.76 +gTests.push({
    1.77 +  desc: "Check adoptNotification does what we expect",
    1.78 +  setUp: function() {
    1.79 +    yield addTab("about:start");
    1.80 +    yield addTab("about:mozilla");
    1.81 +  },
    1.82 +  run: function () {
    1.83 +    let browser = getBrowser();
    1.84 +    let notn = createTestNotification("label", "adopt-notification");
    1.85 +    let firstBox = Browser.getNotificationBox();
    1.86 +    let nextTab = Browser.getNextTab(Browser.getTabForBrowser(browser));
    1.87 +    let nextBox = Browser.getNotificationBox(nextTab.browser);
    1.88 +
    1.89 +    ok(firstBox.getNotificationWithValue("adopt-notification"), "notificationbox has our notification intially");
    1.90 +    nextBox.adoptNotification(notn);
    1.91 +
    1.92 +    ok(!firstBox.getNotificationWithValue("adopt-notification"), "after adoptNotification, original notificationbox no longer has our notification");
    1.93 +    ok(nextBox.getNotificationWithValue("adopt-notification"), "next notificationbox has our notification");
    1.94 +  },
    1.95 +  // leave browser in clean state for next tests
    1.96 +  tearDown: cleanUpOpenedTabs
    1.97 +});
    1.98 +

mercurial