Bug 1174132 - When obtaining page metadata, always prefer the page title over the opengraph title. r=mixedpuppy

This commit is contained in:
Mark Banner 2015-08-27 17:13:06 +01:00
Родитель 0636475293
Коммит 8ab64f8f73
4 изменённых файлов: 56 добавлений и 1 удалений

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

@ -182,7 +182,11 @@ this.PageMetadata = {
switch (key) {
case "title":
case "og:title": {
result.title = value;
// Only set the title if one hasn't already been obtained (e.g. from the
// document title element).
if (!result.title) {
result.title = value;
}
break;
}

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

@ -41,3 +41,33 @@ add_task(function* simpleDoc() {
Assert.equal(data.description, "A very simple test page",
"Should have expected title property");
});
add_task(function* titlesDoc() {
let fileName = "metadata_titles.html";
info(`Loading titles page, ${fileName}`);
let doc = yield promiseDocument(fileName);
Assert.notEqual(doc, null,
"Should have a document to analyse");
let data = PageMetadata.getData(doc);
Assert.notEqual(data, null,
"Should have non-null result");
Assert.equal(data.title, "Test Titles",
"Should use the page title, not the open graph title");
});
add_task(function* titlesFallbackDoc() {
let fileName = "metadata_titles_fallback.html";
info(`Loading titles page, ${fileName}`);
let doc = yield promiseDocument(fileName);
Assert.notEqual(doc, null,
"Should have a document to analyse");
let data = PageMetadata.getData(doc);
Assert.notEqual(data, null,
"Should have non-null result");
Assert.equal(data.title, "Title",
"Should use the open graph title");
});

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

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Test Titles</title>
<meta property="description" content="A very simple test page" />
<meta property="og:title" content="Title" />
</head>
<body>
Llama.
</body>
</html>

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

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta property="description" content="A very simple test page" />
<meta property="og:title" content="Title" />
</head>
<body>
Llama.
</body>
</html>