commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="stylesheet" href="../../js/resources/js-test-style.css"> |
| 5 | <script src="../../js/resources/js-test-pre.js"></script> |
| 6 | </head> |
| 7 | <body> |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 8 | <script> |
| 9 | |
| 10 | description("This tests the constructor for the MessageEvent DOM class."); |
| 11 | |
| 12 | var test_object = {nyannyan: 123}; |
| 13 | |
| 14 | // No initializer is passed. |
| 15 | shouldBe("new MessageEvent('eventType').bubbles", "false"); |
| 16 | shouldBe("new MessageEvent('eventType').cancelable", "false"); |
| 17 | shouldBe("new MessageEvent('eventType').data", "null"); |
| 18 | shouldBeEqualToString("new MessageEvent('eventType').origin", ""); |
| 19 | shouldBeEqualToString("new MessageEvent('eventType').lastEventId", ""); |
| 20 | shouldBe("new MessageEvent('eventType').source", "null"); |
| 21 | shouldBe("new MessageEvent('eventType').ports", "[]"); |
| 22 | |
| 23 | // bubbles is passed. |
| 24 | shouldBe("new MessageEvent('eventType', { bubbles: false }).bubbles", "false"); |
| 25 | shouldBe("new MessageEvent('eventType', { bubbles: true }).bubbles", "true"); |
| 26 | |
| 27 | // cancelable is passed. |
| 28 | shouldBe("new MessageEvent('eventType', { cancelable: false }).cancelable", "false"); |
| 29 | shouldBe("new MessageEvent('eventType', { cancelable: true }).cancelable", "true"); |
| 30 | |
| 31 | // data is passed. |
haraken@chromium.org | 15c182a | 2011-10-18 07:20:17 +0000 | [diff] [blame] | 32 | // FIXME(haraken): This fails because MessageEvent.data cannot handle ScriptValue. |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 33 | shouldBe("new MessageEvent('eventType', { data: test_object }).data", "test_object"); |
haraken@chromium.org | 15c182a | 2011-10-18 07:20:17 +0000 | [diff] [blame] | 34 | // FIXME(haraken): When we pass a DOM object, it crashes in DRT (it returns TypeError in non-DRT build). |
| 35 | // shouldBe("new MessageEvent('eventType', { data: document }).data", "document"); |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 36 | shouldBe("new MessageEvent('eventType', { data: undefined }).data", "undefined"); |
| 37 | shouldBe("new MessageEvent('eventType', { data: null }).data", "null"); |
| 38 | shouldBe("new MessageEvent('eventType', { data: false }).data", "false"); |
| 39 | shouldBe("new MessageEvent('eventType', { data: true }).data", "true"); |
| 40 | shouldBeEqualToString("new MessageEvent('eventType', { data: '' }).data", ""); |
| 41 | shouldBeEqualToString("new MessageEvent('eventType', { data: 'chocolate' }).data", "chocolate"); |
| 42 | shouldBe("new MessageEvent('eventType', { data: 12345 }).data", "12345"); |
| 43 | shouldBe("new MessageEvent('eventType', { data: 18446744073709551615 }).data", "18446744073709552000"); |
| 44 | shouldBe("new MessageEvent('eventType', { data: NaN }).data", "NaN"); |
| 45 | // Note that valueOf() is not called, when the left hand side is evaluated. |
| 46 | shouldBeFalse("new MessageEvent('eventType', { data: {valueOf: function () { return test_object; } } }).data == test_object"); |
| 47 | shouldBe("new MessageEvent('eventType', { get data() { return 123; } }).data", "123"); |
| 48 | shouldThrow("new MessageEvent('eventType', { get data() { throw 'MessageEvent Error'; } })"); |
| 49 | |
| 50 | // origin or lastEventId is passed. |
| 51 | ["origin", "lastEventId"].forEach(function (attr) { |
| 52 | // Strings. |
| 53 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": 'melancholy' })." + attr, "melancholy"); |
| 54 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": '' })." + attr, ""); |
| 55 | |
| 56 | // Non-strings. |
| 57 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": undefined })." + attr, "undefined"); |
| 58 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": null })." + attr, "null"); |
| 59 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": false })." + attr, "false"); |
| 60 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": true })." + attr, "true"); |
| 61 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": 12345 })." + attr, "12345"); |
| 62 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": 18446744073709551615 })." + attr, "18446744073709552000"); |
| 63 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": NaN })." + attr, "NaN"); |
| 64 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": [] })." + attr, ""); |
| 65 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": [1, 2, 3] })." + attr, "1,2,3"); |
| 66 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": {melancholy: 12345} })." + attr, "[object Object]"); |
| 67 | shouldBeEqualToString("new MessageEvent('eventType', { " + attr + ": {valueOf: function () { return 'melancholy'; } } })." + attr, "[object Object]"); |
| 68 | shouldBeEqualToString("new MessageEvent('eventType', { get " + attr + "() { return 123; } })." + attr, "123"); |
| 69 | shouldThrow("new MessageEvent('eventType', { get " + attr + "() { throw 'MessageEvent Error'; } })"); |
| 70 | }); |
| 71 | |
| 72 | // source is passed. |
| 73 | // Window objects. |
| 74 | shouldBe("new MessageEvent('eventType', { source: window }).source", "window"); |
| 75 | shouldBe("new MessageEvent('eventType', { source: this }).source", "this"); |
| 76 | |
| 77 | // Non-window objects. |
| 78 | shouldBe("new MessageEvent('eventType', { source: test_object }).source", "null"); |
| 79 | shouldBe("new MessageEvent('eventType', { source: document }).source", "null"); |
| 80 | shouldBe("new MessageEvent('eventType', { source: undefined }).source", "null"); |
| 81 | shouldBe("new MessageEvent('eventType', { source: null }).source", "null"); |
| 82 | shouldBe("new MessageEvent('eventType', { source: false }).source", "null"); |
| 83 | shouldBe("new MessageEvent('eventType', { source: true }).source", "null"); |
| 84 | shouldBe("new MessageEvent('eventType', { source: '' }).source", "null"); |
| 85 | shouldBe("new MessageEvent('eventType', { source: 'chocolate' }).source", "null"); |
| 86 | shouldBe("new MessageEvent('eventType', { source: 12345 }).source", "null"); |
| 87 | shouldBe("new MessageEvent('eventType', { source: 18446744073709551615 }).source", "null"); |
| 88 | shouldBe("new MessageEvent('eventType', { source: NaN }).source", "null"); |
| 89 | // Note that valueOf() is not called, when the left hand side is evaluated. |
| 90 | shouldBeFalse("new MessageEvent('eventType', { source: {valueOf: function () { return window; } } }).source == window"); |
| 91 | shouldBe("new MessageEvent('eventType', { get source() { return 123; } }).source", "null"); |
| 92 | shouldThrow("new MessageEvent('eventType', { get source() { throw 'MessageEvent Error'; } })"); |
| 93 | |
| 94 | // ports is passed. |
| 95 | // Valid message ports. |
| 96 | var channel = new MessageChannel(); |
| 97 | shouldBe("new MessageEvent('eventType', { ports: [channel.port1, channel.port2, channel.port2] }).ports[0]", "channel.port1"); |
| 98 | shouldBe("new MessageEvent('eventType', { ports: [channel.port1, channel.port2, channel.port2] }).ports[1]", "channel.port2"); |
| 99 | shouldBe("new MessageEvent('eventType', { ports: [channel.port1, channel.port2, channel.port2] }).ports[2]", "channel.port2"); |
| 100 | shouldBe("new MessageEvent('eventType', { ports: [] }).ports", "[]"); |
| 101 | shouldBe("new MessageEvent('eventType', { ports: undefined }).ports", "[]"); |
| 102 | shouldBe("new MessageEvent('eventType', { ports: null }).ports", "[]"); |
| 103 | |
| 104 | // Invalid message ports. |
| 105 | shouldThrow("new MessageEvent('eventType', { ports: [1, 2, 3] }).ports[2]"); |
| 106 | shouldThrow("new MessageEvent('eventType', { ports: test_object }).ports"); |
| 107 | shouldThrow("new MessageEvent('eventType', { ports: document }).ports"); |
| 108 | shouldThrow("new MessageEvent('eventType', { ports: false }).ports"); |
| 109 | shouldThrow("new MessageEvent('eventType', { ports: true }).ports"); |
| 110 | shouldThrow("new MessageEvent('eventType', { ports: '' }).ports"); |
| 111 | shouldThrow("new MessageEvent('eventType', { ports: 'chocolate' }).ports"); |
| 112 | shouldThrow("new MessageEvent('eventType', { ports: 12345 }).ports"); |
| 113 | shouldThrow("new MessageEvent('eventType', { ports: 18446744073709551615 }).ports"); |
| 114 | shouldThrow("new MessageEvent('eventType', { ports: NaN }).ports"); |
| 115 | shouldThrow("new MessageEvent('eventType', { get ports() { return 123; } }).ports"); |
| 116 | shouldThrow("new MessageEvent('eventType', { get ports() { throw 'MessageEvent Error'; } })"); |
| 117 | // Note that valueOf() is not called, when the left hand side is evaluated. |
| 118 | shouldThrow("new MessageEvent('eventType', { ports: {valueOf: function () { return [channel.port1, channel.port2, channel.port2]; } } }).ports[0]"); |
| 119 | |
| 120 | // All initializers are passed. |
| 121 | shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).bubbles", "true"); |
| 122 | shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).cancelable", "true"); |
haraken@chromium.org | 15c182a | 2011-10-18 07:20:17 +0000 | [diff] [blame] | 123 | // FIXME(haraken): This fails because MessageEvent.data cannot handle ScriptValue. |
commit-queue@webkit.org | 9a6aee2 | 2011-09-28 02:02:18 +0000 | [diff] [blame] | 124 | shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).data", "test_object"); |
| 125 | shouldBeEqualToString("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).origin", "wonderful"); |
| 126 | shouldBeEqualToString("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).lastEventId", "excellent"); |
| 127 | shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).source", "window"); |
| 128 | shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).ports[0]", "channel.port1"); |
| 129 | shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).ports[1]", "channel.port2"); |
| 130 | shouldBe("new MessageEvent('eventType', { bubbles: true, cancelable: true, data: test_object, origin: 'wonderful', lastEventId: 'excellent', source: window, ports: [channel.port1, channel.port2, channel.port2] }).ports[2]", "channel.port2"); |
| 131 | |
| 132 | var successfullyParsed = true; |
| 133 | </script> |
| 134 | <script src="../../js/resources/js-test-post.js"></script> |
| 135 | </body> |
| 136 | </html> |