test_disableNewTabAsAddon_pref.js (3514B)
1 /* Any copyright is dedicated to the Public Domain. 2 https://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from ../../../../extensions/newtab/test/xpcshell/head.js */ 7 8 const { 9 AboutNewTabResourceMapping, 10 BUILTIN_ADDON_ID, 11 DISABLE_NEWTAB_AS_ADDON_PREF, 12 } = ChromeUtils.importESModule( 13 "resource:///modules/AboutNewTabResourceMapping.sys.mjs" 14 ); 15 16 // NOTE: this test verifies that when the browser.newtabpage.disableNewTabAsAddon 17 // is set to true (set on the xpcshell.toml side for this specific test file), 18 // then the AboutNewTabResourceMapping module (already initializated by the 19 // setup task added from the head.js support file) is mapping the resources 20 // bundled in the Desktop omni jar without going through the add-ons rootURI. 21 22 add_task(async function test_pref_sanity_check() { 23 Assert.equal( 24 Services.prefs.getBoolPref(DISABLE_NEWTAB_AS_ADDON_PREF, false), 25 true, 26 "Expected disableNewTabAsAddon pref to be true" 27 ); 28 Assert.equal( 29 AboutNewTabResourceMapping.newTabAsAddonDisabled, 30 true, 31 "Expected AboutNewTabResourceMapping.newTabAsAddonDisabled to be true" 32 ); 33 }); 34 35 add_task(async function test_bundled_resource_mapping() { 36 assertNewTabResourceMapping(); 37 }); 38 39 add_task(async function test_AboutNewTabResourceMapping() { 40 Assert.equal( 41 AboutNewTabResourceMapping.addonVersion, 42 null, 43 "Expected AboutNewTabResourceMapping addonVersion to be null" 44 ); 45 46 const resProto = Cc[ 47 "@mozilla.org/network/protocol;1?name=resource" 48 ].getService(Ci.nsIResProtocolHandler); 49 const expectedRootURISpec = `${resProto.getSubstitution("builtin-addons").spec}newtab/`; 50 Assert.equal( 51 AboutNewTabResourceMapping._rootURISpec, 52 expectedRootURISpec, 53 "Got the expected AboutNewTabResourceMapping rootURISpec" 54 ); 55 56 Assert.equal( 57 AboutNewTabResourceMapping._addonListener, 58 null, 59 "Expected no addon listener" 60 ); 61 62 let policy = WebExtensionPolicy.getByID(BUILTIN_ADDON_ID); 63 ok(policy, "Found a WebExtensionPolicy instance for the builtin addon id"); 64 65 Services.fog.testResetFOG(); 66 const { id, rootURI, version } = 67 AboutNewTabResourceMapping.getPreferredMapping(); 68 Assert.deepEqual( 69 { id, rootURI: rootURI.spec, version }, 70 { 71 id: null, 72 rootURI: expectedRootURISpec, 73 version: null, 74 }, 75 "AboutNewTabResourceMapping.getPreferredMapping ignores active builtin addon" 76 ); 77 Assert.ok( 78 !Glean.newtab.addonXpiUsed.testGetValue(), 79 "Probe says we're not using an XPI" 80 ); 81 }); 82 83 add_task(async function test_parentprocess_fetch() { 84 let addon = await AddonManager.getAddonByID(BUILTIN_ADDON_ID); 85 ok(addon, "Found builtin addon"); 86 Assert.equal(addon.isActive, true, "Expect add-on initially active"); 87 Assert.equal( 88 addon.locationName, 89 "app-builtin-addons", 90 "Expected add-on to be in the builtin location" 91 ); 92 await addon.disable({ allowSystemAddons: true }); 93 let policy = WebExtensionPolicy.getByID(BUILTIN_ADDON_ID); 94 ok( 95 !policy, 96 "No WebExtensionPolicy instance should be found for the disabled built-in add-on" 97 ); 98 99 const bundleResReq = await fetch( 100 "resource://newtab/data/content/activity-stream.bundle.js" 101 ); 102 Assert.equal( 103 bundleResReq.status, 104 200, 105 "resource://newtab fetch should be successful" 106 ); 107 108 const cssChromeReq = await fetch( 109 "chrome://newtab/content/css/activity-stream.css" 110 ); 111 Assert.equal( 112 cssChromeReq.status, 113 200, 114 "chrome://newtab fetch should be successfull" 115 ); 116 });