browser_simple_unknown_uris_sync.js (4644B)
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 "use strict"; 6 7 ChromeUtils.defineESModuleGetters(this, { 8 RemoteSettings: "resource://services-settings/remote-settings.sys.mjs", 9 }); 10 11 const { 12 checkInputAndSerializationMatch, 13 checkInputAndSerializationMatchChild, 14 checkSerializationMissingSecondColon, 15 checkSerializationMissingSecondColonChild, 16 removeSecondColon, 17 runParentTestSuite, 18 } = ChromeUtils.importESModule( 19 "resource://testing-common/simple_unknown_uri_helpers.sys.mjs" 20 ); 21 22 const { sinon } = ChromeUtils.importESModule( 23 "resource://testing-common/Sinon.sys.mjs" 24 ); 25 26 add_setup(async function () { 27 await SpecialPowers.pushPrefEnv({ 28 set: [ 29 ["network.url.useDefaultURI", true], 30 ["network.url.simple_uri_unknown_schemes_enabled", true], 31 ["network.url.simple_uri_unknown_schemes", "simpleprotocol,otherproto"], 32 ], 33 }); 34 }); 35 36 const bypassCollectionName = "url-parser-default-unknown-schemes-interventions"; 37 38 let newData = [ 39 { 40 id: "111", 41 scheme: "testinitscheme", 42 }, 43 { 44 id: "112", 45 scheme: "testsyncscheme", 46 }, 47 ]; 48 49 // sync update, test on parent 50 add_task(async function test_bypass_list_update_sync_parent() { 51 const settings = await RemoteSettings(bypassCollectionName); 52 let stub = sinon.stub(settings, "get").returns(newData); 53 registerCleanupFunction(async function () { 54 stub.restore(); 55 }); 56 57 await RemoteSettings(bypassCollectionName).emit("sync", {}); 58 59 runParentTestSuite(); 60 61 stub.restore(); 62 }); 63 64 // sync update, test on child 65 add_task(async function test_bypass_list_update_sync_child() { 66 await SpecialPowers.pushPrefEnv({ 67 set: [["security.allow_eval_with_system_principal", true]], 68 }); 69 70 const settings = await RemoteSettings(bypassCollectionName); 71 let stub = sinon.stub(settings, "get").returns(newData); 72 registerCleanupFunction(async function () { 73 stub.restore(); 74 }); 75 76 const URL_EXAMPLE = "https://example.com"; 77 const tab = BrowserTestUtils.addTab(gBrowser, URL_EXAMPLE); 78 const browser = gBrowser.getBrowserForTab(tab); 79 await BrowserTestUtils.browserLoaded(browser); 80 81 await RemoteSettings(bypassCollectionName).emit("sync", {}); 82 83 await SpecialPowers.spawn( 84 browser, 85 [ 86 removeSecondColon.toString(), 87 checkSerializationMissingSecondColonChild.toString(), 88 checkInputAndSerializationMatchChild.toString(), 89 ], 90 (rscSource, csmscSource, ciasmcSource) => { 91 /* eslint-disable no-eval */ 92 // eslint-disable-next-line no-unused-vars 93 let removeSecondColon = eval(`(${rscSource})`); // used by checker fns 94 let checkSerializationMissingSecondColonChild = eval(`(${csmscSource})`); 95 let checkInputAndSerializationMatchChild = eval(`(${ciasmcSource})`); 96 /* eslint-enable no-eval */ 97 98 // sanity check 99 checkInputAndSerializationMatchChild("https://example.com/"); 100 101 // nsStanardURL 102 checkSerializationMissingSecondColonChild("https://https://example.com"); 103 104 // no-bypass protocol uses defaultURI 105 checkSerializationMissingSecondColonChild( 106 "defaulturischeme://https://example.com" 107 ); 108 109 // an unknown protocol in the bypass list (remote settings) uses simpleURI 110 checkInputAndSerializationMatchChild( 111 "testsyncscheme://https://example.com" 112 ); 113 114 // pref-specified scheme bypass uses simpleURI 115 checkInputAndSerializationMatchChild( 116 "simpleprotocol://https://example.com" 117 ); 118 } 119 ); 120 121 // Cleanup 122 stub.restore(); 123 BrowserTestUtils.removeTab(tab); 124 }); 125 126 // long string 127 add_task(async function test_bypass_list_update_sync_parent_long_string() { 128 let longSchemeList = ["testinitscheme", "testsyncscheme"]; 129 let num = 100; 130 for (let i = 0; i <= num; i++) { 131 longSchemeList.push(`scheme${i}`); 132 } 133 134 let newData = []; 135 for (const i in longSchemeList) { 136 newData.push({ id: i, scheme: longSchemeList[i] }); 137 } 138 139 const settings = await RemoteSettings(bypassCollectionName); 140 let stub = sinon.stub(settings, "get").returns(newData); 141 registerCleanupFunction(async function () { 142 stub.restore(); 143 }); 144 145 await RemoteSettings(bypassCollectionName).emit("sync", {}); 146 147 runParentTestSuite(); 148 149 // another unknown protocol in the bypass list, near the middle of long str 150 checkInputAndSerializationMatch("scheme50://https://example.com"); 151 152 // another unknown protocol in the bypass list, at the end of the long str 153 checkInputAndSerializationMatch("scheme100://https://example.com"); 154 155 stub.restore(); 156 });