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
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 | setPref('dom.ipc.processPrelaunch.testMode', true); // For testing deadlock. |
michael@0 | 55 | |
michael@0 | 56 | function runTest() |
michael@0 | 57 | { |
michael@0 | 58 | // Shutdown preallocated process. |
michael@0 | 59 | SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false); |
michael@0 | 60 | let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"] |
michael@0 | 61 | .getService(SpecialPowers.Ci.nsISyncMessageSender); |
michael@0 | 62 | let seenNuwaReady = false; |
michael@0 | 63 | let msgHandler = { |
michael@0 | 64 | receiveMessage: function receiveMessage(msg) { |
michael@0 | 65 | msg = SpecialPowers.wrap(msg); |
michael@0 | 66 | if (msg.name == 'TEST-ONLY:nuwa-ready') { |
michael@0 | 67 | ok(true, "Got nuwa-ready"); |
michael@0 | 68 | is(seenNuwaReady, false, "Already received nuwa ready"); |
michael@0 | 69 | seenNuwaReady = true; |
michael@0 | 70 | } else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') { |
michael@0 | 71 | ok(true, "Got nuwa-add-new-process"); |
michael@0 | 72 | is(seenNuwaReady, true, "Receive nuwa-add-new-process before nuwa-ready"); |
michael@0 | 73 | testEnd(); |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | }; |
michael@0 | 77 | let timeout = setTimeout(function() { |
michael@0 | 78 | ok(false, "Nuwa process is not launched"); |
michael@0 | 79 | testEnd(); |
michael@0 | 80 | }, 90000); |
michael@0 | 81 | |
michael@0 | 82 | function testEnd() { |
michael@0 | 83 | cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler); |
michael@0 | 84 | cpmm.removeMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler); |
michael@0 | 85 | clearTimeout(timeout); |
michael@0 | 86 | setPref('dom.ipc.processPrelaunch.testMode', false); |
michael@0 | 87 | SimpleTest.finish(); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | cpmm.addMessageListener("TEST-ONLY:nuwa-ready", msgHandler); |
michael@0 | 91 | cpmm.addMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler); |
michael@0 | 92 | |
michael@0 | 93 | |
michael@0 | 94 | // Setting this pref to true should cause us to prelaunch a process. |
michael@0 | 95 | SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | testLoader.onTestReady = runTest; |
michael@0 | 99 | </script> |
michael@0 | 100 | </body> |
michael@0 | 101 | </html> |