tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_meta_og_url.js (1071B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { findCandidates } = ChromeUtils.importESModule(
      7  "moz-src:///browser/components/tabnotes/CanonicalURL.sys.mjs"
      8 );
      9 
     10 /**
     11 * @param {string|undefined} [url]
     12 * @returns {Document}
     13 */
     14 function getDocument(url) {
     15  const html = `
     16 <!DOCTYPE html>
     17 <html>
     18 <head>
     19  <meta charset="utf-8">
     20  ${url ? `<meta property="og:url" content="${url}">` : ""}
     21 </head>
     22 <body>
     23 </body>
     24 </html>
     25 `;
     26  return Document.parseHTMLUnsafe(html);
     27 }
     28 
     29 add_task(async function test_meta_og_url_missing() {
     30  const doc = getDocument();
     31 
     32  const candidates = findCandidates(doc);
     33 
     34  Assert.equal(
     35    candidates.opengraph,
     36    undefined,
     37    `meta[property="og:url"] should not be found`
     38  );
     39 });
     40 
     41 add_task(async function test_meta_og_url_present() {
     42  const doc = getDocument("https://www.example.com");
     43 
     44  const candidates = findCandidates(doc);
     45 
     46  Assert.equal(
     47    candidates.opengraph,
     48    "https://www.example.com",
     49    `meta[property="og:url"] should be found`
     50  );
     51 });