1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/ipc/tests/test_NuwaProcessDeadlock.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 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 +setPref('dom.ipc.processPrelaunch.testMode', true); // For testing deadlock. 1.58 + 1.59 +function runTest() 1.60 +{ 1.61 + // Shutdown preallocated process. 1.62 + SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', false); 1.63 + let cpmm = SpecialPowers.Cc["@mozilla.org/childprocessmessagemanager;1"] 1.64 + .getService(SpecialPowers.Ci.nsISyncMessageSender); 1.65 + let seenNuwaReady = false; 1.66 + let msgHandler = { 1.67 + receiveMessage: function receiveMessage(msg) { 1.68 + msg = SpecialPowers.wrap(msg); 1.69 + if (msg.name == 'TEST-ONLY:nuwa-ready') { 1.70 + ok(true, "Got nuwa-ready"); 1.71 + is(seenNuwaReady, false, "Already received nuwa ready"); 1.72 + seenNuwaReady = true; 1.73 + } else if (msg.name == 'TEST-ONLY:nuwa-add-new-process') { 1.74 + ok(true, "Got nuwa-add-new-process"); 1.75 + is(seenNuwaReady, true, "Receive nuwa-add-new-process before nuwa-ready"); 1.76 + testEnd(); 1.77 + } 1.78 + } 1.79 + }; 1.80 + let timeout = setTimeout(function() { 1.81 + ok(false, "Nuwa process is not launched"); 1.82 + testEnd(); 1.83 + }, 90000); 1.84 + 1.85 + function testEnd() { 1.86 + cpmm.removeMessageListener("TEST-ONLY:nuwa-ready", msgHandler); 1.87 + cpmm.removeMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler); 1.88 + clearTimeout(timeout); 1.89 + setPref('dom.ipc.processPrelaunch.testMode', false); 1.90 + SimpleTest.finish(); 1.91 + } 1.92 + 1.93 + cpmm.addMessageListener("TEST-ONLY:nuwa-ready", msgHandler); 1.94 + cpmm.addMessageListener("TEST-ONLY:nuwa-add-new-process", msgHandler); 1.95 + 1.96 + 1.97 + // Setting this pref to true should cause us to prelaunch a process. 1.98 + SpecialPowers.setBoolPref('dom.ipc.processPrelaunch.enabled', true); 1.99 +} 1.100 + 1.101 +testLoader.onTestReady = runTest; 1.102 +</script> 1.103 +</body> 1.104 +</html>