blob: e4d77b2a2dfe176c1db2d40eebc1cefd370d235f [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("This tests the constructor for the CompositionEvent DOM class.");
var testObject = {nyannyan: 123};
// No initializer is passed.
shouldBe("new CompositionEvent('eventType').bubbles", "false");
shouldBe("new CompositionEvent('eventType').cancelable", "false");
shouldBe("new CompositionEvent('eventType').view", "null");
shouldBe("new CompositionEvent('eventType').detail", "0");
shouldBeEqualToString("new CompositionEvent('eventType').data", "");
// bubbles is passed.
shouldBe("new CompositionEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new CompositionEvent('eventType', { bubbles: true }).bubbles", "true");
// cancelable is passed.
shouldBe("new CompositionEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new CompositionEvent('eventType', { cancelable: true }).cancelable", "true");
// view is passed.
// Window objects.
shouldBe("new CompositionEvent('eventType', { view: window }).view", "window");
shouldBe("new CompositionEvent('eventType', { view: this }).view", "this");
// Non-window objects.
shouldThrowErrorName("new CompositionEvent('eventType', { view: testObject }).view", "TypeError");
shouldThrowErrorName("new CompositionEvent('eventType', { view: document }).view", "TypeError");
shouldBeNull("new CompositionEvent('eventType', { view: undefined }).view");
shouldBeNull("new CompositionEvent('eventType', { view: null }).view");
shouldThrowErrorName("new CompositionEvent('eventType', { view: false }).view", "TypeError");
shouldThrowErrorName("new CompositionEvent('eventType', { view: true }).view", "TypeError");
shouldThrowErrorName("new CompositionEvent('eventType', { view: '' }).view", "TypeError");
shouldThrowErrorName("new CompositionEvent('eventType', { view: 'chocolate' }).view", "TypeError");
shouldThrowErrorName("new CompositionEvent('eventType', { view: 12345 }).view", "TypeError");
shouldThrowErrorName("new CompositionEvent('eventType', { view: 18446744073709551615 }).view", "TypeError");
shouldThrowErrorName("new CompositionEvent('eventType', { view: NaN }).view", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new CompositionEvent('eventType', { view: {valueOf: function () { return window; } } }).view", "TypeError");
shouldThrowErrorName("new CompositionEvent('eventType', { get view() { return 123; } }).view", "TypeError");
shouldThrow("new CompositionEvent('eventType', { get view() { throw 'CompositionEvent Error'; } })");
// data is passed.
// Strings.
shouldBeEqualToString("new CompositionEvent('eventType', { data: 'koakuma' }).data", "koakuma");
shouldBeEqualToString("new CompositionEvent('eventType', { data: '' }).data", "");
// Non-strings.
shouldBeEqualToString("new CompositionEvent('eventType', { data: undefined }).data", "");
shouldBeEqualToString("new CompositionEvent('eventType', { data: null }).data", "null");
shouldBeEqualToString("new CompositionEvent('eventType', { data: false }).data", "false");
shouldBeEqualToString("new CompositionEvent('eventType', { data: true }).data", "true");
shouldBeEqualToString("new CompositionEvent('eventType', { data: 12345 }).data", "12345");
shouldBeEqualToString("new CompositionEvent('eventType', { data: 18446744073709551615 }).data", "18446744073709552000");
shouldBeEqualToString("new CompositionEvent('eventType', { data: NaN }).data", "NaN");
shouldBeEqualToString("new CompositionEvent('eventType', { data: [] }).data", "");
shouldBeEqualToString("new CompositionEvent('eventType', { data: [1, 2, 3] }).data", "1,2,3");
shouldBeEqualToString("new CompositionEvent('eventType', { data: {koakuma: 12345} }).data", "[object Object]");
shouldBeEqualToString("new CompositionEvent('eventType', { data: {valueOf: function () { return 'koakuma'; } } }).data", "[object Object]");
// All initializers are passed.
shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).bubbles", "true");
shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).cancelable", "true");
shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).view", "window");
shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).detail", "111");
shouldBeEqualToString("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).data", "koakuma");
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>