commit ee6f3d3238c2ac4030f8be1f5dd529d113696ca7
parent b6b13a99af4d01dd237e1e7bff422b5dd5d8e074
Author: Irene Ni <rhn0312@gmail.com>
Date: Wed, 7 Jan 2026 22:23:55 +0000
Bug 2002129 - Add unit tests for MozNewTabWallpaperProtocolHandler. r=necko-reviewers,valentin
Differential Revision: https://phabricator.services.mozilla.com/D273923
Diffstat:
2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/netwerk/test/unit/test_wallpaper_protocol.js b/netwerk/test/unit/test_wallpaper_protocol.js
@@ -0,0 +1,38 @@
+"use strict";
+
+// Need profile so that the protocol handler can resolve the path to the underlying file
+do_get_profile();
+
+function run_test() {
+ // Check the protocol handler implements the correct interfaces
+ let handler = Services.io.getProtocolHandler("moz-newtab-wallpaper");
+ ok(
+ handler instanceof Ci.nsIProtocolHandler,
+ "moz-newtab-wallpaper handler provides nsIProtocolHandler interface"
+ );
+ ok(
+ handler instanceof Ci.nsISubstitutingProtocolHandler,
+ "moz-newtab-wallpaper handler provides nsISubstitutingProtocolHandler interface"
+ );
+
+ // Create a dummy loadinfo which we can hand to newChannel
+ let dummyURI = Services.io.newURI("https://www.example.com/");
+ let dummyChannel = NetUtil.newChannel({
+ uri: dummyURI,
+ loadUsingSystemPrincipal: true,
+ });
+ let dummyLoadInfo = dummyChannel.loadInfo;
+
+ // Test that empty host fails
+ let emptyHost = Services.io.newURI("moz-newtab-wallpaper://");
+ Assert.throws(
+ () => handler.newChannel(emptyHost, dummyLoadInfo),
+ /NS_ERROR/i,
+ "moz-newtab-wallpaper URI with empty host must not resolve"
+ );
+
+ // Test that valid host creates a channel (even if file doesn't exist yet)
+ let validURI = Services.io.newURI("moz-newtab-wallpaper://wallpaper.jpg");
+ let channel = handler.newChannel(validURI, dummyLoadInfo);
+ ok(channel, "moz-newtab-wallpaper URI with valid host creates a channel");
+}
diff --git a/netwerk/test/unit/xpcshell.toml b/netwerk/test/unit/xpcshell.toml
@@ -1586,6 +1586,8 @@ run-sequentially = ["true"] # node server exceptions dont replay well
["test_verify_traffic.js"]
+["test_wallpaper_protocol.js"]
+
["test_websocket_500k.js"]
skip-if = [
"verify",