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 /toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html | |
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 'toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html')
-rw-r--r-- | toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html | 311 |
1 files changed, 311 insertions, 0 deletions
diff --git a/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html b/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html new file mode 100644 index 000000000..d14e85a25 --- /dev/null +++ b/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html @@ -0,0 +1,311 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for nsIContentPrefService2 in child processes</title> + <script type="application/javascript" + src="/tests/SimpleTest/SimpleTest.js"> + </script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> + + <script type="application/javascript;version=1.8"> + "use strict"; + + SimpleTest.waitForExplicitFinish(); + + const childFrameURL = + "data:text/html,<!DOCTYPE HTML><html><body></body></html>"; + + function childFrameScript(isFramePrivate) { + "use strict"; + + function Tester(resultArray) { + this.results = []; + } + + Tester.prototype.is = + function(a, b, note) { + this.results.push([a === b, note + " (" + a + ", " + b + ")"]); + }; + Tester.prototype.ok = + function(b, note) { + this.results.push([b != false, note]); + }; + + var cps = Components.classes["@mozilla.org/content-pref/service;1"] + .getService(Components.interfaces.nsIContentPrefService2); + + let test = null; + function* test1(message) { + let tester = new Tester(); + + tester.ok(cps !== null, "got the content pref service"); + + cps.setGlobal("testing", 42, null, { + handleCompletion: function(reason) { + tester.is(reason, 0, "set a pref?"); + test.next(); + } + }); + + yield; + + let numResults = 0; + cps.getGlobal("testing", null, { + handleResult: function(pref) { + numResults++; + tester.is(pref.name, "testing", "pref has the right name"); + tester.is(pref.value, 42, "pref has the right value"); + }, + + handleCompletion: function(reason) { + tester.is(reason, 0, "get a pref?"); + tester.is(numResults, 1, "got the right number of prefs"); + tester.is(test.next().done, true, "done with test1"); + message.target.sendAsyncMessage("testRemoteContentPrefs:test1Finished", + { results: tester.results }); + } + }); + + yield; + } + + function* test2(message) { + let tester = new Tester(); + + let observer; + let removed = false; + cps.addObserverForName("testName", observer = { + onContentPrefSet: function(group, name, value, isPrivate) { + if (removed) { + message.target.sendAsyncMessage("testRemoteContentPrefs:fail", + { reason: "unexpected notification" }); + } + tester.is(group, null, "group should be null"); + tester.is(name, "testName", "should only see testName"); + tester.is(value, 42, "value should be correct"); + tester.is(isPrivate, isFramePrivate, "privacy should match"); + + message.target.sendAsyncMessage("testRemoteContentPrefs:test2poke2", {}) + }, + + onContentPrefRemoved: function(group, name, isPrivate) { + tester.is(group, null, "group should be null"); + tester.is(name, "testName"); + tester.is(isPrivate, isFramePrivate, "privacy should match"); + tester.is(test.next().done, true, "should be done with test2"); + + cps.removeObserverForName("testName", observer); + removed = true; + + message.target.sendAsyncMessage("testRemoteContentPrefs:test2Finished", + { results: tester.results }); + } + }); + + message.target.sendAsyncMessage("testRemoteContentPrefs:test2poke", {}); + yield; + } + + function* test3(message) { + let tester = new Tester(); + + cps.setGlobal("testName", 42, null, { + handleCompletion: function(reason) { + tester.is(reason, 0, "set a pref"); + cps.set("http://mochi.test", "testpref", "str", null, { + handleCompletion: function(reason) { + tester.is(reason, 0, "set a pref"); + test.next(); + } + }); + } + }); + + yield; + + cps.removeByDomain("http://mochi.test", null, { + handleCompletion: function(reason) { + tester.is(reason, 0, "remove succeeded"); + cps.getByDomainAndName("http://mochi.test", "testpref", null, { + handleResult: function() { + message.target.sendAsyncMessage("testRemoteContentPrefs:fail", + { reason: "got removed pref in test3" }); + }, + handleCompletion: function() { + test.next(); + } + }); + } + }); + + yield; + + message.target.sendAsyncMessage("testRemoteContentPrefs:test3Finished", + { results: tester.results }); + } + + function* test4(message) { + let tester = new Tester(); + + let prefObserver = { + onContentPrefSet: function(group, name, value, isPrivate) { + test.next({ group: group, name: name, value: value, isPrivate: isPrivate }); + }, + onContentPrefRemoved: function(group, name, isPrivate) { + test.next({ group: group, name: name, isPrivate: isPrivate }); + } + }; + + addMessageListener("testRemoteContentPrefs:prefResults", (msg) => { + test.next(msg.data.results); + }); + + cps.addObserverForName("test", prefObserver); + + cps.set("http://mochi.test", "test", 42, { usePrivateBrowsing: true }); + let event = yield; + tester.is(event.name, "test"); + tester.is(event.isPrivate, true); + + message.target.sendAsyncMessage("testRemoteContentPrefs:getPref", + { group: "http://mochi.test", name: "test" }); + + let results = yield; + tester.is(results.length, 0, "should not have seen the pb pref"); + + message.target.sendAsyncMessage("testRemoteContentPrefs:test4Finished", + { results: tester.results }); + } + + addMessageListener("testRemoteContentPrefs:test1", function(message) { + test = test1(message); + test.next(); + }); + addMessageListener("testRemoteContentPrefs:test2", function(message) { + test = test2(message); + test.next(); + }); + addMessageListener("testRemoteContentPrefs:test3", function(message) { + test = test3(message); + test.next(); + }); + addMessageListener("testRemoteContentPrefs:test4", function(message) { + test = test4(message); + test.next(); + }); + } + + function processResults(results) { + for (let i of results) { + ok(...i); + } + } + + let test; + function* testStructure(mm, isPrivate, callback) { + let lastResult; + + function testDone(msg) { + test.next(msg.data); + } + + mm.addMessageListener("testRemoteContentPrefs:test1Finished", testDone); + mm.addMessageListener("testRemoteContentPrefs:test2Finished", testDone); + mm.addMessageListener("testRemoteContentPrefs:test3Finished", testDone); + mm.addMessageListener("testRemoteContentPrefs:test4Finished", testDone); + + mm.addMessageListener("testRemoteContentPrefs:fail", function(msg) { + ok(false, msg.data.reason); + }); + + mm.sendAsyncMessage("testRemoteContentPrefs:test1", {}); + lastResult = yield; + processResults(lastResult.results); + + var cps = SpecialPowers.Cc["@mozilla.org/content-pref/service;1"] + .getService(SpecialPowers.Ci.nsIContentPrefService2); + mm.sendAsyncMessage("testRemoteContentPrefs:test2", {}); + mm.addMessageListener("testRemoteContentPrefs:test2poke", function() { + cps.setGlobal("testName", 42, {usePrivateBrowsing: isPrivate}); + }); + mm.addMessageListener("testRemoteContentPrefs:test2poke2", function() { + cps.removeGlobal("testName", {usePrivateBrowsing: isPrivate}); + }); + + lastResult = yield; + processResults(lastResult.results); + + mm.sendAsyncMessage("testRemoteContentPrefs:test3", {}); + lastResult = yield; + processResults(lastResult.results); + + mm.addMessageListener("testRemoteContentPrefs:getPref", function(msg) { + let results = []; + cps.getByDomainAndName(msg.data.group, msg.data.name, null, { + handleResult: function(pref) { + results.push(pref); + }, + handleCompletion: function(reason) { + mm.sendAsyncMessage("testRemoteContentPrefs:prefResults", + { results: results }); + } + }); + }); + + mm.sendAsyncMessage("testRemoteContentPrefs:test4", {}); + lastResult = yield; + processResults(lastResult.results); + + document.getElementById('iframe').remove(); + setTimeout(callback, 0); + } + + function runTest(isPrivate, callback) { + info("testing with isPrivate=" + isPrivate); + let iframe = document.createElement("iframe"); + SpecialPowers.wrap(iframe).mozbrowser = true; + if (isPrivate) { + SpecialPowers.wrap(iframe).mozprivatebrowsing = true; + } + iframe.id = "iframe"; + iframe.src = childFrameURL; + + iframe.addEventListener("mozbrowserloadend", function() { + info("Got iframe load event."); + let mm = SpecialPowers.getBrowserFrameMessageManager(iframe); + mm.loadFrameScript("data:,(" + childFrameScript.toString() + ")(" + isPrivate + ");", + false); + + test = testStructure(mm, isPrivate, callback); + test.next(); + }); + + document.body.appendChild(iframe); + } + + function runTests() { + info("Browser prefs set."); + runTest(false, function() { + runTest(true, function() { + SimpleTest.finish(); + }); + }); + } + + addEventListener("load", function() { + info("Got load event."); + + SpecialPowers.addPermission("browser", true, document); + SpecialPowers.pushPrefEnv({ + "set": [ + ["dom.ipc.browser_frames.oop_by_default", true], + ["dom.mozBrowserFramesEnabled", true], + ["browser.pagethumbnails.capturing_disabled", true] + ] + }, runTests); + }); + </script> +</body> +</html> |