Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / constructors / related-event-constructor.html
blob726d66d74d5f162e05b4bf0692c4aedd124f6ec2
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 RelatedEvent DOM class.");
11 var testObject = {nyannyan: 123};
12 var testDiv = document.createElement("div");
14 // No initializer is passed.
15 shouldBeFalse("new RelatedEvent('eventType').bubbles");
16 shouldBeFalse("new RelatedEvent('eventType').cancelable");
17 shouldBeNull("new RelatedEvent('eventType').relatedTarget");
19 // bubbles is passed.
20 shouldBeFalse("new RelatedEvent('eventType', { bubbles: false }).bubbles");
21 shouldBeTrue("new RelatedEvent('eventType', { bubbles: true }).bubbles");
23 // cancelable is passed.
24 shouldBeFalse("new RelatedEvent('eventType', { cancelable: false }).cancelable");
25 shouldBeTrue("new RelatedEvent('eventType', { cancelable: true }).cancelable");
27 // relatedTarget is passed.
28 // Valid objects.
29 shouldBe("new RelatedEvent('eventType', { relatedTarget: testDiv }).relatedTarget", "testDiv");
30 shouldBe("new RelatedEvent('eventType', { relatedTarget: document }).relatedTarget", "document");
31 shouldBe("new RelatedEvent('eventType', { relatedTarget: window }).relatedTarget", "window");
33 // Invalid objects.
34 shouldThrow("new RelatedEvent('eventType', { relatedTarget: testObject }).relatedTarget");
35 shouldBeNull("new RelatedEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
36 shouldBeNull("new RelatedEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
37 shouldThrow("new RelatedEvent('eventType', { relatedTarget: false }).relatedTarget");
38 shouldThrow("new RelatedEvent('eventType', { relatedTarget: true }).relatedTarget");
39 shouldThrow("new RelatedEvent('eventType', { relatedTarget: '' }).relatedTarget");
40 shouldThrow("new RelatedEvent('eventType', { relatedTarget: 'chocolate' }).relatedTarget");
41 shouldThrow("new RelatedEvent('eventType', { relatedTarget: 12345 }).relatedTarget");
42 shouldThrow("new RelatedEvent('eventType', { relatedTarget: 18446744073709551615 }).relatedTarget");
43 shouldThrow("new RelatedEvent('eventType', { relatedTarget: NaN }).relatedTarget");
44 // Note that valueOf() is not called, when the left hand side is evaluated.
45 shouldThrow("new RelatedEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } }).relatedTarget == testDiv");
46 shouldBeTrue("new RelatedEvent('eventType', { get relatedTarget() { return testDiv; } }).relatedTarget == testDiv");
47 shouldThrow("new RelatedEvent('eventType', { get relatedTarget() { return 123; } }).relatedTarget");
48 shouldThrow("new RelatedEvent('eventType', { get relatedTarget() { throw 'RelatedEvent Error'; } })");
50 // All initializers are passed.
51 shouldBeTrue("new RelatedEvent('eventType', { bubbles: true, cancelable: true, relatedTarget: testDiv }).bubbles", "true");
52 shouldBeTrue("new RelatedEvent('eventType', { bubbles: true, cancelable: true, relatedTarget: testDiv }).cancelable", "true");
53 shouldBe("new RelatedEvent('eventType', { bubbles: true, cancelable: true, relatedTarget: testDiv }).relatedTarget", "testDiv");
54 </script>
55 </body>
56 </html>