<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.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");
shouldBe("new StorageEvent('eventType').key", "null");
// Note: oldValue is nullable.
shouldBe("new StorageEvent('eventType').oldValue", "null");
// Note: newValue is nullable.
shouldBe("new StorageEvent('eventType').newValue", "null");
shouldBeEqualToString("new StorageEvent('eventType').url", "");
shouldBe("new StorageEvent('eventType').storageArea", "null");

// 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.
    if (attr == "key" || attr == "oldValue" || attr == "newValue") {
        // Those members are nullable.
        shouldBe("new StorageEvent('eventType', { " + attr + ": undefined })." + attr, "null");
        shouldBe("new StorageEvent('eventType', { " + attr + ": null })." + attr, "null");
    } else {
        shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": undefined })." + attr, "");
        shouldBeEqualToString("new StorageEvent('eventType', { " + attr + ": null })." + attr, "null");
    }
    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]");
});

// 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};
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: test_object })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: window })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: document })", "TypeError");
shouldBe("new StorageEvent('eventType', { storageArea: undefined }).storageArea", "null");
shouldBe("new StorageEvent('eventType', { storageArea: null }).storageArea", "null");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: false })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: true })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: '' })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: 'chocolate' })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: 12345 })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: 18446744073709551615 })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: NaN })", "TypeError");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrowErrorName("new StorageEvent('eventType', { storageArea: {valueOf: function () { return window; } } })", "TypeError");
shouldThrowErrorName("new StorageEvent('eventType', { get storageArea() { return 123; } }).storageArea", "TypeError");
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>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
