From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../base/content/test/metaTags/bad_meta_tags.html | 14 ++++++ browser/base/content/test/metaTags/browser.ini | 9 ++++ .../content/test/metaTags/browser_bad_meta_tags.js | 37 ++++++++++++++ .../content/test/metaTags/browser_meta_tags.js | 57 ++++++++++++++++++++++ browser/base/content/test/metaTags/head.js | 19 ++++++++ browser/base/content/test/metaTags/meta_tags.html | 29 +++++++++++ 6 files changed, 165 insertions(+) create mode 100644 browser/base/content/test/metaTags/bad_meta_tags.html create mode 100644 browser/base/content/test/metaTags/browser.ini create mode 100644 browser/base/content/test/metaTags/browser_bad_meta_tags.js create mode 100644 browser/base/content/test/metaTags/browser_meta_tags.js create mode 100644 browser/base/content/test/metaTags/head.js create mode 100644 browser/base/content/test/metaTags/meta_tags.html (limited to 'browser/base/content/test/metaTags') 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 @@ + + + + BadMetaTags + + + + + + + + + + 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 @@ + + + + + MetaTags + + + + + + + + + + + + + -- cgit v1.2.3