1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/unit/test_threadlifetime-03.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Check that thread-lifetime grips last past a resume. 1.9 + */ 1.10 + 1.11 +var gDebuggee; 1.12 +var gClient; 1.13 +var gThreadClient; 1.14 + 1.15 +function run_test() 1.16 +{ 1.17 + initTestDebuggerServer(); 1.18 + gDebuggee = addTestGlobal("test-grips"); 1.19 + gClient = new DebuggerClient(DebuggerServer.connectPipe()); 1.20 + gClient.connect(function() { 1.21 + attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) { 1.22 + gThreadClient = aThreadClient; 1.23 + test_thread_lifetime(); 1.24 + }); 1.25 + }); 1.26 + do_test_pending(); 1.27 +} 1.28 + 1.29 +function test_thread_lifetime() 1.30 +{ 1.31 + // Get three thread-lifetime grips. 1.32 + gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) { 1.33 + let grips = []; 1.34 + 1.35 + let handler = function(aResponse) { 1.36 + if (aResponse.error) { 1.37 + do_check_eq(aResponse.error, ''); 1.38 + finishClient(gClient); 1.39 + } 1.40 + grips.push(aResponse.from); 1.41 + if (grips.length == 3) { 1.42 + test_release_many(grips); 1.43 + } 1.44 + }; 1.45 + for (let i = 0; i < 3; i++) { 1.46 + gClient.request({ to: aPacket.frame.arguments[i].actor, type: "threadGrip" }, 1.47 + handler); 1.48 + } 1.49 + }); 1.50 + 1.51 + gDebuggee.eval("(" + function() { 1.52 + function stopMe(arg1, arg2, arg3) { 1.53 + debugger; 1.54 + }; 1.55 + stopMe({obj: 1}, {obj: 2}, {obj: 3}); 1.56 + } + ")()"); 1.57 +} 1.58 + 1.59 +function test_release_many(grips) 1.60 +{ 1.61 + // Release the first two grips, leave the third alive. 1.62 + 1.63 + let release = [grips[0], grips[1]]; 1.64 + 1.65 + gThreadClient.releaseMany(release, function(aResponse) { 1.66 + // First two actors should return a noSuchActor error, because 1.67 + // they're gone now. 1.68 + gClient.request({ to: grips[0], type: "bogusRequest" }, function(aResponse) { 1.69 + do_check_eq(aResponse.error, "noSuchActor"); 1.70 + gClient.request({ to: grips[1], type: "bogusRequest" }, function(aResponse) { 1.71 + do_check_eq(aResponse.error, "noSuchActor"); 1.72 + 1.73 + // Last actor should return unrecognizedPacketType, because it's still 1.74 + // alive. 1.75 + gClient.request({ to: grips[2], type: "bogusRequest" }, function(aResponse) { 1.76 + do_check_eq(aResponse.error, "unrecognizedPacketType"); 1.77 + gThreadClient.resume(function() { 1.78 + finishClient(gClient); 1.79 + }); 1.80 + }); 1.81 + }); 1.82 + }); 1.83 + }); 1.84 +}