simple_unknown_uri_helpers.sys.mjs (2187B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import { NetUtil } from "resource://gre/modules/NetUtil.sys.mjs"; 6 import { Assert } from "resource://testing-common/Assert.sys.mjs"; 7 8 export function checkInputAndSerializationMatch(input) { 9 let uri = NetUtil.newURI(input); 10 Assert.equal( 11 uri.spec, 12 input, 13 `serialization should match the input: {input}` 14 ); 15 } 16 17 export function checkInputAndSerializationMatchChild(input) { 18 let uri = Services.io.newURI(input); 19 Assert.equal( 20 uri.spec, 21 input, 22 `serialization should match the input: {input}` 23 ); 24 } 25 26 export function removeSecondColon(str) { 27 let colonIndex = str.indexOf(":"); 28 if (colonIndex !== -1) { 29 colonIndex = str.indexOf(":", colonIndex + 1); 30 if (colonIndex !== -1) { 31 return str.slice(0, colonIndex) + str.slice(colonIndex + 1); 32 } 33 } 34 Assert.ok(false, "we expected at least two colons"); 35 return str; 36 } 37 38 export function checkSerializationMissingSecondColon(input) { 39 let uri = NetUtil.newURI(input); 40 Assert.equal( 41 uri.spec, 42 removeSecondColon(input), 43 `serialization should be missing second colon from input: {input}` 44 ); 45 } 46 47 export function checkSerializationMissingSecondColonChild(input) { 48 let uri = Services.io.newURI(input); 49 Assert.equal( 50 uri.spec, 51 removeSecondColon(input), 52 `serialization should be missing second colon from input: {input}` 53 ); 54 } 55 56 export function runParentTestSuite() { 57 // sanity check 58 checkInputAndSerializationMatch("https://example.com/"); 59 60 // special scheme uses nsStanardURL 61 checkSerializationMissingSecondColon("https://https://example.com"); 62 63 // no-bypass protocol uses defaultURI 64 checkSerializationMissingSecondColon( 65 "defaulturischeme://https://example.com" 66 ); 67 68 // an unknown protocol in the bypass list (remote settings) uses simpleURI 69 checkInputAndSerializationMatch("testsyncscheme://https://example.com"); 70 71 // pref-specified scheme bypass uses simpleURI 72 checkInputAndSerializationMatch("simpleprotocol://https://example.com"); 73 }