1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/notification/test_notification_storage.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Notification Basics</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="MockServices.js"></script> 1.10 + <script type="text/javascript" src="NotificationTest.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.12 +</head> 1.13 +<body> 1.14 +<p id="display"></p> 1.15 +<div id="content" style="display: none"></div> 1.16 +<pre id="test"></pre> 1.17 +<script type="text/javascript"> 1.18 + 1.19 + function deleteAllNotifications() { 1.20 + var promise = Notification.get(); 1.21 + promise.then(function (notifications) { 1.22 + notifications.forEach(function(notification) { 1.23 + notification.close(); 1.24 + }); 1.25 + }); 1.26 + } 1.27 + 1.28 + var info = NotificationTest.info; 1.29 + 1.30 + var steps = [ 1.31 + function (done) { 1.32 + info("Test that Notifcation.get fulfills the promise"); 1.33 + var promise = Notification.get(); 1.34 + ok(promise.then, "should return a promise"); 1.35 + 1.36 + // Create a new notification to make sure 1.37 + // Notification.get() works while creating 1.38 + var notification = new Notification("this is a test"); 1.39 + 1.40 + promise.then(function () { 1.41 + ok(true, "promise should be fulfilled"); 1.42 + done(); 1.43 + }); 1.44 + }, 1.45 + 1.46 + deleteAllNotifications, 1.47 + 1.48 + function (done) { 1.49 + info("Test adding a notification, and making sure get returns it"); 1.50 + NotificationTest.allowNotifications(); 1.51 + var options = { 1.52 + dir: "auto", 1.53 + lang: "", 1.54 + body: "This is a notification body", 1.55 + tag: "sometag", 1.56 + icon: "icon.png" 1.57 + }; 1.58 + var notification = new Notification("This is a title", options); 1.59 + var promise = Notification.get(); 1.60 + promise.then(function (notifications) { 1.61 + ok(notifications.length, "should return notifications"); 1.62 + for (var i = 0; i < notifications.length; i++) { 1.63 + var notification = notifications[i]; 1.64 + if (notification.tag === options.tag) { 1.65 + ok(true, "should contain newly created notification"); 1.66 + for (var key in options) { 1.67 + is(notification[key], options[key], key + " property should match"); 1.68 + } 1.69 + notification.close(); 1.70 + return; 1.71 + } 1.72 + } 1.73 + ok(false, "should contain newly created notification"); 1.74 + notification.close(); 1.75 + }); 1.76 + notification.onclose = done; 1.77 + }, 1.78 + 1.79 + function (done) { 1.80 + info("Testing fetching notification by tag filter"); 1.81 + var n1 = new Notification("title1", {tag: "tag1"}); 1.82 + var n2 = new Notification("title2", {tag: "tag2"}); 1.83 + var n3 = new Notification("title3", {tag: "tag3"}); 1.84 + var promise = Notification.get({tag: "tag3"}); 1.85 + promise.then(function (notifications) { 1.86 + var notification = notifications[0]; 1.87 + is(notifications.length, 1, "should return 1 notification"); 1.88 + is(notifications[0].title, "title3", "titles should match"); 1.89 + is(notifications[0].tag, "tag3", "tags should match"); 1.90 + var closeCount = 0; 1.91 + var waitForAll = function () { 1.92 + if (++closeCount >= 3) { 1.93 + done(); 1.94 + } 1.95 + }; 1.96 + n1.onclose = waitForAll; 1.97 + n2.onclose = waitForAll; 1.98 + n3.onclose = waitForAll; 1.99 + n1.close(); 1.100 + n2.close(); 1.101 + n3.close(); 1.102 + }); 1.103 + }, 1.104 + 1.105 + deleteAllNotifications, 1.106 + 1.107 + function (done) { 1.108 + info("Testing fetching no notifications"); 1.109 + var promise = Notification.get(); 1.110 + promise.then(function (notifications) { 1.111 + is(notifications.length, 0, "should return 0 notifications"); 1.112 + done(); 1.113 + }); 1.114 + }, 1.115 + 1.116 + function (done) { 1.117 + info("Testing fetching multiple notifications"); 1.118 + var n1 = new Notification("title1"); 1.119 + var n2 = new Notification("title2"); 1.120 + var n3 = new Notification("title3"); 1.121 + var promise = Notification.get(); 1.122 + promise.then(function (notifications) { 1.123 + is(notifications.length, 3, "should return 2 notifications"); 1.124 + done(); 1.125 + }); 1.126 + } 1.127 + ]; 1.128 + 1.129 + MockServices.register(); 1.130 + NotificationTest.run(steps, function () { 1.131 + MockServices.unregister(); 1.132 + }); 1.133 +</script> 1.134 +</body> 1.135 +</html>