OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <body> | 2 <body> |
3 <head> | 3 <head> |
4 <script src="../resources/js-test.js"></script> | 4 <script src="../resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <script> | 6 <script> |
7 description("Accessing navigator.getBattery() on a closed window."); | 7 description("Accessing navigator.getBattery() on a closed window."); |
8 | 8 |
9 window.jsTestIsAsync = true; | 9 window.jsTestIsAsync = true; |
10 | 10 |
11 var w; | 11 var w; |
12 var nav; | 12 var nav; |
13 | 13 |
14 function processMessage(event) { | 14 function processMessage(event) { |
15 if (event.data == "opened") { | 15 if (event.data == "opened") { |
16 nav = w.navigator; | 16 nav = w.navigator; |
17 shouldBeTrue("typeof(nav.getBattery()) == 'object'"); | 17 shouldBeTrue("typeof(nav.getBattery()) == 'object'"); |
18 w.close(); | 18 w.close(); |
19 w = null; | 19 w = null; |
20 } else if (event.data == "closed") { | 20 } else if (event.data == "closed") { |
21 shouldBeUndefined("nav.getBattery()"); | 21 nav.getBattery().then(battery => { |
22 finishJSTest(); | 22 assert_unreachable('getBattery should reject on a closed window'); |
| 23 }) |
| 24 .catch(error => { |
| 25 // DOMException.SECURITY_ERR = 18. |
| 26 debug('Error Code is ' + error.code); |
| 27 assert_equals(error.code, DOMException.SECURITY_ERR); |
| 28 }); |
| 29 setTimeout(finishJSTest, 0); |
23 } | 30 } |
24 } | 31 } |
25 | 32 |
26 if (window.testRunner) { | 33 if (window.testRunner) { |
27 testRunner.dumpAsText(); | 34 testRunner.dumpAsText(); |
28 testRunner.setCanOpenWindows(); | 35 testRunner.setCanOpenWindows(); |
29 } | 36 } |
30 w = window.open('../resources/window-postmessage-open-close.html'); | 37 w = window.open('../resources/window-postmessage-open-close.html'); |
31 window.addEventListener("message", processMessage, false); | 38 window.addEventListener("message", processMessage, false); |
32 </script> | 39 </script> |
33 </body> | 40 </body> |
OLD | NEW |