test_wallpaper_protocol.js (1394B)
1 "use strict"; 2 3 // Need profile so that the protocol handler can resolve the path to the underlying file 4 do_get_profile(); 5 6 function run_test() { 7 // Check the protocol handler implements the correct interfaces 8 let handler = Services.io.getProtocolHandler("moz-newtab-wallpaper"); 9 ok( 10 handler instanceof Ci.nsIProtocolHandler, 11 "moz-newtab-wallpaper handler provides nsIProtocolHandler interface" 12 ); 13 ok( 14 handler instanceof Ci.nsISubstitutingProtocolHandler, 15 "moz-newtab-wallpaper handler provides nsISubstitutingProtocolHandler interface" 16 ); 17 18 // Create a dummy loadinfo which we can hand to newChannel 19 let dummyURI = Services.io.newURI("https://www.example.com/"); 20 let dummyChannel = NetUtil.newChannel({ 21 uri: dummyURI, 22 loadUsingSystemPrincipal: true, 23 }); 24 let dummyLoadInfo = dummyChannel.loadInfo; 25 26 // Test that empty host fails 27 let emptyHost = Services.io.newURI("moz-newtab-wallpaper://"); 28 Assert.throws( 29 () => handler.newChannel(emptyHost, dummyLoadInfo), 30 /NS_ERROR/i, 31 "moz-newtab-wallpaper URI with empty host must not resolve" 32 ); 33 34 // Test that valid host creates a channel (even if file doesn't exist yet) 35 let validURI = Services.io.newURI("moz-newtab-wallpaper://wallpaper.jpg"); 36 let channel = handler.newChannel(validURI, dummyLoadInfo); 37 ok(channel, "moz-newtab-wallpaper URI with valid host creates a channel"); 38 }