test_provider_id.js (1699B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const { GenAI } = ChromeUtils.importESModule( 5 "resource:///modules/GenAI.sys.mjs" 6 ); 7 8 registerCleanupFunction(() => { 9 Services.prefs.clearUserPref("browser.ml.chat.provider"); 10 Services.prefs.clearUserPref("browser.ml.chat.providers"); 11 }); 12 13 /** 14 * Check various provider ids are converted 15 */ 16 add_task(async function test_provider_id() { 17 Assert.equal(GenAI.getProviderId(""), "none", "Empty is none"); 18 Assert.equal( 19 GenAI.getProviderId("http://mochi.test"), 20 "custom", 21 "Unknown is custom" 22 ); 23 Assert.equal( 24 GenAI.getProviderId("http://localhost:8080"), 25 "localhost", 26 "Known gets an id" 27 ); 28 Assert.equal(GenAI.getProviderId(), "none", "Default to empty"); 29 30 Services.prefs.setStringPref( 31 "browser.ml.chat.provider", 32 "http://mochi.test:8888" 33 ); 34 Assert.equal(GenAI.getProviderId(), "custom", "Used custom pref"); 35 }); 36 37 /** 38 * Check that providers can be hidden 39 */ 40 add_task(async function test_hide_providers() { 41 const chatgpt = GenAI.chatProviders.get("https://chatgpt.com"); 42 43 Assert.ok(!chatgpt.hidden, "ChatGPT shown by default"); 44 45 Services.prefs.setStringPref("browser.ml.chat.providers", ""); 46 47 Assert.ok(chatgpt.hidden, "ChatGPT hidden"); 48 }); 49 50 /** 51 * Check that providers can be ordered 52 */ 53 add_task(async function test_providers_order() { 54 Services.prefs.setStringPref( 55 "browser.ml.chat.providers", 56 "huggingchat,chatgpt" 57 ); 58 59 const shown = []; 60 GenAI.chatProviders.forEach(val => { 61 if (!val.hidden) { 62 shown.push(val.id); 63 } 64 }); 65 66 Assert.equal(shown, "huggingchat,chatgpt", "Providers reordered"); 67 });