diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /browser/base/content/test/general/browser_remoteTroubleshoot.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'browser/base/content/test/general/browser_remoteTroubleshoot.js')
-rw-r--r-- | browser/base/content/test/general/browser_remoteTroubleshoot.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/browser/base/content/test/general/browser_remoteTroubleshoot.js b/browser/base/content/test/general/browser_remoteTroubleshoot.js new file mode 100644 index 000000000..5c939dbd0 --- /dev/null +++ b/browser/base/content/test/general/browser_remoteTroubleshoot.js @@ -0,0 +1,93 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +var {WebChannel} = Cu.import("resource://gre/modules/WebChannel.jsm", {}); + +const TEST_URL_TAIL = "example.com/browser/browser/base/content/test/general/test_remoteTroubleshoot.html" +const TEST_URI_GOOD = Services.io.newURI("https://" + TEST_URL_TAIL, null, null); +const TEST_URI_BAD = Services.io.newURI("http://" + TEST_URL_TAIL, null, null); +const TEST_URI_GOOD_OBJECT = Services.io.newURI("https://" + TEST_URL_TAIL + "?object", null, null); + +// Creates a one-shot web-channel for the test data to be sent back from the test page. +function promiseChannelResponse(channelID, originOrPermission) { + return new Promise((resolve, reject) => { + let channel = new WebChannel(channelID, originOrPermission); + channel.listen((id, data, target) => { + channel.stopListening(); + resolve(data); + }); + }); +} + +// Loads the specified URI in a new tab and waits for it to send us data on our +// test web-channel and resolves with that data. +function promiseNewChannelResponse(uri) { + let channelPromise = promiseChannelResponse("test-remote-troubleshooting-backchannel", + uri); + let tab = gBrowser.loadOneTab(uri.spec, { inBackground: false }); + return promiseTabLoaded(tab).then( + () => channelPromise + ).then(data => { + gBrowser.removeTab(tab); + return data; + }); +} + +add_task(function*() { + // We haven't set a permission yet - so even the "good" URI should fail. + let got = yield promiseNewChannelResponse(TEST_URI_GOOD); + // Should have no data. + Assert.ok(got.message === undefined, "should have failed to get any data"); + + // Add a permission manager entry for our URI. + Services.perms.add(TEST_URI_GOOD, + "remote-troubleshooting", + Services.perms.ALLOW_ACTION); + registerCleanupFunction(() => { + Services.perms.remove(TEST_URI_GOOD, "remote-troubleshooting"); + }); + + // Try again - now we are expecting a response with the actual data. + got = yield promiseNewChannelResponse(TEST_URI_GOOD); + + // Check some keys we expect to always get. + Assert.ok(got.message.extensions, "should have extensions"); + Assert.ok(got.message.graphics, "should have graphics"); + + // Check we have channel and build ID info: + Assert.equal(got.message.application.buildID, Services.appinfo.appBuildID, + "should have correct build ID"); + + let updateChannel = null; + try { + updateChannel = Cu.import("resource://gre/modules/UpdateUtils.jsm", {}).UpdateUtils.UpdateChannel; + } catch (ex) {} + if (!updateChannel) { + Assert.ok(!('updateChannel' in got.message.application), + "should not have update channel where not available."); + } else { + Assert.equal(got.message.application.updateChannel, updateChannel, + "should have correct update channel."); + } + + + // And check some keys we know we decline to return. + Assert.ok(!got.message.modifiedPreferences, "should not have a modifiedPreferences key"); + Assert.ok(!got.message.crashes, "should not have crash info"); + + // Now a http:// URI - should get nothing even with the permission setup. + got = yield promiseNewChannelResponse(TEST_URI_BAD); + Assert.ok(got.message === undefined, "should have failed to get any data"); + + // Check that the page can send an object as well if it's in the whitelist + let webchannelWhitelistPref = "webchannel.allowObject.urlWhitelist"; + let origWhitelist = Services.prefs.getCharPref(webchannelWhitelistPref); + let newWhitelist = origWhitelist + " https://example.com"; + Services.prefs.setCharPref(webchannelWhitelistPref, newWhitelist); + registerCleanupFunction(() => { + Services.prefs.clearUserPref(webchannelWhitelistPref); + }); + got = yield promiseNewChannelResponse(TEST_URI_GOOD_OBJECT); + Assert.ok(got.message, "should have gotten some data back"); +}); |