Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 3 // This helper also exposes |client|, |postMessage()|, |runNextTestOrQuit()|, | |
| 4 // |synthesizeNotificationClick()| and |initialize()|. | |
| 5 importScripts('sw-test-helpers.js'); | |
| 6 importScripts('../../../resources/get-host-info.js'); | |
| 7 | |
| 8 function initializeClient() { | |
| 9 synthesizeNotificationClick().then(function(e) { | |
| 10 clients.openWindow('blank.html').then(function(c) { | |
| 11 return c; | |
| 12 }).then(runNextTestOrQuit); | |
| 13 }); | |
| 14 } | |
| 15 | |
| 16 var TESTS = [ | |
| 17 | |
| 18 initializeClient, | |
| 19 | |
| 20 function testNavigateControlledClient(client) { | |
| 21 client.navigate('test.html').then(function(c) { | |
| 22 self.postMessage('navigate() can navigate controlled client'); | |
| 23 self.postMessage('navigate() result: ' + c); | |
| 24 self.postMessage(' url: ' + c.url); | |
| 25 self.postMessage(' visibilityState: ' + c.visibilityState); | |
| 26 self.postMessage(' focused: ' + c.focused); | |
| 27 self.postMessage(' frameType: ' + c.frameType); | |
| 28 return c; | |
| 29 }).then(runNextTestOrQuit); | |
| 30 }, | |
| 31 | |
| 32 initializeClient, | |
| 33 | |
| 34 function testNavigateNotControlledClient(client) { | |
|
nhiroki
2015/07/15 08:53:14
|client| ("/serviceworker/chromium/resources/blank
zino
2015/09/22 07:53:31
Done.
| |
| 35 client.navigate('/').then(function(c) { | |
| 36 self.postMessage('navigate() can navigate not controlled client'); | |
|
nhiroki
2015/07/15 08:53:14
According to the spec, non-controlled clients shou
zino
2015/09/22 07:53:31
Done.
| |
| 37 self.postMessage('navigate() result: ' + c); | |
| 38 return c; | |
| 39 }).then(runNextTestOrQuit); | |
| 40 }, | |
| 41 | |
| 42 initializeClient, | |
| 43 | |
| 44 function testNavigateCrossOriginClient(client) { | |
| 45 var cross_origin_url = get_host_info()['HTTP_REMOTE_ORIGIN'] + | |
| 46 '/serviceworker/chromium/resources/blank.html'; | |
| 47 client.navigate(cross_origin_url).then(function(c) { | |
| 48 self.postMessage('navigate() can navigate to a cross origin url'); | |
| 49 self.postMessage('navigate() result: ' + c); | |
| 50 }).then(runNextTestOrQuit); | |
| 51 }, | |
| 52 | |
| 53 initializeClient, | |
| 54 | |
| 55 function testNavigateInvalidURL(client) { | |
| 56 client.navigate('http://[test].com').catch(function(e) { | |
| 57 self.postMessage('navigate() can not navigate to an invalid url'); | |
| 58 self.postMessage('navigate() error is ' + e.name); | |
| 59 return client; | |
| 60 }).then(runNextTestOrQuit); | |
| 61 }, | |
| 62 | |
| 63 function testNavigateViewSource(client) { | |
| 64 client.navigate('view-source://http://test.com').catch(function(e) { | |
| 65 self.postMessage('navigate() can not navigate to ' + | |
| 66 'view-source scheme'); | |
| 67 self.postMessage('navigate() error is ' + e.name); | |
| 68 return client; | |
| 69 }).then(runNextTestOrQuit); | |
| 70 }, | |
| 71 | |
| 72 function testNavigateFileScheme(client) { | |
| 73 client.navigate('file:///').catch(function(e) { | |
| 74 self.postMessage('navigate() can not navigate to file scheme'); | |
| 75 self.postMessage('navigate() error is ' + e.name); | |
| 76 return client; | |
| 77 }).then(runNextTestOrQuit); | |
| 78 }, | |
| 79 | |
| 80 function testNavigateAboutBlank(client) { | |
| 81 client.navigate('about:blank').catch(function(e) { | |
| 82 self.postMessage('navigate() can not navigate to about:blank'); | |
| 83 self.postMessage('navigate() error is ' + e.name); | |
| 84 return client; | |
| 85 }).then(runNextTestOrQuit); | |
| 86 }, | |
| 87 | |
| 88 function testNavigateAboutCrash(client) { | |
| 89 client.navigate('about:crash').catch(function(e) { | |
| 90 self.postMessage('navigate() can not navigate to about:crash'); | |
| 91 self.postMessage('navigate() error is ' + e.name); | |
| 92 return client; | |
| 93 }).then(runNextTestOrQuit); | |
| 94 } | |
| 95 ]; | |
| 96 | |
| 97 self.onmessage = function(e) { | |
| 98 if (e.data == 'start') { | |
| 99 initialize().then(runNextTestOrQuit); | |
| 100 } else { | |
| 101 initialize().then(function() { | |
| 102 self.postMessage('received unexpected message'); | |
| 103 self.postMessage('quit'); | |
| 104 }); | |
| 105 } | |
| 106 }; | |
| OLD | NEW |