browser_remoteTroubleshoot.js (3312B)
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 var { WebChannel } = ChromeUtils.importESModule( 6 "resource://gre/modules/WebChannel.sys.mjs" 7 ); 8 const { PermissionTestUtils } = ChromeUtils.importESModule( 9 "resource://testing-common/PermissionTestUtils.sys.mjs" 10 ); 11 12 const TEST_URL_TAIL = 13 "example.com/browser/browser/base/content/test/general/test_remoteTroubleshoot.html"; 14 const TEST_URI_GOOD = Services.io.newURI("https://" + TEST_URL_TAIL); 15 const TEST_URI_BAD = Services.io.newURI("http://" + TEST_URL_TAIL); 16 17 // Loads the specified URI in a new tab and waits for it to send us data via 18 // the SpecialPowers.spawn() call and resolves with that data. 19 async function promiseNewChannelResponse(uri) { 20 let tab = gBrowser.addTab(uri.spec, { 21 inBackground: false, 22 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), 23 }); 24 await BrowserTestUtils.browserLoaded(tab.linkedBrowser); 25 26 let data = await SpecialPowers.spawn( 27 gBrowser.selectedBrowser, 28 [], 29 async function () { 30 return Cu.waiveXrays(content).remoteTroubleShootingResult; 31 } 32 ); 33 34 await gBrowser.removeTab(tab); 35 36 return data; 37 } 38 39 add_task(async function () { 40 // We haven't set a permission yet - so even the "good" URI should fail. 41 let got = await promiseNewChannelResponse(TEST_URI_GOOD); 42 // Should return an error. 43 Assert.strictEqual( 44 got.errno, 45 2, 46 "should have failed with errno 2, no such channel" 47 ); 48 49 // Add a permission manager entry for our URI. 50 PermissionTestUtils.add( 51 TEST_URI_GOOD, 52 "remote-troubleshooting", 53 Services.perms.ALLOW_ACTION 54 ); 55 registerCleanupFunction(() => { 56 PermissionTestUtils.remove(TEST_URI_GOOD, "remote-troubleshooting"); 57 }); 58 59 // Try again - now we are expecting a response with the actual data. 60 got = await promiseNewChannelResponse(TEST_URI_GOOD); 61 62 // Check some keys we expect to always get. 63 Assert.ok(got.addons, "should have addons"); 64 Assert.ok(got.graphics, "should have graphics"); 65 66 // Check we have channel and build ID info: 67 Assert.equal( 68 got.application.buildID, 69 Services.appinfo.appBuildID, 70 "should have correct build ID" 71 ); 72 73 let updateChannel = null; 74 try { 75 updateChannel = ChromeUtils.importESModule( 76 "resource://gre/modules/UpdateUtils.sys.mjs" 77 ).UpdateUtils.UpdateChannel; 78 } catch (ex) {} 79 if (!updateChannel) { 80 Assert.ok( 81 !("updateChannel" in got.application), 82 "should not have update channel where not available." 83 ); 84 } else { 85 Assert.equal( 86 got.application.updateChannel, 87 updateChannel, 88 "should have correct update channel." 89 ); 90 } 91 92 // And check some keys we know we decline to return. 93 Assert.ok( 94 !got.modifiedPreferences, 95 "should not have a modifiedPreferences key" 96 ); 97 Assert.ok( 98 !got.printingPreferences, 99 "should not have a printingPreferences key" 100 ); 101 Assert.ok(!got.crashes, "should not have crash info"); 102 103 // Now a http:// URI - should receive an error 104 got = await promiseNewChannelResponse(TEST_URI_BAD); 105 Assert.strictEqual( 106 got.errno, 107 2, 108 "should have failed with errno 2, no such channel" 109 ); 110 });