Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / constructors / serviceworker-message-event-constructor.html
blobd1a207c22b6ea53ffbe00856b2fff6c4c799883e
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
9 description("This tests the constructor for the ServiceWorkerMessageEvent DOM class.");
11 var test_object = {nyannyan: 123};
13 // No initializer is passed.
14 shouldBe("new ServiceWorkerMessageEvent('eventType').bubbles", "false");
15 shouldBe("new ServiceWorkerMessageEvent('eventType').cancelable", "false");
16 shouldBe("new ServiceWorkerMessageEvent('eventType').data", "null");
17 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType').origin", "");
18 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType').lastEventId", "");
19 shouldBe("new ServiceWorkerMessageEvent('eventType').source", "null");
20 shouldBe("new ServiceWorkerMessageEvent('eventType').ports", "null");
22 // bubbles is passed.
23 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: false }).bubbles", "false");
24 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true }).bubbles", "true");
26 // cancelable is passed.
27 shouldBe("new ServiceWorkerMessageEvent('eventType', { cancelable: false }).cancelable", "false");
28 shouldBe("new ServiceWorkerMessageEvent('eventType', { cancelable: true }).cancelable", "true");
30 // data is passed.
31 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: test_object }).data", "test_object");
32 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: document }).data", "document");
33 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: undefined }).data", "null");
34 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: null }).data", "null");
35 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: false }).data", "false");
36 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: true }).data", "true");
37 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { data: '' }).data", "");
38 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { data: 'chocolate' }).data", "chocolate");
39 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: 12345 }).data", "12345");
40 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: 18446744073709551615 }).data", "18446744073709552000");
41 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: NaN }).data", "NaN");
42 // Note that valueOf() is not called, when the left hand side is evaluated.
43 shouldBeFalse("new ServiceWorkerMessageEvent('eventType', { data: {valueOf: function () { return test_object; } } }).data == test_object");
44 shouldBe("new ServiceWorkerMessageEvent('eventType', { get data() { return 123; } }).data", "123");
45 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get data() { throw 'ServiceWorkerMessageEvent Error'; } })");
47 // origin or lastEventId is passed.
48 ["origin", "lastEventId"].forEach(function (attr) {
49 // Strings.
50 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": 'melancholy' })." + attr, "melancholy");
51 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": '' })." + attr, "");
53 // Non-strings.
54 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": undefined })." + attr, "");
55 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": null })." + attr, "null");
56 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": false })." + attr, "false");
57 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": true })." + attr, "true");
58 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": 12345 })." + attr, "12345");
59 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": 18446744073709551615 })." + attr, "18446744073709552000");
60 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": NaN })." + attr, "NaN");
61 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": [] })." + attr, "");
62 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": [1, 2, 3] })." + attr, "1,2,3");
63 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": {melancholy: 12345} })." + attr, "[object Object]");
64 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": {valueOf: function () { return 'melancholy'; } } })." + attr, "[object Object]");
65 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { get " + attr + "() { return 123; } })." + attr, "123");
66 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get " + attr + "() { throw 'ServiceWorkerMessageEvent Error'; } })");
67 });
69 // MessagePort objects.
70 var channel = new MessageChannel();
71 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1], source: channel.port1 }).source", "channel.port1");
73 // Unacceptable source objects (not a ServiceWorker or a MessagePort).
74 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: window }).source");
75 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: this }).source");
76 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: test_object }).source");
77 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: document }).source");
78 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: document.body }).source");
79 shouldBe("new ServiceWorkerMessageEvent('eventType', { source: undefined }).source", "null");
80 shouldBe("new ServiceWorkerMessageEvent('eventType', { source: null }).source", "null");
81 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: false }).source");
82 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: true }).source");
83 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: '' }).source");
84 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: 'chocolate' }).source");
85 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: 12345 }).source");
86 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: 18446744073709551615 }).source");
87 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: NaN }).source");
88 // Note that valueOf() is not called, when the left hand side is evaluated.
89 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: {valueOf: function () { return window; } } }).source == window");
90 shouldBe("new ServiceWorkerMessageEvent('eventType', { get source() { return channel.port1; } }).source", "channel.port1");
91 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get source() { return 123; } }).source");
92 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get source() { throw 'ServiceWorkerMessageEvent Error'; } })");
94 // ports is passed.
95 // Valid message ports.
96 var channel2 = new MessageChannel();
97 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, channel.port2, channel2.port1] }).ports[0]", "channel.port1");
98 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, channel.port2, channel2.port1] }).ports[1]", "channel.port2");
99 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, channel.port2, channel2.port1] }).ports[2]", "channel2.port1");
100 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [] }).ports", "[]");
101 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: undefined }).ports", "null");
103 // Invalid message ports.
104 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: null }).ports");
105 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: [1, 2, 3] }).ports[2]");
106 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: test_object }).ports");
107 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: document }).ports");
108 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: false }).ports");
109 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: true }).ports");
110 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: '' }).ports");
111 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: 'chocolate' }).ports");
112 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: 12345 }).ports");
113 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: 18446744073709551615 }).ports");
114 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: NaN }).ports");
115 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get ports() { return 123; } }).ports");
116 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get ports() { throw 'ServiceWorkerMessageEvent Error'; } })");
117 // Note that valueOf() is not called, when the left hand side is evaluated.
118 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: {valueOf: function () { return [channel.port1, channel.port2, channel.port2]; } } }).ports[0]");
120 // All initializers are passed.
122 var port = new MessageChannel().port1;
123 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).bubbles", "true");
124 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).cancelable", "true");
125 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).data", "test_object");
126 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).origin", "wonderful");
127 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).lastEventId", "excellent");
128 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).source", "port");
129 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).ports[0]", "channel.port1");
130 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).ports[1]", "channel.port2");
131 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).ports[2]", "channel2.port1");
132 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: port, ports: {length: 3, 0: channel.port1, 1: channel.port2, 2: channel2.port1} }).ports[2]", "channel2.port1");
134 </script>
135 </body>
136 </html>