Bug 1523562 [wpt PR 15014] - Add some tests for named properties on Storage., a=testonly

Automatic update from web-platform-tests
Add some tests for named properties on Storage.

--
fixup! Add some tests for named properties on Storage.

--
Add some tests for named properties on Storage. (#15014)

--

wpt-commits: 07cf5c1e4289b504c72b86cbe487d35fa5d2395c, 66e29f00f5ac4b42175342c15927b9efaf4dc19f, 70cc8f087f69a681dfe58aa75dbdab466419b3dd
wpt-pr: 15014
This commit is contained in:
Ms2ger 2019-02-01 11:39:27 +00:00 коммит произвёл James Graham
Родитель dc77afe822
Коммит fa087eb719
2 изменённых файлов: 159 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,57 @@
["localStorage", "sessionStorage"].forEach(function(name) {
[9, "x"].forEach(function(key) {
test(function() {
var desc = {
value: "value",
};
var storage = window[name];
storage.clear();
assert_equals(storage[key], undefined);
assert_equals(storage.getItem(key), null);
assert_equals(Object.defineProperty(storage, key, desc), storage);
assert_equals(storage[key], "value");
assert_equals(storage.getItem(key), "value");
}, "Defining data property for key " + key + " on " + name);
test(function() {
var desc1 = {
value: "value",
};
var desc2 = {
value: "new value",
};
var storage = window[name];
storage.clear();
assert_equals(storage[key], undefined);
assert_equals(storage.getItem(key), null);
assert_equals(Object.defineProperty(storage, key, desc1), storage);
assert_equals(storage[key], "value");
assert_equals(storage.getItem(key), "value");
assert_equals(Object.defineProperty(storage, key, desc2), storage);
assert_equals(storage[key], "new value");
assert_equals(storage.getItem(key), "new value");
}, "Defining data property for key " + key + " on " + name + " twice");
test(function() {
var desc = {
value: {
toString: function() { return "value"; }
},
};
var storage = window[name];
storage.clear();
assert_equals(storage[key], undefined);
assert_equals(storage.getItem(key), null);
assert_equals(Object.defineProperty(storage, key, desc), storage);
assert_equals(storage[key], "value");
assert_equals(storage.getItem(key), "value");
}, "Defining data property with toString for key " + key + " on " + name);
});
});

Просмотреть файл

@ -0,0 +1,102 @@
["localStorage", "sessionStorage"].forEach(function(name) {
[9, "x"].forEach(function(key) {
test(function() {
var value = "value";
var storage = window[name];
storage.clear();
assert_equals(storage[key], undefined);
assert_equals(storage.getItem(key), null);
assert_equals(storage[key] = value, value);
assert_equals(storage[key], "value");
assert_equals(storage.getItem(key), "value");
}, "Setting property for key " + key + " on " + name);
test(function() {
var value = {
toString: function() { return "value"; }
};
var storage = window[name];
storage.clear();
assert_equals(storage[key], undefined);
assert_equals(storage.getItem(key), null);
assert_equals(storage[key] = value, value);
assert_equals(storage[key], "value");
assert_equals(storage.getItem(key), "value");
}, "Setting property with toString for key " + key + " on " + name);
test(function() {
Storage.prototype[key] = "proto";
this.add_cleanup(function() { delete Storage.prototype[key]; });
var value = "value";
var storage = window[name];
storage.clear();
assert_equals(storage[key], "proto");
assert_equals(storage.getItem(key), null);
assert_equals(storage[key] = value, value);
// Hidden because no [OverrideBuiltins].
assert_equals(storage[key], "proto");
assert_equals(Object.getOwnPropertyDescriptor(storage, key), undefined);
assert_equals(storage.getItem(key), "value");
}, "Setting property for key " + key + " on " + name + " with data property on prototype");
test(function() {
Storage.prototype[key] = "proto";
this.add_cleanup(function() { delete Storage.prototype[key]; });
var value = "value";
var storage = window[name];
storage.clear();
storage.setItem(key, "existing");
// Hidden because no [OverrideBuiltins].
assert_equals(storage[key], "proto");
assert_equals(Object.getOwnPropertyDescriptor(storage, key), undefined);
assert_equals(storage.getItem(key), "existing");
assert_equals(storage[key] = value, value);
assert_equals(storage[key], "proto");
assert_equals(Object.getOwnPropertyDescriptor(storage, key), undefined);
assert_equals(storage.getItem(key), "value");
}, "Setting property for key " + key + " on " + name + " with data property on prototype and existing item");
test(function() {
var calledSetter = [];
Object.defineProperty(Storage.prototype, key, {
"get": function() { return "proto getter"; },
"set": function(v) { calledSetter.push(v); },
configurable: true,
});
this.add_cleanup(function() { delete Storage.prototype[key]; });
var value = "value";
var storage = window[name];
storage.clear();
assert_equals(storage[key], "proto getter");
assert_equals(storage.getItem(key), null);
assert_equals(storage[key] = value, value);
// Property is hidden because no [OverrideBuiltins].
if (typeof key === "number") {
// P is an array index: call through to OrdinarySetWithOwnDescriptor()
assert_array_equals(calledSetter, [value]);
assert_equals(storage[key], "proto getter");
assert_equals(storage.getItem(key), null);
} else {
// P is not an array index: early return in [[Set]] step 2.
// https://github.com/heycam/webidl/issues/630
assert_equals(storage[key], "proto getter");
assert_equals(Object.getOwnPropertyDescriptor(storage, key), undefined);
assert_equals(storage.getItem(key), "value");
}
}, "Setting property for key " + key + " on " + name + " with accessor property on prototype");
});
});