diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/modules/tests/browser/browser_PageMetadata.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/modules/tests/browser/browser_PageMetadata.js')
-rw-r--r-- | toolkit/modules/tests/browser/browser_PageMetadata.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/toolkit/modules/tests/browser/browser_PageMetadata.js b/toolkit/modules/tests/browser/browser_PageMetadata.js new file mode 100644 index 000000000..ca6e18368 --- /dev/null +++ b/toolkit/modules/tests/browser/browser_PageMetadata.js @@ -0,0 +1,73 @@ +/** + * Tests PageMetadata.jsm, which extracts metadata and microdata from a + * document. + */ + +var {PageMetadata} = Cu.import("resource://gre/modules/PageMetadata.jsm", {}); + +var rootURL = "http://example.com/browser/toolkit/modules/tests/browser/"; + +function promiseDocument(fileName) { + let url = rootURL + fileName; + + return new Promise((resolve, reject) => { + let xhr = new XMLHttpRequest(); + xhr.onload = () => resolve(xhr.responseXML); + xhr.onerror = () => reject(new Error("Error loading document")); + xhr.open("GET", url); + xhr.responseType = "document"; + xhr.send(); + }); +} + +/** + * Load a simple document. + */ +add_task(function* simpleDoc() { + let fileName = "metadata_simple.html"; + info(`Loading a simple 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.url, rootURL + fileName, + "Should have expected url property"); + Assert.equal(data.title, "Test Title", + "Should have expected title property"); + 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"); +}); |