Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test runs only with pattern: os != 'android'
- Manifest: browser/components/aiwindow/models/tests/xpcshell/xpcshell.toml
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
do_get_profile();
const { getTabList, MAX_TABS } = ChromeUtils.importESModule(
"moz-src:///browser/components/aiwindow/models/Tools.sys.mjs"
);
const { sinon } = ChromeUtils.importESModule(
);
add_task(function test_getTabList_filters_non_web_urls() {
const BrowserWindowTracker = ChromeUtils.importESModule(
"resource:///modules/BrowserWindowTracker.sys.mjs"
).BrowserWindowTracker;
const sb = sinon.createSandbox();
try {
const fakeWindow = createFakeWindow([
createFakeTab("about:preferences", "Preferences", 2000),
createFakeTab("about:config", "Config", 3000),
createFakeTab("about:blank", "Blank", 5000),
createFakeTab("chrome://browser/content/browser.xhtml", "Chrome", 6000),
createFakeTab("data:text/html,hello", "Data URL", 9000),
]);
sb.stub(BrowserWindowTracker, "orderedWindows").get(() => [fakeWindow]);
const tabs = getTabList();
Assert.equal(
tabs.length,
2,
"Should only return http/https tabs (filtered 7)"
);
Assert.equal(
tabs[0].url,
"Should return mozilla.org"
);
Assert.ok(
tabs.every(
t => t.url.startsWith("https://") || t.url.startsWith("http://")
),
"Only http/https URLs in results"
);
} finally {
sb.restore();
}
});
add_task(function test_getTabList_pagination() {
const BrowserWindowTracker = ChromeUtils.importESModule(
"resource:///modules/BrowserWindowTracker.sys.mjs"
).BrowserWindowTracker;
const sb = sinon.createSandbox();
try {
const tabs = [];
for (let i = 0; i < MAX_TABS + 20; i++) {
tabs.push(
);
}
tabs.push(
createFakeTab(FAKE_TAB_URL, "This is so fake", (MAX_TABS + 20) * 1000)
);
const fakeWindow = createFakeWindow(tabs);
sb.stub(BrowserWindowTracker, "orderedWindows").get(() => [fakeWindow]);
// Test default limit
const defaultResult = getTabList();
Assert.equal(
defaultResult.length,
MAX_TABS,
`Should return at most ${MAX_TABS} tabs`
);
Assert.equal(
defaultResult[0].url,
FAKE_TAB_URL,
"First tab should be most recent"
);
} finally {
sb.restore();
}
});
add_task(function test_getTabList_custom_pagination() {
const BrowserWindowTracker = ChromeUtils.importESModule(
"resource:///modules/BrowserWindowTracker.sys.mjs"
).BrowserWindowTracker;
const sb = sinon.createSandbox();
try {
const tabs = [];
for (let i = 0; i < MAX_TABS + 20; i++) {
tabs.push(
);
}
tabs.push(
createFakeTab(FAKE_TAB_URL, "This is so fake", (MAX_TABS + 20) * 1000)
);
const fakeWindow = createFakeWindow(tabs);
sb.stub(BrowserWindowTracker, "orderedWindows").get(() => [fakeWindow]);
// Test custom limit
const CUSTOM_LIMIT = 4;
const defaultResult = getTabList(CUSTOM_LIMIT);
Assert.equal(
defaultResult.length,
4,
`Should return at most ${CUSTOM_LIMIT} tabs`
);
Assert.equal(
defaultResult[0].url,
FAKE_TAB_URL,
"First tab should be most recent"
);
} finally {
sb.restore();
}
});
add_task(function test_getTabList_filters_non_ai_windows() {
const BrowserWindowTracker = ChromeUtils.importESModule(
"resource:///modules/BrowserWindowTracker.sys.mjs"
).BrowserWindowTracker;
const sb = sinon.createSandbox();
try {
const aiWindow = createFakeWindow(
[
],
false,
true
);
const classicWindow = createFakeWindow(
[
],
false,
false
);
sb.stub(BrowserWindowTracker, "orderedWindows").get(() => [
classicWindow,
aiWindow,
]);
const tabs = getTabList();
Assert.equal(
tabs.length,
2,
"Should only return tabs from AI Windows (filtered 2 classic tabs)"
);
Assert.ok(
!tabs.some(t => t.url.includes("classic")),
"No classic window tabs in results"
);
} finally {
sb.restore();
}
});