test_nsjsinspector.js (1909B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test the basic functionality of the nsIJSInspector component. 7 var gCount = 0; 8 const MAX = 10; 9 10 var inspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); 11 12 // Emulate 10 simultaneously-debugged windows from 3 separate client connections. 13 var requestor = count => ({ 14 url: "http://foo/bar/" + count, 15 connection: "conn" + (count % 3), 16 }); 17 18 function run_test() { 19 test_nesting(); 20 } 21 22 function test_nesting() { 23 Assert.equal(inspector.eventLoopNestLevel, 0); 24 25 Services.tm.dispatchToMainThread({ run: enterEventLoop }); 26 27 Assert.equal(inspector.enterNestedEventLoop(requestor(gCount)), 0); 28 Assert.equal(inspector.eventLoopNestLevel, 0); 29 Assert.equal(inspector.lastNestRequestor, null); 30 } 31 32 function enterEventLoop() { 33 if (gCount++ < MAX) { 34 Services.tm.dispatchToMainThread({ run: enterEventLoop }); 35 36 Object.create(requestor(gCount)); 37 38 Assert.equal(inspector.eventLoopNestLevel, gCount); 39 Assert.equal(inspector.lastNestRequestor.url, requestor(gCount - 1).url); 40 Assert.equal( 41 inspector.lastNestRequestor.connection, 42 requestor(gCount - 1).connection 43 ); 44 Assert.equal(inspector.enterNestedEventLoop(requestor(gCount)), gCount); 45 } else { 46 Assert.equal(gCount, MAX + 1); 47 Services.tm.dispatchToMainThread({ run: exitEventLoop }); 48 } 49 } 50 51 function exitEventLoop() { 52 if (inspector.lastNestRequestor != null) { 53 Assert.equal(inspector.lastNestRequestor.url, requestor(gCount - 1).url); 54 Assert.equal( 55 inspector.lastNestRequestor.connection, 56 requestor(gCount - 1).connection 57 ); 58 if (gCount-- > 1) { 59 Services.tm.dispatchToMainThread({ run: exitEventLoop }); 60 } 61 62 Assert.equal(inspector.exitNestedEventLoop(), gCount); 63 Assert.equal(inspector.eventLoopNestLevel, gCount); 64 } 65 }