blob: 848a69f18b1c22ab53eff0c1b39d95a397fd877c [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("This tests the constructor for the StorageEvent DOM class.");
// No initializer is passed.
shouldBe("new StorageEvent('eventType').bubbles", "false");
shouldBe("new StorageEvent('eventType').cancelable", "false");
// Note: key is nullable.
shouldBeNull("new StorageEvent('eventType').key");
// Note: oldValue is nullable.
shouldBeNull("new StorageEvent('eventType').oldValue");
// Note: newValue is nullable.
shouldBeNull("new StorageEvent('eventType').newValue");
shouldBeEqualToString("new StorageEvent('eventType').url", "");
shouldBeNull("new StorageEvent('eventType').storageArea");
// bubbles is passed.
shouldBe("new StorageEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new StorageEvent('eventType', { bubbles: true }).bubbles", "true");
// cancelable is passed.
shouldBe("new StorageEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new StorageEvent('eventType', { cancelable: true }).cancelable", "true");
// key, oldValue, newValue and url is passed.
["key", "oldValue", "newValue", "url"].forEach(function(attr) {
// Strings.
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": 'abcde' })." + attr, "abcde");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": '' })." + attr, "");
// Non-strings.
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": false })." + attr, "false");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": true })." + attr, "true");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": 12345 })." + attr, "12345");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": 18446744073709551615 })." + attr, "18446744073709552000");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": NaN })." + attr, "NaN");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": [] })." + attr, "");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": [1, 2, 3] })." + attr, "1,2,3");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": {abcde: 12345} })." + attr, "[object Object]");
shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": {valueOf: function () { return 'abcde'; } } })." + attr, "[object Object]");
});
// key, oldValue and newValue are nullable strings.
["key", "oldValue", "newValue"].forEach(function(attr) {
shouldBeNull("new StorageEvent('eventType', { " + attr + ": undefined })." + attr);
shouldBeNull("new StorageEvent('eventType', { " + attr + ": null })." + attr);
});
// url is non-nullable string.
shouldBeEqualToString("new StorageEvent('eventType', { url: undefined }).url", "");
shouldBeEqualToString("new StorageEvent('eventType', { url: null }).url", "null");
// storageArea is passed.
// Storage objects.
shouldBe("new StorageEvent('eventType', { storageArea: localStorage }).storageArea", "localStorage");
shouldBe("new StorageEvent('eventType', { storageArea: sessionStorage }).storageArea", "sessionStorage");
// Non-Storage objects.
var test_object = {abc: 123};
shouldThrow("new StorageEvent('eventType', { storageArea: test_object }).storageArea");
shouldThrow("new StorageEvent('eventType', { storageArea: window }).storageArea");
shouldThrow("new StorageEvent('eventType', { storageArea: document }).storageArea");
shouldBe("new StorageEvent('eventType', { storageArea: undefined }).storageArea", "null");
shouldBe("new StorageEvent('eventType', { storageArea: null }).storageArea", "null");
shouldThrow("new StorageEvent('eventType', { storageArea: false }).storageArea");
shouldThrow("new StorageEvent('eventType', { storageArea: true }).storageArea");
shouldThrow("new StorageEvent('eventType', { storageArea: '' }).storageArea");
shouldThrow("new StorageEvent('eventType', { storageArea: 'chocolate' }).storageArea");
shouldThrow("new StorageEvent('eventType', { storageArea: 12345 }).storageArea");
shouldThrow("new StorageEvent('eventType', { storageArea: 18446744073709551615 }).storageArea");
shouldThrow("new StorageEvent('eventType', { storageArea: NaN }).storageArea");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrow("new StorageEvent('eventType', { storageArea: {valueOf: function () { return window; } } }).storageArea == window");
shouldBe("new StorageEvent('eventType', { get storageArea() { return localStorage; } }).storageArea", "localStorage");
shouldThrow("new StorageEvent('eventType', { get storageArea() { return 123; } }).storageArea");
shouldThrow("new StorageEvent('eventType', { get storageArea() { throw 'StorageEvent Error'; } })");
// All initializers are passed.
shouldBe("new StorageEvent('eventType', { bubbles: true, cancelable: false, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).bubbles", "true");
shouldBe("new StorageEvent('eventType', { bubbles: false, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).cancelable", "true");
shouldBeEqualToString("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).key", "abc");
shouldBeEqualToString("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).oldValue", "def");
shouldBeEqualToString("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).newValue", "ghi");
shouldBeEqualToString("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).url", "jkl");
shouldBe("new StorageEvent('eventType', { bubbles: true, cancelable: true, key: 'abc', oldValue: 'def', newValue: 'ghi', url: 'jkl', storageArea: localStorage }).storageArea", "localStorage");
</script>
</body>
</html>