Bug 1467745 [wpt PR 11403] - [testharness.js] Get title from the filename if not given, a=testonly

Automatic update from web-platform-tests[testharness.js] Get title from the filename or a META comment if not given (#11403)

--

wpt-commits: f777ec99a11d0d0522e691a8dab93c70d70941f3
wpt-pr: 11403
This commit is contained in:
Simon Pieters 2018-07-06 21:53:12 +00:00 коммит произвёл James Graham
Родитель 94761ffc6c
Коммит 63017bb760
5 изменённых файлов: 56 добавлений и 6 удалений

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

@ -352715,6 +352715,20 @@
{}
]
],
"infrastructure/server/title.any.js": [
[
"/infrastructure/server/title.any.html",
{}
],
[
"/infrastructure/server/title.any.sharedworker.html",
{}
],
[
"/infrastructure/server/title.any.worker.html",
{}
]
],
"infrastructure/server/wpt-server-http.sub.html": [
[
"/infrastructure/server/wpt-server-http.sub.html",
@ -591864,6 +591878,10 @@
"6f246bdc6d67a92a6518870542c20d2f8b2b5f5d",
"testharness"
],
"infrastructure/server/title.any.js": [
"d1220af2e8cc4fab720497311064666393eea7c8",
"testharness"
],
"infrastructure/server/wpt-server-http.sub.html": [
"2a400478de23a6aecf31bdc08b187784c36be629",
"testharness"

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

@ -0,0 +1,13 @@
// META: global=window,dedicatedworker,sharedworker
// META: title=foobar
test(t => {
if (GLOBAL.isWindow()) {
assert_equals(document.title, 'foobar');
assert_false('META_TITLE' in self);
} else {
assert_equals(META_TITLE, 'foobar');
}
assert_equals(t.name, 'foobar');
});
done();

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

@ -50,7 +50,7 @@ test(function(t) {
},
{
"status_string": "FAIL",
"name": "Untitled",
"name": "worker-error",
"properties": {},
"message": "Error: This failure is expected."
},

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

@ -213,12 +213,9 @@ policies and contribution forms [3].
}
WindowTestEnvironment.prototype.next_default_test_name = function() {
//Don't use document.title to work around an Opera bug in XHTML documents
var title = document.getElementsByTagName("title")[0];
var prefix = (title && title.firstChild && title.firstChild.data) || "Untitled";
var suffix = this.name_counter > 0 ? " " + this.name_counter : "";
this.name_counter++;
return prefix + suffix;
return get_title() + suffix;
};
WindowTestEnvironment.prototype.on_new_harness_properties = function(properties) {
@ -288,7 +285,7 @@ policies and contribution forms [3].
WorkerTestEnvironment.prototype.next_default_test_name = function() {
var suffix = this.name_counter > 0 ? " " + this.name_counter : "";
this.name_counter++;
return "Untitled" + suffix;
return get_title() + suffix;
};
WorkerTestEnvironment.prototype.on_new_harness_properties = function() {};
@ -2917,6 +2914,25 @@ policies and contribution forms [3].
return undefined;
}
/** Returns the <title> or filename or "Untitled" */
function get_title()
{
if ('document' in global_scope) {
//Don't use document.title to work around an Opera bug in XHTML documents
var title = document.getElementsByTagName("title")[0];
if (title && title.firstChild && title.firstChild.data) {
return title.firstChild.data;
}
}
if ('META_TITLE' in global_scope && META_TITLE) {
return META_TITLE;
}
if ('location' in global_scope) {
return location.pathname.substring(location.pathname.lastIndexOf('/') + 1, location.pathname.indexOf('.'));
}
return "Untitled";
}
function supports_post_message(w)
{
var supports;

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

@ -289,6 +289,9 @@ done();
if key == b"script":
attribute = value.decode('utf-8').replace("\\", "\\\\").replace('"', '\\"')
return 'importScripts("%s")' % attribute
if key == b"title":
value = value.decode('utf-8').replace("\\", "\\\\").replace('"', '\\"')
return 'self.META_TITLE = "%s";' % value
return None