test_SearchBrowsingHistoryDomainBoost.js (1865B)
1 /** 2 * This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 */ 6 7 const { matchDomains, mergeDedupe } = ChromeUtils.importESModule( 8 "moz-src:///browser/components/aiwindow/models/SearchBrowsingHistoryDomainBoost.sys.mjs" 9 ); 10 11 add_task(async function test_matchDomains_games_and_boundary_behavior() { 12 // Positive: should match games category 13 const domains = matchDomains("video games"); 14 Assert.ok( 15 domains?.includes("store.steampowered.com"), 16 "Should include store.steampowered.com for games" 17 ); 18 19 // Negative: should not match substrings inside words ("endgame" should not trigger "game") 20 const domains2 = matchDomains("endgame"); 21 Assert.equal(domains2, null, "Should not match 'game' inside 'endgame'"); 22 }); 23 24 add_task(async function test_matchDomains_prefers_longer_phrases() { 25 // "tech news" should match tech_news (not generic news) 26 const domains = matchDomains("tech news"); 27 Assert.ok( 28 domains?.includes("techcrunch.com"), 29 "Should match tech_news domains" 30 ); 31 Assert.ok( 32 !domains.includes("reuters.com"), 33 "Should not fall back to generic news domains" 34 ); 35 }); 36 37 add_task(async function test_mergeDedupe_semantic_first_then_topup() { 38 const primary = [ 39 { id: 1, url: "https://example.com/a", title: "A" }, 40 { id: 2, url: "https://example.com/b", title: "B" }, 41 ]; 42 const secondary = [ 43 { id: 3, url: "https://example.com/b", title: "B dup" }, // dup by url 44 { id: 4, url: "https://example.com/c", title: "C" }, 45 ]; 46 47 const out = mergeDedupe(primary, secondary, 10); 48 Assert.deepEqual( 49 out.map(r => r.url), 50 ["https://example.com/a", "https://example.com/b", "https://example.com/c"], 51 "Should keep primary order and de-dupe by url" 52 ); 53 });