constructor-basic.https.html (2077B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Notification constructor (basic)</title> 4 <link rel="author" title="Intel" href="http://www.intel.com/"> 5 <link rel="author" title="Xin Liu" href="mailto:xinx.liu@intel.com"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script> 9 test(function() { 10 var notification = new Notification("New Email Received") 11 assert_true(notification instanceof Notification) 12 notification.onshow = function() { 13 notification.close() 14 } 15 }, "Called the notification constructor with one argument.") 16 17 test(() => { 18 assert_equals( 19 new Notification("a").silent, 20 null, 21 "Expected null by default" 22 ); 23 }, "Constructing a notification without a NotificationOptions defaults to null."); 24 25 test(() => { 26 for (const silent of [null, undefined]) { 27 assert_equals( 28 new Notification("a", { silent }).silent, 29 null, 30 `Expected silent to be null when initialized with ${silent}.` 31 ); 32 } 33 for (const silent of [true, 1, 100, {}, [], "a string"]) { 34 assert_true( 35 new Notification("a", { silent }).silent, 36 `Expected silent to be true when initialized with ${silent}.` 37 ); 38 } 39 for (const silent of [false, 0, "", NaN]) { 40 assert_false( 41 new Notification("a", { silent }).silent, 42 `Expected silent to be false when initialized with ${silent}.` 43 ); 44 } 45 }, "constructing a notification with a NotificationOptions dictionary correctly sets and reflects the silent attribute."); 46 47 test(() => { 48 const notification = new Notification("a"); 49 assert_equals(notification.lang, "", "lang should default to an empty string"); 50 assert_equals(notification.body, "", "body should default to an empty string"); 51 assert_equals(notification.tag, "", "tag should default to an empty string"); 52 assert_equals(notification.icon, "", "icon should default to an empty string"); 53 }, "String options should default to empty strings"); 54 </script>