OLD | NEW |
1 // This helper will setup a small test framework that will use TESTS and run | 1 // This helper will setup a small test framework that will use TESTS and run |
2 // them sequentially and call self.postMessage('quit') when done. | 2 // them sequentially and call self.postMessage('quit') when done. |
3 // This helper also exposes |client|, |postMessage()|, |runNextTestOrQuit()|, | 3 // This helper also exposes |client|, |postMessage()|, |runNextTestOrQuit()|, |
4 // |synthesizeNotificationClick()| and |initialize()|. | 4 // |synthesizeNotificationClick()| and |initialize()|. |
5 importScripts('sw-test-helpers.js'); | 5 importScripts('sw-test-helpers.js'); |
6 | 6 |
7 var TESTS = [ | 7 var TESTS = [ |
8 function testWithNoNotificationClick() { | 8 function testWithNoNotificationClick() { |
9 clients.openWindow('/').catch(function(e) { | 9 clients.openWindow('/').catch(function(e) { |
10 self.postMessage('openWindow() can\'t open a window without a user i
nteraction'); | 10 self.postMessage('openWindow() can\'t open a window without a user i
nteraction'); |
11 self.postMessage('openWindow() error is ' + e.name); | 11 self.postMessage('openWindow() error is ' + e.name); |
12 }).then(runNextTestOrQuit); | 12 }).then(runNextTestOrQuit); |
13 }, | 13 }, |
14 | 14 |
15 function testOpenCrossOriginWindow() { | 15 function testOpenCrossOriginWindow() { |
16 synthesizeNotificationClick().then(function(e) { | 16 synthesizeNotificationClick().then(function(e) { |
17 clients.openWindow('https://test.com/').catch(function(e) { | 17 clients.openWindow('https://test.com/').then(function(c) { |
18 self.postMessage('openWindow() can\'t open cross origin windows'
); | 18 self.postMessage('openWindow() can open cross origin windows'); |
19 self.postMessage('openWindow() error is ' + e.name); | 19 self.postMessage('openWindow() result: ' + c); |
20 }).then(runNextTestOrQuit); | 20 }).then(runNextTestOrQuit); |
21 }); | 21 }); |
22 }, | 22 }, |
23 | 23 |
24 function testOpenNotControlledWindow() { | 24 function testOpenNotControlledWindow() { |
25 synthesizeNotificationClick().then(function(e) { | 25 synthesizeNotificationClick().then(function(e) { |
26 clients.openWindow('/').then(function(c) { | 26 clients.openWindow('/').then(function(c) { |
27 self.postMessage('openWindow() can open not controlled windows')
; | 27 self.postMessage('openWindow() can open not controlled windows')
; |
28 self.postMessage('openWindow() result: ' + c); | 28 self.postMessage('openWindow() result: ' + c); |
29 }).then(runNextTestOrQuit); | 29 }).then(runNextTestOrQuit); |
30 }); | 30 }); |
31 }, | 31 }, |
32 | 32 |
33 function testOpenControlledWindow() { | 33 function testOpenControlledWindow() { |
34 synthesizeNotificationClick().then(function(e) { | 34 synthesizeNotificationClick().then(function(e) { |
35 clients.openWindow('blank.html').then(function(c) { | 35 clients.openWindow('blank.html').then(function(c) { |
36 self.postMessage('openWindow() can open controlled windows'); | 36 self.postMessage('openWindow() can open controlled windows'); |
37 self.postMessage('openWindow() result: ' + c); | 37 self.postMessage('openWindow() result: ' + c); |
38 self.postMessage(' url: ' + c.url); | 38 self.postMessage(' url: ' + c.url); |
39 self.postMessage(' visibilityState: ' + c.visibilityState); | 39 self.postMessage(' visibilityState: ' + c.visibilityState); |
40 self.postMessage(' focused: ' + c.focused); | 40 self.postMessage(' focused: ' + c.focused); |
41 self.postMessage(' frameType: ' + c.frameType); | 41 self.postMessage(' frameType: ' + c.frameType); |
42 }).then(runNextTestOrQuit); | 42 }).then(runNextTestOrQuit); |
43 }); | 43 }); |
44 } | 44 }, |
| 45 |
| 46 function testOpenAboutBlank() { |
| 47 synthesizeNotificationClick().then(function(e) { |
| 48 clients.openWindow('about:blank').then(function(c) { |
| 49 self.postMessage('openWindow() can open about:blank'); |
| 50 self.postMessage('openWindow() result: ' + c); |
| 51 }).then(runNextTestOrQuit); |
| 52 }); |
| 53 }, |
| 54 |
| 55 function testOpenAboutCrash() { |
| 56 synthesizeNotificationClick().then(function(e) { |
| 57 clients.openWindow('about:crash').then(function(c) { |
| 58 self.postMessage('openWindow() can open about:crash'); |
| 59 self.postMessage('openWindow() result: ' + c); |
| 60 }).then(runNextTestOrQuit); |
| 61 }); |
| 62 }, |
| 63 |
| 64 function testOpenViewSource() { |
| 65 synthesizeNotificationClick().then(function(e) { |
| 66 clients.openWindow('view-source://http://test.com').catch(function(c
) { |
| 67 self.postMessage('openWindow() can not open view-source scheme')
; |
| 68 }).then(runNextTestOrQuit); |
| 69 }); |
| 70 }, |
| 71 |
| 72 function testOpenFileScheme() { |
| 73 synthesizeNotificationClick().then(function(e) { |
| 74 clients.openWindow('file:///').catch(function(error) { |
| 75 self.postMessage('openWindow() can not open file scheme'); |
| 76 self.postMessage('openWindow() error is: ' + error.name); |
| 77 }).then(runNextTestOrQuit); |
| 78 }); |
| 79 }, |
45 ]; | 80 ]; |
46 | 81 |
47 self.onmessage = function(e) { | 82 self.onmessage = function(e) { |
48 if (e.data == 'start') { | 83 if (e.data == 'start') { |
49 initialize().then(runNextTestOrQuit); | 84 initialize().then(runNextTestOrQuit); |
50 } else { | 85 } else { |
51 initialize().then(function() { | 86 initialize().then(function() { |
52 self.postMessage('received unexpected message'); | 87 self.postMessage('received unexpected message'); |
53 self.postMessage('quit'); | 88 self.postMessage('quit'); |
54 }); | 89 }); |
55 } | 90 } |
56 }; | 91 }; |
OLD | NEW |