1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/ipc/tests/test_NuwaProcessCreation.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +Test if Nuwa process created successfully. 1.8 +--> 1.9 +<head> 1.10 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.12 +</head> 1.13 +<body> 1.14 + 1.15 +<script type="application/javascript;version=1.7"> 1.16 +"use strict"; 1.17 + 1.18 +SimpleTest.waitForExplicitFinish(); 1.19 + 1.20 +function TestLoader() {} 1.21 + 1.22 +TestLoader.prototype = { 1.23 + _waitingTask: 0, 1.24 + onTestReady: null, 1.25 + unlockTestReady: function() { 1.26 + this._waitingTask--; 1.27 + this._maybeLoadTest(); 1.28 + }, 1.29 + lockTestReady: function() { 1.30 + this._waitingTask++; 1.31 + }, 1.32 + _maybeLoadTest: function() { 1.33 + if (this._waitingTask == 0) { 1.34 + this.onTestReady(); 1.35 + } 1.36 + } 1.37 +} 1.38 + 1.39 +var testLoader = new TestLoader(); 1.40 +testLoader.lockTestReady(); 1.41 +window.addEventListener('load', function() { 1.42 + testLoader.unlockTestReady(); 1.43 +}); 1.44 + 1.45 +function setPref(pref, value) { 1.46 + testLoader.lockTestReady(); 1.47 + if (value !== undefined && value !== null) { 1.48 + SpecialPowers.pushPrefEnv({'set': [[pref, value]]}, function() { testLoader.unlockTestReady(); }); 1.49 + } else { 1.50 + SpecialPowers.pushPrefEnv({'clear': [[pref]]}, function() { testLoader.unlockTestReady(); }); 1.51 + } 1.52 +} 1.53 + 1.54 +setPref('dom.ipc.processPriorityManager.testMode', true); 1.55 +setPref('dom.ipc.processPriorityManager.enabled', true); 1.56 +setPref('dom.ipc.processPriorityManager.backgroundLRUPoolLevels', 2); 1.57 + 1.58 +function runTest() 1.59 +{ 1.60 + // Shutdown preallocated process. 1.61 + SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false); 1.62 + let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"] 1.63 + .getService(SpecialPowers.Ci.nsISyncMessageSender); 1.64 + let seenNuwaReady = false; 1.65 + let msgHandler = { 1.66 + receiveMessage: function receiveMessage(msg) { 1.67 + msg = SpecialPowers.wrap(msg); 1.68 + if (msg.name == 'TEST-ONLY:nuwa-ready') { 1.69 + ok(true, "Got nuwa-ready"); 1.70 + is(seenNuwaReady, false, "Already received nuwa ready"); 1.71 + seenNuwaReady = true; 1.72 + } else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') { 1.73 + ok(true, "Got nuwa-add-new-process"); 1.74 + is(seenNuwaReady, true, "Receive nuwa-add-new-process before nuwa-ready"); 1.75 + testEnd(); 1.76 + } 1.77 + } 1.78 + }; 1.79 + let timeout = setTimeout(function() { 1.80 + ok(false, "Nuwa process is not launched"); 1.81 + testEnd(); 1.82 + }, 60000); 1.83 + 1.84 + function testEnd() { 1.85 + cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler); 1.86 + cpmm.removeMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler); 1.87 + clearTimeout(timeout); 1.88 + SimpleTest.finish(); 1.89 + } 1.90 + 1.91 + cpmm.addMessageListener("TEST-ONLY:nuwa-ready", msgHandler); 1.92 + cpmm.addMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler); 1.93 + 1.94 + 1.95 + // Setting this pref to true should cause us to prelaunch a process. 1.96 + SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true); 1.97 +} 1.98 + 1.99 +testLoader.onTestReady = runTest; 1.100 +</script> 1.101 +</body> 1.102 +</html>