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