blob: be8be63fc89c4fc66059f12041a47f7046aeaf71 [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 FocusEvent DOM class.");
var testObject = {nyannyan: 123};
var testDiv = document.createElement("div");
var xhr = new XMLHttpRequest;
// No initializer is passed.
shouldBe("new FocusEvent('eventType').bubbles", "false");
shouldBe("new FocusEvent('eventType').cancelable", "false");
shouldBe("new FocusEvent('eventType').view", "null");
shouldBe("new FocusEvent('eventType').detail", "0");
shouldBe("new FocusEvent('eventType').relatedTarget", "null");
// bubbles is passed.
shouldBe("new FocusEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new FocusEvent('eventType', { bubbles: true }).bubbles", "true");
// cancelable is passed.
shouldBe("new FocusEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new FocusEvent('eventType', { cancelable: true }).cancelable", "true");
// view is passed.
// Window objects.
shouldBe("new FocusEvent('eventType', { view: window }).view", "window");
shouldBe("new FocusEvent('eventType', { view: this }).view", "this");
// Non-window objects.
shouldThrowErrorName("new FocusEvent('eventType', { view: testObject }).view", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { view: document }).view", "TypeError");
shouldBeNull("new FocusEvent('eventType', { view: undefined }).view");
shouldBeNull("new FocusEvent('eventType', { view: null }).view");
shouldThrowErrorName("new FocusEvent('eventType', { view: false }).view", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { view: true }).view", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { view: '' }).view", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { view: 'chocolate' }).view", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { view: 12345 }).view", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { view: 18446744073709551615 }).view", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { view: NaN }).view", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new FocusEvent('eventType', { view: {valueOf: function () { return window; } } }).view", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { get view() { return 123; } }).view", "TypeError");
shouldThrow("new FocusEvent('eventType', { get view() { throw 'FocusEvent Error'; } })");
// relatedTarget is passed.
// Valid objects.
shouldBe("new FocusEvent('eventType', { relatedTarget: testDiv }).relatedTarget", "testDiv");
shouldBe("new FocusEvent('eventType', { relatedTarget: document }).relatedTarget", "document");
shouldBe("new FocusEvent('eventType', { relatedTarget: xhr }).relatedTarget", "xhr");
shouldBe("new FocusEvent('eventType', { relatedTarget: window }).relatedTarget", "window");
// Invalid objects.
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: testObject })", "TypeError");
shouldBe("new FocusEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: false })", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: true })", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: '' })", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: 'chocolate' })", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: 12345 })", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: 18446744073709551615 })", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: NaN })", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new FocusEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } })", "TypeError");
shouldThrowErrorName("new FocusEvent('eventType', { get relatedTarget() { return 123; } })", "TypeError");
shouldThrow("new FocusEvent('eventType', { get relatedTarget() { throw 'FocusEvent Error'; } })");
// All initializers are passed.
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).bubbles", "true");
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).cancelable", "true");
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).view", "window");
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).detail", "111");
shouldBe("new FocusEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, relatedTarget: testDiv }).relatedTarget", "testDiv");
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>