Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
-
CI results over the last 21 days5,964Runs99.98%Pass0Failures1Timeouts0Crashes0Skips
Runs with issues per day (up to 0.1%) Oct 2Oct 22- Timeouts
- This test runs only with pattern: os != 'android'
- Manifest: browser/components/aiwindow/ui/test/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
const { AgentPageDetector, AgentPageCategory } = ChromeUtils.importESModule(
"moz-src:///browser/components/aiwindow/ui/modules/AgentPageDetector.sys.mjs"
);
const { getPageCategory, getPageInfo, getProductInfo, isProductURL } =
AgentPageDetector;
const { PRODUCT_DETAIL, SHOPPING_HOME, NEWS_HOME } = AgentPageCategory;
// Supported product pages (US .com only): [url, expectedSite, expectedId].
const PRODUCT_URLS = [
// Amazon - /dp/, /gp/product/
[
"amazon",
"B08PZHYWJS",
],
// Walmart - /ip/<slug>/<id>.
[
"walmart",
"611698847",
],
// Best Buy - /product/<slug>/<id>.
[
"bestbuy",
"JJGCQYH68H",
],
// Sephora - P-id in the path.
[
"sephora",
"P123456",
],
];
// URLs that must not be treated as a supported product page.
const NON_PRODUCT_URLS = [
// Supported hosts, but not product pages.
// Best Buy category page (.c), not a product.
// Best Buy /product/ path whose id segment isn't a clean SKU (has a dot).
// Supported retailers, unsupported markets.
// Unsupported retailers.
// Non-web schemes and non-URLs.
"about:blank",
"data:text/html,hi",
"not a url",
];
// Home pages, with the host they are expected to be matched on.
const SHOPPING_HOME_URLS = [
// US.
// Canada.
];
const NEWS_HOME_URLS = [
// US.
// Canada.
];
// Listed hosts, but deeper than the home page, plus unlisted hosts.
const NON_HOME_URLS = [
];
add_task(function test_detects_supported_product_pages() {
for (const [url, site, id] of PRODUCT_URLS) {
const info = getProductInfo(url);
Assert.ok(info, `Detects a product page: ${url}`);
Assert.equal(info.site, site, `Correct retailer for ${url}`);
Assert.equal(info.id, id, `Correct product id for ${url}`);
Assert.ok(isProductURL(url), `isProductURL is true for ${url}`);
Assert.deepEqual(
getPageInfo(url),
{ category: PRODUCT_DETAIL, site, id },
`Categorized as a product page: ${url}`
);
}
});
add_task(function test_ignores_non_product_pages() {
for (const url of NON_PRODUCT_URLS) {
Assert.equal(getProductInfo(url), null, `Not a product page: ${url}`);
Assert.ok(!isProductURL(url), `isProductURL is false for ${url}`);
Assert.notEqual(
getPageCategory(url),
PRODUCT_DETAIL,
`Not categorized as a product page: ${url}`
);
}
});
add_task(function test_detects_home_pages() {
const cases = [
[SHOPPING_HOME, SHOPPING_HOME_URLS],
[NEWS_HOME, NEWS_HOME_URLS],
];
for (const [category, urls] of cases) {
for (const [url, site] of urls) {
Assert.deepEqual(
getPageInfo(url),
{ category, site },
`Detects a ${category} page: ${url}`
);
}
}
});
add_task(function test_ignores_non_home_pages() {
for (const url of NON_HOME_URLS) {
Assert.equal(getPageCategory(url), null, `Not a home page: ${url}`);
}
});
add_task(function test_accepts_url_and_nsiuri_inputs() {
Assert.equal(
getProductInfo(new URL(spec))?.id,
"B08PZHYWJS",
"Accepts a URL instance"
);
Assert.equal(
getProductInfo(Services.io.newURI(spec))?.id,
"B08PZHYWJS",
"Accepts an nsIURI instance"
);
Assert.equal(getProductInfo(null), null, "Handles null input");
Assert.equal(
NEWS_HOME,
"getPageCategory accepts an nsIURI instance"
);
Assert.equal(getPageCategory(null), null, "getPageCategory handles null");
});