Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Notification Basics</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="MockServices.js"></script> |
michael@0 | 7 | <script type="text/javascript" src="NotificationTest.js"></script> |
michael@0 | 8 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 9 | </head> |
michael@0 | 10 | <body> |
michael@0 | 11 | <p id="display"></p> |
michael@0 | 12 | <div id="content" style="display: none"></div> |
michael@0 | 13 | <pre id="test"></pre> |
michael@0 | 14 | <script type="text/javascript"> |
michael@0 | 15 | |
michael@0 | 16 | function deleteAllNotifications() { |
michael@0 | 17 | var promise = Notification.get(); |
michael@0 | 18 | promise.then(function (notifications) { |
michael@0 | 19 | notifications.forEach(function(notification) { |
michael@0 | 20 | notification.close(); |
michael@0 | 21 | }); |
michael@0 | 22 | }); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | var info = NotificationTest.info; |
michael@0 | 26 | |
michael@0 | 27 | var steps = [ |
michael@0 | 28 | function (done) { |
michael@0 | 29 | info("Test that Notifcation.get fulfills the promise"); |
michael@0 | 30 | var promise = Notification.get(); |
michael@0 | 31 | ok(promise.then, "should return a promise"); |
michael@0 | 32 | |
michael@0 | 33 | // Create a new notification to make sure |
michael@0 | 34 | // Notification.get() works while creating |
michael@0 | 35 | var notification = new Notification("this is a test"); |
michael@0 | 36 | |
michael@0 | 37 | promise.then(function () { |
michael@0 | 38 | ok(true, "promise should be fulfilled"); |
michael@0 | 39 | done(); |
michael@0 | 40 | }); |
michael@0 | 41 | }, |
michael@0 | 42 | |
michael@0 | 43 | deleteAllNotifications, |
michael@0 | 44 | |
michael@0 | 45 | function (done) { |
michael@0 | 46 | info("Test adding a notification, and making sure get returns it"); |
michael@0 | 47 | NotificationTest.allowNotifications(); |
michael@0 | 48 | var options = { |
michael@0 | 49 | dir: "auto", |
michael@0 | 50 | lang: "", |
michael@0 | 51 | body: "This is a notification body", |
michael@0 | 52 | tag: "sometag", |
michael@0 | 53 | icon: "icon.png" |
michael@0 | 54 | }; |
michael@0 | 55 | var notification = new Notification("This is a title", options); |
michael@0 | 56 | var promise = Notification.get(); |
michael@0 | 57 | promise.then(function (notifications) { |
michael@0 | 58 | ok(notifications.length, "should return notifications"); |
michael@0 | 59 | for (var i = 0; i < notifications.length; i++) { |
michael@0 | 60 | var notification = notifications[i]; |
michael@0 | 61 | if (notification.tag === options.tag) { |
michael@0 | 62 | ok(true, "should contain newly created notification"); |
michael@0 | 63 | for (var key in options) { |
michael@0 | 64 | is(notification[key], options[key], key + " property should match"); |
michael@0 | 65 | } |
michael@0 | 66 | notification.close(); |
michael@0 | 67 | return; |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | ok(false, "should contain newly created notification"); |
michael@0 | 71 | notification.close(); |
michael@0 | 72 | }); |
michael@0 | 73 | notification.onclose = done; |
michael@0 | 74 | }, |
michael@0 | 75 | |
michael@0 | 76 | function (done) { |
michael@0 | 77 | info("Testing fetching notification by tag filter"); |
michael@0 | 78 | var n1 = new Notification("title1", {tag: "tag1"}); |
michael@0 | 79 | var n2 = new Notification("title2", {tag: "tag2"}); |
michael@0 | 80 | var n3 = new Notification("title3", {tag: "tag3"}); |
michael@0 | 81 | var promise = Notification.get({tag: "tag3"}); |
michael@0 | 82 | promise.then(function (notifications) { |
michael@0 | 83 | var notification = notifications[0]; |
michael@0 | 84 | is(notifications.length, 1, "should return 1 notification"); |
michael@0 | 85 | is(notifications[0].title, "title3", "titles should match"); |
michael@0 | 86 | is(notifications[0].tag, "tag3", "tags should match"); |
michael@0 | 87 | var closeCount = 0; |
michael@0 | 88 | var waitForAll = function () { |
michael@0 | 89 | if (++closeCount >= 3) { |
michael@0 | 90 | done(); |
michael@0 | 91 | } |
michael@0 | 92 | }; |
michael@0 | 93 | n1.onclose = waitForAll; |
michael@0 | 94 | n2.onclose = waitForAll; |
michael@0 | 95 | n3.onclose = waitForAll; |
michael@0 | 96 | n1.close(); |
michael@0 | 97 | n2.close(); |
michael@0 | 98 | n3.close(); |
michael@0 | 99 | }); |
michael@0 | 100 | }, |
michael@0 | 101 | |
michael@0 | 102 | deleteAllNotifications, |
michael@0 | 103 | |
michael@0 | 104 | function (done) { |
michael@0 | 105 | info("Testing fetching no notifications"); |
michael@0 | 106 | var promise = Notification.get(); |
michael@0 | 107 | promise.then(function (notifications) { |
michael@0 | 108 | is(notifications.length, 0, "should return 0 notifications"); |
michael@0 | 109 | done(); |
michael@0 | 110 | }); |
michael@0 | 111 | }, |
michael@0 | 112 | |
michael@0 | 113 | function (done) { |
michael@0 | 114 | info("Testing fetching multiple notifications"); |
michael@0 | 115 | var n1 = new Notification("title1"); |
michael@0 | 116 | var n2 = new Notification("title2"); |
michael@0 | 117 | var n3 = new Notification("title3"); |
michael@0 | 118 | var promise = Notification.get(); |
michael@0 | 119 | promise.then(function (notifications) { |
michael@0 | 120 | is(notifications.length, 3, "should return 2 notifications"); |
michael@0 | 121 | done(); |
michael@0 | 122 | }); |
michael@0 | 123 | } |
michael@0 | 124 | ]; |
michael@0 | 125 | |
michael@0 | 126 | MockServices.register(); |
michael@0 | 127 | NotificationTest.run(steps, function () { |
michael@0 | 128 | MockServices.unregister(); |
michael@0 | 129 | }); |
michael@0 | 130 | </script> |
michael@0 | 131 | </body> |
michael@0 | 132 | </html> |