OLD | NEW |
---|---|
(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", "[]"); | |
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 // FIXME: undefined data will return null at the moment. | |
34 //shouldBe("new ServiceWorkerMessageEvent('eventType', { data: undefined }).data ", "undefined"); | |
bashi
2015/05/22 00:23:36
Per spec, it should be null.
- In terms of IDL di
xiang
2015/05/25 02:04:25
I see, thanks!
| |
35 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: null }).data", "nul l"); | |
36 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: false }).data", "fa lse"); | |
37 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: true }).data", "tru e"); | |
38 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { data: '' }). data", ""); | |
39 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { data: 'choco late' }).data", "chocolate"); | |
40 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: 12345 }).data", "12 345"); | |
41 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: 1844674407370955161 5 }).data", "18446744073709552000"); | |
42 shouldBe("new ServiceWorkerMessageEvent('eventType', { data: NaN }).data", "NaN" ); | |
43 // Note that valueOf() is not called, when the left hand side is evaluated. | |
44 shouldBeFalse("new ServiceWorkerMessageEvent('eventType', { data: {valueOf: func tion () { return test_object; } } }).data == test_object"); | |
45 shouldBe("new ServiceWorkerMessageEvent('eventType', { get data() { return 123; } }).data", "123"); | |
46 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get data() { throw 'Se rviceWorkerMessageEvent Error'; } })"); | |
47 | |
48 // origin or lastEventId is passed. | |
49 ["origin", "lastEventId"].forEach(function (attr) { | |
50 // Strings. | |
51 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": 'melancholy' })." + attr, "melancholy"); | |
52 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": '' })." + attr, ""); | |
53 | |
54 // Non-strings. | |
55 // FIXME: undefined origin/lastEventId will return "" at the moment. | |
56 //shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + at tr + ": undefined })." + attr, "undefined"); | |
57 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": null })." + attr, "null"); | |
58 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": false })." + attr, "false"); | |
59 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": true })." + attr, "true"); | |
60 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": 12345 })." + attr, "12345"); | |
61 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": 18446744073709551615 })." + attr, "18446744073709552000"); | |
62 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": NaN })." + attr, "NaN"); | |
63 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": [] })." + attr, ""); | |
64 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": [1, 2, 3] })." + attr, "1,2,3"); | |
65 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": {melancholy: 12345} })." + attr, "[object Object]"); | |
66 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { " + attr + ": {valueOf: function () { return 'melancholy'; } } })." + attr, "[object Obj ect]"); | |
67 shouldBeEqualToString("new ServiceWorkerMessageEvent('eventType', { get " + attr + "() { return 123; } })." + attr, "123"); | |
68 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get " + attr + "() { throw 'ServiceWorkerMessageEvent Error'; } })"); | |
69 }); | |
70 | |
71 // MessagePort objects. | |
72 var channel = new MessageChannel(); | |
73 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1], s ource: channel.port1 }).source", "channel.port1"); | |
74 | |
75 // Unacceptable source objects (not a ServiceWorker or a MessagePort). | |
76 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: window }).sour ce"); | |
77 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: this }).source "); | |
78 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: test_object }) .source"); | |
79 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: document }).so urce"); | |
80 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: document.body }).source"); | |
81 shouldBe("new ServiceWorkerMessageEvent('eventType', { source: undefined }).sour ce", "null"); | |
82 shouldBe("new ServiceWorkerMessageEvent('eventType', { source: null }).source", "null"); | |
83 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: false }).sourc e"); | |
84 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: true }).source "); | |
85 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: '' }).source") ; | |
86 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: 'chocolate' }) .source"); | |
87 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: 12345 }).sourc e"); | |
88 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: 18446744073709 551615 }).source"); | |
89 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: NaN }).source" ); | |
90 // Note that valueOf() is not called, when the left hand side is evaluated. | |
91 shouldThrow("new ServiceWorkerMessageEvent('eventType', { source: {valueOf: func tion () { return window; } } }).source == window"); | |
92 shouldBe("new ServiceWorkerMessageEvent('eventType', { get source() { return cha nnel.port1; } }).source", "channel.port1"); | |
93 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get source() { return 123; } }).source"); | |
94 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get source() { throw ' ServiceWorkerMessageEvent Error'; } })"); | |
95 | |
96 // ports is passed. | |
97 // Valid message ports. | |
98 var channel2 = new MessageChannel(); | |
99 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, ch annel.port2, channel2.port1] }).ports[0]", "channel.port1"); | |
100 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, ch annel.port2, channel2.port1] }).ports[1]", "channel.port2"); | |
101 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [channel.port1, ch annel.port2, channel2.port1] }).ports[2]", "channel2.port1"); | |
102 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: [] }).ports", "[]" ); | |
103 shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: undefined }).ports ", "[]"); | |
104 // FIXME null ports will trigger TypeError exception at the moment. | |
105 //shouldBe("new ServiceWorkerMessageEvent('eventType', { ports: null }).ports", "[]"); | |
106 | |
107 // Invalid message ports. | |
108 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: [1, 2, 3] }).po rts[2]"); | |
109 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: test_object }). ports"); | |
110 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: document }).por ts"); | |
111 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: false }).ports" ); | |
112 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: true }).ports") ; | |
113 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: '' }).ports"); | |
114 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: 'chocolate' }). ports"); | |
115 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: 12345 }).ports" ); | |
116 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: 184467440737095 51615 }).ports"); | |
117 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: NaN }).ports"); | |
118 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get ports() { return 1 23; } }).ports"); | |
119 shouldThrow("new ServiceWorkerMessageEvent('eventType', { get ports() { throw 'S erviceWorkerMessageEvent Error'; } })"); | |
120 // Note that valueOf() is not called, when the left hand side is evaluated. | |
121 shouldThrow("new ServiceWorkerMessageEvent('eventType', { ports: {valueOf: funct ion () { return [channel.port1, channel.port2, channel.port2]; } } }).ports[0]") ; | |
122 | |
123 // All initializers are passed. | |
124 | |
125 var port = new MessageChannel().port1; | |
126 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 "); | |
127 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"); | |
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] }).data", "test_ob ject"); | |
129 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"); | |
130 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"); | |
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] }).source", "port" ); | |
132 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"); | |
133 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"); | |
134 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"); | |
135 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"); | |
136 | |
137 </script> | |
138 </body> | |
139 </html> | |
OLD | NEW |