Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Side by Side Diff: LayoutTests/fast/events/constructors/serviceworker-message-event-constructor.html

Issue 1130113006: ServiceWorker: Introduce ServiceWorkerMessageEvent to replace MessageEvent (3/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: make more tests pass Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8
9 description("This tests the constructor for the ServiceWorkerMessageEvent DOM cl ass.");
10
11 var test_object = {nyannyan: 123};
12
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");
21
22 // bubbles is passed.
23 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: false }).bubbles ", "false");
24 shouldBe("new ServiceWorkerMessageEvent('eventType', { bubbles: true }).bubbles" , "true");
25
26 // cancelable is passed.
27 shouldBe("new ServiceWorkerMessageEvent('eventType', { cancelable: false }).canc elable", "false");
28 shouldBe("new ServiceWorkerMessageEvent('eventType', { cancelable: true }).cance lable", "true");
29
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", "nul l");
35 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: false }).data", "fa lse");
36 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: true }).data", "tru e");
37 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { data: '' }). data", "");
38 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { data: 'choco late' }).data", "chocolate");
39 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: 12345 }).data", "12 345");
40 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: 1844674407370955161 5 }).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: func tion () { 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 'Se rviceWorkerMessageEvent Error'; } })");
46
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, "");
52
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 Obj ect]");
65 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { get " + attr + "() { return 123; } })." + attr, "123");
66 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get " + attr + "() { throw 'ServiceWorkerMessageEvent Error'; } })");
67 });
68
69 // MessagePort objects.
70 var channel = new MessageChannel();
71 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1], s ource: channel.port1 }).source", "channel.port1");
72
73 // Unacceptable source objects (not a ServiceWorker or a MessagePort).
74 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: window }).sour ce");
75 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: this }).source ");
76 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: test_object }) .source");
77 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: document }).so urce");
78 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: document.body }).source");
79 shouldBe("new ServiceWorkerMessageEvent('eventType', { source: undefined }).sour ce", "null");
80 shouldBe("new ServiceWorkerMessageEvent('eventType', { source: null }).source", "null");
81 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: false }).sourc e");
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 }).sourc e");
86 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: 18446744073709 551615 }).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: func tion () { return window; } } }).source == window");
90 shouldBe("new ServiceWorkerMessageEvent('eventType', { get source() { return cha nnel.port1; } }).source", "channel.port1");
91 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get source() { return 123; } }).source");
92 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get source() { throw ' ServiceWorkerMessageEvent Error'; } })");
93
94 // ports is passed.
95 // Valid message ports.
96 var channel2 = new MessageChannel();
97 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, ch annel.port2, channel2.port1] }).ports[0]", "channel.port1");
98 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, ch annel.port2, channel2.port1] }).ports[1]", "channel.port2");
99 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, ch annel.port2, channel2.port1] }).ports[2]", "channel2.port1");
100 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [] }).ports", "[]" );
101 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: undefined }).ports ", "null");
102
103 // Invalid message ports.
104 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: null }).ports") ;
105 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: [1, 2, 3] }).po rts[2]");
106 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: test_object }). ports");
107 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: document }).por ts");
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: 184467440737095 51615 }).ports");
114 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: NaN }).ports");
115 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get ports() { return 1 23; } }).ports");
116 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get ports() { throw 'S erviceWorkerMessageEvent Error'; } })");
117 // Note that valueOf() is not called, when the left hand side is evaluated.
118 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: {valueOf: funct ion () { return [channel.port1, channel.port2, channel.port2]; } } }).ports[0]") ;
119
120 // All initializers are passed.
121
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", "t rue");
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_ob ject");
126 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { bubbles: tru e, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excel lent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).or igin", "wonderful");
127 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { bubbles: tru e, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excel lent', source: port, ports: [channel.port1, channel.port2, channel2.port1] }).la stEventId", "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]", "cha nnel.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]", "cha nnel.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]", "cha nnel2.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");
133
134 </script>
135 </body>
136 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698