Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / chromium / resources / clients-openwindow.js
blob7671ba6746be3483b7485af372e95b1285e0a028
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');
8 var TESTS = [
9     function testWithNoNotificationClick() {
10         clients.openWindow('/').catch(function(e) {
11             self.postMessage('openWindow() can\'t open a window without a user interaction');
12             self.postMessage('openWindow() error is ' + e.name);
13         }).then(runNextTestOrQuit);
14     },
16     function testOpenCrossOriginWindow() {
17         synthesizeNotificationClick().then(function(e) {
18             var cross_origin_url =
19                 get_host_info()['HTTP_REMOTE_ORIGIN'] +
20                 '/serviceworker/chromium/resources/blank.html';
21             clients.openWindow(cross_origin_url).then(function(c) {
22                 self.postMessage('openWindow() can open cross origin windows');
23                 self.postMessage('openWindow() result: ' + c);
24             }).then(runNextTestOrQuit);
25         });
26     },
28     function testOpenNotControlledWindow() {
29         synthesizeNotificationClick().then(function(e) {
30             clients.openWindow('/').then(function(c) {
31                 self.postMessage('openWindow() can open not controlled windows');
32                 self.postMessage('openWindow() result: ' + c);
33             }).then(runNextTestOrQuit);
34         });
35     },
37     function testOpenControlledWindow() {
38         synthesizeNotificationClick().then(function(e) {
39             clients.openWindow('blank.html').then(function(c) {
40                 self.postMessage('openWindow() can open controlled windows');
41                 self.postMessage('openWindow() result: ' + c);
42                 self.postMessage(' url: ' + c.url);
43                 self.postMessage(' visibilityState: ' + c.visibilityState);
44                 self.postMessage(' focused: ' + c.focused);
45                 self.postMessage(' frameType: ' + c.frameType);
46             }).then(runNextTestOrQuit);
47         });
48     },
50     function testOpenAboutBlank() {
51         synthesizeNotificationClick().then(function(e) {
52             clients.openWindow('about:blank').then(function(c) {
53                 self.postMessage('openWindow() can open about:blank');
54                 self.postMessage('openWindow() result: ' + c);
55             }).then(runNextTestOrQuit);
56         });
57     },
59     function testOpenAboutCrash() {
60         synthesizeNotificationClick().then(function(e) {
61             clients.openWindow('about:crash').then(function(c) {
62                 self.postMessage('openWindow() can open about:crash');
63                 self.postMessage('openWindow() result: ' + c);
64             }).then(runNextTestOrQuit);
65         });
66     },
68     function testOpenInvalidURL() {
69         synthesizeNotificationClick().then(function(e) {
70             clients.openWindow('http://[test].com').catch(function(error) {
71                 self.postMessage('openWindow() can not open an invalid url');
72                 self.postMessage('openWindow() error is: ' + error.name);
73             }).then(runNextTestOrQuit);
74         });
75     },
77     function testOpenViewSource() {
78         synthesizeNotificationClick().then(function(e) {
79             clients.openWindow('view-source://http://test.com').catch(function(c) {
80                 self.postMessage('openWindow() can not open view-source scheme');
81             }).then(runNextTestOrQuit);
82         });
83     },
85     function testOpenFileScheme() {
86         synthesizeNotificationClick().then(function(e) {
87             clients.openWindow('file:///').catch(function(error) {
88                 self.postMessage('openWindow() can not open file scheme');
89                 self.postMessage('openWindow() error is: ' + error.name);
90             }).then(runNextTestOrQuit);
91         });
92     },
95 self.onmessage = function(e) {
96     if (e.data == 'start') {
97         initialize().then(runNextTestOrQuit);
98     } else {
99         initialize().then(function() {
100             self.postMessage('received unexpected message');
101             self.postMessage('quit');
102         });
103     }