|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test the eventLoopLag actor. |
|
6 */ |
|
7 |
|
8 "use strict"; |
|
9 |
|
10 function run_test() |
|
11 { |
|
12 let {EventLoopLagFront} = devtools.require("devtools/server/actors/eventlooplag"); |
|
13 |
|
14 DebuggerServer.init(function () { return true; }); |
|
15 DebuggerServer.addBrowserActors(); |
|
16 |
|
17 // As seen in EventTracer.cpp |
|
18 let threshold = 20; |
|
19 let interval = 10; |
|
20 |
|
21 |
|
22 let front; |
|
23 let client = new DebuggerClient(DebuggerServer.connectPipe()); |
|
24 |
|
25 // Start tracking event loop lags. |
|
26 client.connect(function () { |
|
27 client.listTabs(function(resp) { |
|
28 front = new EventLoopLagFront(client, resp); |
|
29 front.start().then(success => { |
|
30 do_check_true(success); |
|
31 front.once("event-loop-lag", gotLagEvent); |
|
32 do_execute_soon(lag); |
|
33 }); |
|
34 }); |
|
35 }); |
|
36 |
|
37 // Force a lag |
|
38 function lag() { |
|
39 let start = new Date(); |
|
40 let duration = threshold + interval + 1; |
|
41 while (true) { |
|
42 if (((new Date()) - start) > duration) { |
|
43 break; |
|
44 } |
|
45 } |
|
46 } |
|
47 |
|
48 // Got a lag event. The test will time out if the actor |
|
49 // fails to detect the lag. |
|
50 function gotLagEvent(time) { |
|
51 do_print("lag: " + time); |
|
52 do_check_true(time >= threshold); |
|
53 front.stop().then(() => { |
|
54 finishClient(client); |
|
55 }); |
|
56 } |
|
57 |
|
58 do_test_pending(); |
|
59 } |