tor-browser

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

test_schemaorg.js (5960B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /**
      6 * Tests that the page data service can parse schema.org metadata into PageData.
      7 */
      8 
      9 add_task(async function test_single_product_microdata() {
     10  await verifyPageData(
     11    `
     12      <!DOCTYPE html>
     13      <html>
     14      <head>
     15      <title>Product Info 1</title>
     16      </head>
     17      <body>
     18        <div itemscope itemtype="https://schema.org/Organization">
     19          <div itemprop="employee" itemscope itemtype="https://schema.org/Person">
     20            <span itemprop="name">Mr. Nested Name</span>
     21          </div>
     22 
     23          <span itemprop="name">Mozilla</span>
     24        </div>
     25 
     26        <div itemscope itemtype="https://schema.org/Product">
     27          <img itemprop="image" src="bon-echo-microwave-17in.jpg" />
     28          <a href="microwave.html" itemprop="url">
     29            <span itemprop="name">Bon Echo Microwave</span>
     30          </a>
     31 
     32          <div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
     33            <span itemprop="price" content="3.50">£3.50</span>
     34            <span itemprop="priceCurrency" content="GBP"></span>
     35          </div>
     36 
     37          <span itemprop="gtin" content="13572468"></span>
     38 
     39          <span itemprop="description">The most amazing microwave in the world</span>
     40        </div>
     41      </body>
     42      </html>
     43    `,
     44    {
     45      siteName: "Mozilla",
     46      description: "The most amazing microwave in the world",
     47      image: BASE_URL + "/bon-echo-microwave-17in.jpg",
     48      data: {
     49        [PageDataSchema.DATA_TYPE.PRODUCT]: {
     50          name: "Bon Echo Microwave",
     51          price: {
     52            value: 3.5,
     53            currency: "GBP",
     54          },
     55        },
     56      },
     57    }
     58  );
     59 });
     60 
     61 add_task(async function test_single_product_json_ld() {
     62  await verifyPageData(
     63    `
     64      <!DOCTYPE html>
     65      <html>
     66      <head>
     67      <script type="application/ld+json">
     68        {
     69          "@context": "http://schema.org",
     70          "@type": "Organization",
     71          "employee": {
     72            "@type": "Person",
     73            "name": "Mr. Nested Name"
     74          },
     75          "name": "Mozilla"
     76        }
     77      </script>
     78      <script type="application/ld+json">
     79        {
     80          "@context": "https://schema.org",
     81          "@type": "Product",
     82          "image": "bon-echo-microwave-17in.jpg",
     83          "url": "microwave.html",
     84          "name": "Bon Echo Microwave",
     85          "offers": {
     86            "@type": "Offer",
     87            "price": "3.50",
     88            "priceCurrency": "GBP"
     89          },
     90          "gtin": "13572468",
     91          "description": "The most amazing microwave in the world"
     92        }
     93      </script>
     94      </head>
     95      <body>
     96      </body>
     97      </html>
     98    `,
     99    {
    100      siteName: "Mozilla",
    101      description: "The most amazing microwave in the world",
    102      image: BASE_URL + "/bon-echo-microwave-17in.jpg",
    103      data: {
    104        [PageDataSchema.DATA_TYPE.PRODUCT]: {
    105          name: "Bon Echo Microwave",
    106          price: {
    107            value: 3.5,
    108            currency: "GBP",
    109          },
    110        },
    111      },
    112    }
    113  );
    114 });
    115 
    116 add_task(async function test_single_product_combined() {
    117  await verifyPageData(
    118    `
    119      <!DOCTYPE html>
    120      <html>
    121      <head>
    122      <script type="application/ld+json">
    123        {
    124          "@context": "https://schema.org",
    125          "@type": "Product",
    126          "image": "bon-echo-microwave-17in.jpg",
    127          "url": "microwave.html",
    128          "name": "Bon Echo Microwave",
    129          "offers": {
    130            "@type": "Offer",
    131            "price": "3.50",
    132            "priceCurrency": "GBP"
    133          },
    134          "gtin": "13572468",
    135          "description": "The most amazing microwave in the world"
    136        }
    137      </script>
    138      </head>
    139      <body>
    140        <div itemscope itemtype="https://schema.org/Organization">
    141          <div itemprop="employee" itemscope itemtype="https://schema.org/Person">
    142            <span itemprop="name">Mr. Nested Name</span>
    143          </div>
    144 
    145          <span itemprop="name">Mozilla</span>
    146        </div>
    147      </body>
    148      </html>
    149    `,
    150    {
    151      siteName: "Mozilla",
    152      description: "The most amazing microwave in the world",
    153      image: BASE_URL + "/bon-echo-microwave-17in.jpg",
    154      data: {
    155        [PageDataSchema.DATA_TYPE.PRODUCT]: {
    156          name: "Bon Echo Microwave",
    157          price: {
    158            value: 3.5,
    159            currency: "GBP",
    160          },
    161        },
    162      },
    163    }
    164  );
    165 });
    166 
    167 add_task(async function test_single_multiple_microdata() {
    168  await verifyPageData(
    169    `
    170      <!DOCTYPE html>
    171      <html>
    172      <head>
    173      <title>Product Info 2</title>
    174      </head>
    175      <body>
    176        <div itemscope itemtype="https://schema.org/Product">
    177          <img itemprop="image" src="bon-echo-microwave-17in.jpg" />
    178          <a href="microwave.html" itemprop="url">
    179            <span itemprop="name">Bon Echo Microwave</span>
    180          </a>
    181 
    182          <div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
    183            <span itemprop="price" content="3.28">£3.28</span>
    184            <span itemprop="priceCurrency" content="GBP"></span>
    185          </div>
    186 
    187          <span itemprop="gtin" content="13572468"></span>
    188        </div>
    189        <div itemscope itemtype="http://schema.org/Product">
    190          <img itemprop="image" src="gran-paradiso-toaster-17in.jpg" />
    191          <a href="toaster.html" itemprop="url">
    192            <span itemprop="name">Gran Paradiso Toaster</span>
    193          </a>
    194 
    195          <span itemprop="gtin" content="15263748"></span>
    196        </div>
    197      </body>
    198      </html>
    199    `,
    200    {
    201      image: BASE_URL + "/bon-echo-microwave-17in.jpg",
    202      data: {
    203        [PageDataSchema.DATA_TYPE.PRODUCT]: {
    204          name: "Bon Echo Microwave",
    205          price: {
    206            value: 3.28,
    207            currency: "GBP",
    208          },
    209        },
    210      },
    211    }
    212  );
    213 });