blob: de3365d51746a992b45dae0f8934b6d9b0cfd28b [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.
shouldBe("new FocusEvent('eventType', { view: testObject }).view", "null");
shouldBe("new FocusEvent('eventType', { view: document }).view", "null");
shouldBe("new FocusEvent('eventType', { view: undefined }).view", "null");
shouldBe("new FocusEvent('eventType', { view: null }).view", "null");
shouldBe("new FocusEvent('eventType', { view: false }).view", "null");
shouldBe("new FocusEvent('eventType', { view: true }).view", "null");
shouldBe("new FocusEvent('eventType', { view: '' }).view", "null");
shouldBe("new FocusEvent('eventType', { view: 'chocolate' }).view", "null");
shouldBe("new FocusEvent('eventType', { view: 12345 }).view", "null");
shouldBe("new FocusEvent('eventType', { view: 18446744073709551615 }).view", "null");
shouldBe("new FocusEvent('eventType', { view: NaN }).view", "null");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldBeFalse("new FocusEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window");
shouldBe("new FocusEvent('eventType', { get view() { return 123; } }).view", "null");
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.
shouldBe("new FocusEvent('eventType', { relatedTarget: testObject }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: undefined }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: null }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: false }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: true }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: '' }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: 'chocolate' }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: 12345 }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: 18446744073709551615 }).relatedTarget", "null");
shouldBe("new FocusEvent('eventType', { relatedTarget: NaN }).relatedTarget", "null");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldBeFalse("new FocusEvent('eventType', { relatedTarget: {valueOf: function () { return testDiv; } } }).relatedTarget == testDiv");
shouldBe("new FocusEvent('eventType', { get relatedTarget() { return 123; } }).relatedTarget", "null");
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>