summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/metaTags
diff options
context:
space:
mode:
Diffstat (limited to 'browser/base/content/test/metaTags')
-rw-r--r--browser/base/content/test/metaTags/bad_meta_tags.html14
-rw-r--r--browser/base/content/test/metaTags/browser.ini9
-rw-r--r--browser/base/content/test/metaTags/browser_bad_meta_tags.js37
-rw-r--r--browser/base/content/test/metaTags/browser_meta_tags.js57
-rw-r--r--browser/base/content/test/metaTags/head.js19
-rw-r--r--browser/base/content/test/metaTags/meta_tags.html29
6 files changed, 165 insertions, 0 deletions
diff --git a/browser/base/content/test/metaTags/bad_meta_tags.html b/browser/base/content/test/metaTags/bad_meta_tags.html
new file mode 100644
index 0000000000..ce687d7792
--- /dev/null
+++ b/browser/base/content/test/metaTags/bad_meta_tags.html
@@ -0,0 +1,14 @@
+<html>
+ <head>
+ <meta charset="UTF-8" />
+ <title>BadMetaTags</title>
+ <meta property="twitter:image" content="http://test.com/twitter-image.jpg" />
+ <meta property="og:image:url" content="ftp://test.com/og-image-url" />
+ <meta property="og:image" content="file:///Users/invalid/img.jpg" />
+ <meta property="twitter:description" />
+ <meta property="og:description" content="" />
+ <meta name="description" content="description" />
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/browser/base/content/test/metaTags/browser.ini b/browser/base/content/test/metaTags/browser.ini
new file mode 100644
index 0000000000..4468d331f0
--- /dev/null
+++ b/browser/base/content/test/metaTags/browser.ini
@@ -0,0 +1,9 @@
+[DEFAULT]
+support-files =
+ head.js
+
+[browser_bad_meta_tags.js]
+support-files = bad_meta_tags.html
+[browser_meta_tags.js]
+skip-if = tsan # Bug 1403403
+support-files = meta_tags.html
diff --git a/browser/base/content/test/metaTags/browser_bad_meta_tags.js b/browser/base/content/test/metaTags/browser_bad_meta_tags.js
new file mode 100644
index 0000000000..00cc128ec0
--- /dev/null
+++ b/browser/base/content/test/metaTags/browser_bad_meta_tags.js
@@ -0,0 +1,37 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const TEST_PATH =
+ getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ "https://example.com"
+ ) + "bad_meta_tags.html";
+
+/**
+ * This tests that with the page bad_meta_tags.html, ContentMetaHandler.jsm parses
+ * out the meta tags available and does not store content provided by a malformed
+ * meta tag. In this case the best defined meta tags are malformed, so here we
+ * test that we store the next best ones - "description" and "twitter:image". The
+ * list of meta tags and order of preference is found in ContentMetaHandler.jsm.
+ */
+add_task(async function test_bad_meta_tags() {
+ const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PATH);
+
+ // Wait until places has stored the page info
+ const pageInfo = await waitForPageInfo(TEST_PATH);
+ is(
+ pageInfo.description,
+ "description",
+ "did not collect a og:description because meta tag was malformed"
+ );
+ is(
+ pageInfo.previewImageURL.href,
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ "http://test.com/twitter-image.jpg",
+ "did not collect og:image because of invalid loading principal"
+ );
+
+ BrowserTestUtils.removeTab(tab);
+ await PlacesUtils.history.clear();
+});
diff --git a/browser/base/content/test/metaTags/browser_meta_tags.js b/browser/base/content/test/metaTags/browser_meta_tags.js
new file mode 100644
index 0000000000..380a71214c
--- /dev/null
+++ b/browser/base/content/test/metaTags/browser_meta_tags.js
@@ -0,0 +1,57 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const TEST_PATH =
+ getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ "https://example.com"
+ ) + "meta_tags.html";
+/**
+ * This tests that with the page meta_tags.html, ContentMetaHandler.jsm parses
+ * out the meta tags avilable and only stores the best one for description and
+ * one for preview image url. In the case of this test, the best defined meta
+ * tags are "og:description" and "og:image:secure_url". The list of meta tags
+ * and order of preference is found in ContentMetaHandler.jsm.
+ */
+add_task(async function test_metadata() {
+ const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PATH);
+
+ // Wait until places has stored the page info
+ const pageInfo = await waitForPageInfo(TEST_PATH);
+ is(pageInfo.description, "og:description", "got the correct description");
+ is(
+ pageInfo.previewImageURL.href,
+ "https://test.com/og-image-secure-url.jpg",
+ "got the correct preview image"
+ );
+
+ BrowserTestUtils.removeTab(tab);
+ await PlacesUtils.history.clear();
+});
+
+/**
+ * This test is almost like the previous one except it opens a second tab to
+ * make sure the extra tab does not cause the debounce logic to be skipped. If
+ * incorrectly skipped, the updated metadata would not include the delayed meta.
+ */
+add_task(async function multiple_tabs() {
+ const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PATH);
+
+ // Add a background tab to cause another page to load *without* putting the
+ // desired URL in a background tab, which results in its timers being throttled.
+ BrowserTestUtils.addTab(gBrowser);
+
+ // Wait until places has stored the page info
+ const pageInfo = await waitForPageInfo(TEST_PATH);
+ is(pageInfo.description, "og:description", "got the correct description");
+ is(
+ pageInfo.previewImageURL.href,
+ "https://test.com/og-image-secure-url.jpg",
+ "got the correct preview image"
+ );
+
+ BrowserTestUtils.removeTab(tab);
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+ await PlacesUtils.history.clear();
+});
diff --git a/browser/base/content/test/metaTags/head.js b/browser/base/content/test/metaTags/head.js
new file mode 100644
index 0000000000..1f292c4c03
--- /dev/null
+++ b/browser/base/content/test/metaTags/head.js
@@ -0,0 +1,19 @@
+ChromeUtils.defineESModuleGetters(this, {
+ PlacesTestUtils: "resource://testing-common/PlacesTestUtils.sys.mjs",
+ PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs",
+});
+
+/**
+ * Wait for url's page info (non-null description and preview url) to be set.
+ * Because there is debounce logic in ContentLinkHandler.jsm to only make one
+ * single SQL update, we have to wait for some time before checking that the page
+ * info was stored.
+ */
+async function waitForPageInfo(url) {
+ let pageInfo;
+ await BrowserTestUtils.waitForCondition(async () => {
+ pageInfo = await PlacesUtils.history.fetch(url, { includeMeta: true });
+ return pageInfo && pageInfo.description && pageInfo.previewImageURL;
+ });
+ return pageInfo;
+}
diff --git a/browser/base/content/test/metaTags/meta_tags.html b/browser/base/content/test/metaTags/meta_tags.html
new file mode 100644
index 0000000000..ad162da1f5
--- /dev/null
+++ b/browser/base/content/test/metaTags/meta_tags.html
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="UTF-8" />
+ <title>MetaTags</title>
+ <meta property="twitter:description" content="twitter:description" />
+ <meta property="og:description" content="og:description" />
+ <meta name="description" content="description" />
+ <meta name="unknown:tag" content="unknown:tag" />
+ <meta property="og:image" content="https://test.com/og-image.jpg" />
+ <meta property="twitter:image" content="https://test.com/twitter-image.jpg" />
+ <meta property="og:image:url" content="https://test.com/og-image-url" />
+ <meta name="thumbnail" content="https://test.com/thumbnail.jpg" />
+ </head>
+ <body>
+ <script>
+ function addMeta(tag) {
+ const meta = document.createElement("meta");
+ meta.content = "https://test.com/og-image-secure-url.jpg";
+ meta.setAttribute("property", tag);
+ document.head.appendChild(meta);
+ }
+
+ // Delay adding this "best" image tag to test that later tags are used.
+ // Use a delay that is long enough for tests to check for wrong metadata.
+ setTimeout(() => addMeta("og:image:secure_url"), 100);
+ </script>
+ </body>
+</html>