mirror of
https://github.com/servo/servo.git
synced 2025-08-22 13:55:34 +01:00
Update web-platform-tests to revision 3137d1d2d7757366a69f8a449b458b5057e0e81e
This commit is contained in:
parent
81ca858678
commit
d6ba94ca28
2339 changed files with 89274 additions and 9328 deletions
66
tests/wpt/web-platform-tests/clear-site-data/navigation.html
Normal file
66
tests/wpt/web-platform-tests/clear-site-data/navigation.html
Normal file
|
@ -0,0 +1,66 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="support/test_utils.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script>
|
||||
/** Ensures that all datatypes are nonempty. */
|
||||
function populateDatatypes() {
|
||||
return Promise.all(TestUtils.DATATYPES.map(function(datatype) {
|
||||
return datatype.add().then(datatype.isEmpty().then(function(isEmpty) {
|
||||
assert_false(
|
||||
isEmpty,
|
||||
datatype.name + " has to be nonempty before the test starts.");
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array.<Array.<Datatype>> combination A combination of datatypes.
|
||||
* @param Dict.<string, boolean> report A map between a datatype name and
|
||||
* whether it is empty.
|
||||
* @return boolean Whether all datatypes are empty if and only if they are
|
||||
* included in the |combination|.
|
||||
*/
|
||||
function verifyDatatypes(combination, report) {
|
||||
TestUtils.DATATYPES.forEach(function(datatype) {
|
||||
if (combination.indexOf(datatype) != -1) {
|
||||
assert_true(
|
||||
report[datatype.name],
|
||||
datatype.name + " should have been cleared.");
|
||||
} else {
|
||||
assert_false(
|
||||
report[datatype.name],
|
||||
datatype.name + " should NOT have been cleared.");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
TestUtils.COMBINATIONS.forEach(function(combination) {
|
||||
var test_name =
|
||||
"Clear datatypes on navigation: " +
|
||||
combination.map(function(e) { return e.name; }).join(", ");
|
||||
|
||||
promise_test(function(test) {
|
||||
return populateDatatypes()
|
||||
.then(function() {
|
||||
// Navigate to a resource with a Clear-Site-Data header in an
|
||||
// iframe, then verify that the correct types have been deleted.
|
||||
return new Promise(function(resolve, reject) {
|
||||
window.addEventListener("message", resolve);
|
||||
var iframe = document.createElement("iframe");
|
||||
iframe.src = TestUtils.getClearSiteDataUrl(combination);
|
||||
document.body.appendChild(iframe);
|
||||
}).then(function(messageEvent) {
|
||||
verifyDatatypes(combination, messageEvent.data);
|
||||
});
|
||||
});
|
||||
}, test_name);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,40 @@
|
|||
import json
|
||||
|
||||
RESPONSE = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Clear-Site-Data</title>
|
||||
<script src="test_utils.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
/**
|
||||
* A map between a datatype name and whether it is empty.
|
||||
* @property Object.<string, boolean>
|
||||
*/
|
||||
var report = {};
|
||||
|
||||
Promise.all(TestUtils.DATATYPES.map(function(datatype) {
|
||||
return datatype.isEmpty().then(function(isEmpty) {
|
||||
report[datatype.name] = isEmpty;
|
||||
});
|
||||
})).then(function() {
|
||||
window.top.postMessage(report, "*");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
# A support server that receives a list of datatypes in the GET query
|
||||
# and returns a Clear-Site-Data header with those datatypes. The content
|
||||
# of the response is a html site using postMessage to report the status
|
||||
# of the datatypes, so that if used in an iframe, it can inform the
|
||||
# embedder whether the data deletion succeeded.
|
||||
def main(request, response):
|
||||
types = [key for key in request.GET.keys()]
|
||||
header = json.dumps({ "types": types })
|
||||
return ([("Clear-Site-Data", header),
|
||||
("Content-Type", "text/html")],
|
||||
RESPONSE)
|
|
@ -0,0 +1,89 @@
|
|||
var TestUtils = (function() {
|
||||
function randomString() {
|
||||
var result = "";
|
||||
for (var i = 0; i < 5; i++)
|
||||
result += String.fromCharCode(97 + Math.floor(Math.random() * 26));
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Representation of one datatype.
|
||||
* @typedef Datatype
|
||||
* @type{object}
|
||||
* @property{string} name Name of the datatype.
|
||||
* @method{function():Void} add A function to add an instance of the datatype.
|
||||
* @method{function():boolean} isEmpty A function that tests whether
|
||||
* the datatype's storage backend is empty.
|
||||
*/
|
||||
var Datatype;
|
||||
|
||||
var TestUtils = {};
|
||||
|
||||
/**
|
||||
* All datatypes supported by Clear-Site-Data.
|
||||
* @param{Array.<Datatype>}
|
||||
*/
|
||||
TestUtils.DATATYPES = [
|
||||
{
|
||||
"name": "cookies",
|
||||
"add": function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
document.cookie = randomString() + "=" + randomString();
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
"isEmpty": function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
resolve(!document.cookie);
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "storage",
|
||||
"add": function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
localStorage.setItem(randomString(), randomString());
|
||||
resolve();
|
||||
});
|
||||
},
|
||||
"isEmpty": function() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
resolve(!localStorage.length);
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* All possible combinations of datatypes.
|
||||
* @property {Array.<Array.<Datatype>>}
|
||||
*/
|
||||
TestUtils.COMBINATIONS = (function() {
|
||||
var combinations = [];
|
||||
for (var mask = 0; mask < (1 << TestUtils.DATATYPES.length); mask++) {
|
||||
var combination = [];
|
||||
|
||||
for (var datatype = 0;
|
||||
datatype < TestUtils.DATATYPES.length; datatype++) {
|
||||
if (mask & (1 << datatype))
|
||||
combination.push(TestUtils.DATATYPES[datatype]);
|
||||
}
|
||||
|
||||
combinations.push(combination);
|
||||
}
|
||||
return combinations;
|
||||
})();
|
||||
|
||||
/**
|
||||
* Get the support server URL that returns a Clear-Site-Data header
|
||||
* to clear |datatypes|.
|
||||
* @param{Array.<Datatype>} datatypes The list of datatypes to be deleted.
|
||||
* @return string The URL to be queried.
|
||||
*/
|
||||
TestUtils.getClearSiteDataUrl = function(datatypes) {
|
||||
names = datatypes.map(function(e) { return e.name });
|
||||
return "support/echo-clear-site-data.py?" + names.join("&");
|
||||
}
|
||||
|
||||
return TestUtils;
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue