forked from mirrors/gecko-dev
		
	 918ed6c474
			
		
	
	
		918ed6c474
		
	
	
	
	
		
			
			This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm
MozReview-Commit-ID: 1Nc3XDu0wGl
--HG--
extra : source : 12fc4dee861c812fd2bd032c63ef17af61800c70
extra : intermediate-source : 34c999fa006bffe8705cf50c54708aa21a962e62
extra : histedit_source : b2be2c5e5d226e6c347312456a6ae339c1e634b0
		
	
			
		
			
				
	
	
		
			73 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /**
 | |
|  * Tests PageMetadata.jsm, which extracts metadata and microdata from a
 | |
|  * document.
 | |
|  */
 | |
| 
 | |
| var {PageMetadata} = ChromeUtils.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(async function simpleDoc() {
 | |
|   let fileName = "metadata_simple.html";
 | |
|   info(`Loading a simple page, ${fileName}`);
 | |
| 
 | |
|   let doc = await 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(async function titlesDoc() {
 | |
|   let fileName = "metadata_titles.html";
 | |
|   info(`Loading titles page, ${fileName}`);
 | |
| 
 | |
|   let doc = await 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(async function titlesFallbackDoc() {
 | |
|   let fileName = "metadata_titles_fallback.html";
 | |
|   info(`Loading titles page, ${fileName}`);
 | |
| 
 | |
|   let doc = await 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");
 | |
| });
 |