dom/ipc/tests/test_NuwaProcessCreation.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 Test if Nuwa process created successfully.
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 9 </head>
michael@0 10 <body>
michael@0 11
michael@0 12 <script type="application/javascript;version=1.7">
michael@0 13 "use strict";
michael@0 14
michael@0 15 SimpleTest.waitForExplicitFinish();
michael@0 16
michael@0 17 function TestLoader() {}
michael@0 18
michael@0 19 TestLoader.prototype = {
michael@0 20 _waitingTask: 0,
michael@0 21 onTestReady: null,
michael@0 22 unlockTestReady: function() {
michael@0 23 this._waitingTask--;
michael@0 24 this._maybeLoadTest();
michael@0 25 },
michael@0 26 lockTestReady: function() {
michael@0 27 this._waitingTask++;
michael@0 28 },
michael@0 29 _maybeLoadTest: function() {
michael@0 30 if (this._waitingTask == 0) {
michael@0 31 this.onTestReady();
michael@0 32 }
michael@0 33 }
michael@0 34 }
michael@0 35
michael@0 36 var testLoader = new TestLoader();
michael@0 37 testLoader.lockTestReady();
michael@0 38 window.addEventListener('load', function() {
michael@0 39 testLoader.unlockTestReady();
michael@0 40 });
michael@0 41
michael@0 42 function setPref(pref, value) {
michael@0 43 testLoader.lockTestReady();
michael@0 44 if (value !== undefined && value !== null) {
michael@0 45 SpecialPowers.pushPrefEnv({'set': [[pref, value]]}, function() { testLoader.unlockTestReady(); });
michael@0 46 } else {
michael@0 47 SpecialPowers.pushPrefEnv({'clear': [[pref]]}, function() { testLoader.unlockTestReady(); });
michael@0 48 }
michael@0 49 }
michael@0 50
michael@0 51 setPref('dom.ipc.processPriorityManager.testMode', true);
michael@0 52 setPref('dom.ipc.processPriorityManager.enabled', true);
michael@0 53 setPref('dom.ipc.processPriorityManager.backgroundLRUPoolLevels', 2);
michael@0 54
michael@0 55 function runTest()
michael@0 56 {
michael@0 57 // Shutdown preallocated process.
michael@0 58 SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false);
michael@0 59 let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"]
michael@0 60 .getService(SpecialPowers.Ci.nsISyncMessageSender);
michael@0 61 let seenNuwaReady = false;
michael@0 62 let msgHandler = {
michael@0 63 receiveMessage: function receiveMessage(msg) {
michael@0 64 msg = SpecialPowers.wrap(msg);
michael@0 65 if (msg.name == 'TEST-ONLY:nuwa-ready') {
michael@0 66 ok(true, "Got nuwa-ready");
michael@0 67 is(seenNuwaReady, false, "Already received nuwa ready");
michael@0 68 seenNuwaReady = true;
michael@0 69 } else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') {
michael@0 70 ok(true, "Got nuwa-add-new-process");
michael@0 71 is(seenNuwaReady, true, "Receive nuwa-add-new-process before nuwa-ready");
michael@0 72 testEnd();
michael@0 73 }
michael@0 74 }
michael@0 75 };
michael@0 76 let timeout = setTimeout(function() {
michael@0 77 ok(false, "Nuwa process is not launched");
michael@0 78 testEnd();
michael@0 79 }, 60000);
michael@0 80
michael@0 81 function testEnd() {
michael@0 82 cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
michael@0 83 cpmm.removeMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
michael@0 84 clearTimeout(timeout);
michael@0 85 SimpleTest.finish();
michael@0 86 }
michael@0 87
michael@0 88 cpmm.addMessageListener("TEST-ONLY:nuwa-ready", msgHandler);
michael@0 89 cpmm.addMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler);
michael@0 90
michael@0 91
michael@0 92 // Setting this pref to true should cause us to prelaunch a process.
michael@0 93 SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true);
michael@0 94 }
michael@0 95
michael@0 96 testLoader.onTestReady = runTest;
michael@0 97 </script>
michael@0 98 </body>
michael@0 99 </html>

mercurial