| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto
r-protocol-test.js"></script> | 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto
r-protocol-test.js"></script> |
| 4 <script type="text/javascript" src="../../http/tests/inspector-protocol/tracing-
test.js"></script> |
| 4 <script> | 5 <script> |
| 5 | 6 |
| 6 function testFunction() | 7 function performActions(callback) |
| 7 { | 8 { |
| 8 var timerId = setTimeout(function() | 9 var timerId = setTimeout(function() |
| 9 { | 10 { |
| 10 evaluateInFrontend("InspectorTest.testFunctionTimerFired(" + timerId + "
, " + timerId2 + ")"); | 11 evaluateInFrontend("InspectorTest.testFunctionTimerFired(" + timerId + "
, " + timerId2 + ")"); |
| 12 callback(); |
| 11 }, 0); | 13 }, 0); |
| 12 | 14 |
| 13 var timerId2 = setTimeout(function() { }, 0); | 15 var timerId2 = setTimeout(function() { }, 0); |
| 14 clearTimeout(timerId2); | 16 clearTimeout(timerId2); |
| 15 return timerId; | 17 return timerId; |
| 16 } | 18 } |
| 17 | 19 |
| 18 function test() | 20 function test() |
| 19 { | 21 { |
| 20 InspectorTest.eventHandler["Tracing.dataCollected"] = dataCollected; | 22 InspectorTest.invokeAsyncWithTracing("performActions", finish); |
| 21 InspectorTest.eventHandler["Tracing.tracingComplete"] = tracingComplete; | |
| 22 InspectorTest.sendCommand("Tracing.start", { "categories" : "disabled-by-def
ault-devtools.timeline", "type": "" }, onStart); | |
| 23 | 23 |
| 24 var firedTimerId; | 24 var firedTimerId; |
| 25 var removedTimerId; | 25 var removedTimerId; |
| 26 InspectorTest.testFunctionTimerFired = function(timerId1, timerId2) | 26 InspectorTest.testFunctionTimerFired = function(timerId1, timerId2) |
| 27 { | 27 { |
| 28 firedTimerId = timerId1; | 28 firedTimerId = timerId1; |
| 29 removedTimerId = timerId2; | 29 removedTimerId = timerId2; |
| 30 InspectorTest.log("SUCCESS: testFunctionTimerFired"); | 30 InspectorTest.log("SUCCESS: testFunctionTimerFired"); |
| 31 InspectorTest.sendCommand("Tracing.end", { }, onStop); | |
| 32 } | 31 } |
| 33 | 32 |
| 34 function onStart(response) | 33 function finish(devtoolsEvents) |
| 35 { | 34 { |
| 36 InspectorTest.log("Recording started"); | |
| 37 InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunct
ion()" }); | |
| 38 } | |
| 39 | |
| 40 var devtoolsEvents = []; | |
| 41 function dataCollected(reply) | |
| 42 { | |
| 43 var allEvents = reply.params.value; | |
| 44 devtoolsEvents = devtoolsEvents.concat(allEvents.filter(function(e) | |
| 45 { | |
| 46 return e.cat === "disabled-by-default-devtools.timeline"; | |
| 47 })); | |
| 48 } | |
| 49 | |
| 50 function tracingComplete(event) | |
| 51 { | |
| 52 InspectorTest.log("Tracing complete"); | |
| 53 | |
| 54 function hasTimerId(id, e) { return e.args.data.timerId === id} | 35 function hasTimerId(id, e) { return e.args.data.timerId === id} |
| 55 | 36 |
| 56 var installTimer1 = findEvent("TimerInstall", "I", hasTimerId.bind(this,
firedTimerId)); | 37 var installTimer1 = InspectorTest.findEvent("TimerInstall", "I", hasTime
rId.bind(this, firedTimerId)); |
| 57 var installTimer2 = findEvent("TimerInstall", "I", hasTimerId.bind(this,
removedTimerId)); | 38 var installTimer2 = InspectorTest.findEvent("TimerInstall", "I", hasTime
rId.bind(this, removedTimerId)); |
| 58 | 39 |
| 59 InspectorTest.assert(!!installTimer1.args.data.frame, "TimerInstall fram
e"); | 40 InspectorTest.assert(!!installTimer1.args.data.frame, "TimerInstall fram
e"); |
| 60 InspectorTest.assertEquals(installTimer1.args.data.frame, installTimer2.
args.data.frame, "TimerInstall frame match"); | 41 InspectorTest.assertEquals(installTimer1.args.data.frame, installTimer2.
args.data.frame, "TimerInstall frame match"); |
| 61 | 42 |
| 62 findEvent("TimerRemove", "I", hasTimerId.bind(this, removedTimerId)); | 43 InspectorTest.findEvent("TimerRemove", "I", hasTimerId.bind(this, remove
dTimerId)); |
| 63 findEvent("TimerFire", "X", hasTimerId.bind(this, firedTimerId)); | 44 InspectorTest.findEvent("TimerFire", "X", hasTimerId.bind(this, firedTim
erId)); |
| 64 | 45 |
| 65 InspectorTest.log("SUCCESS: found all expected events."); | 46 InspectorTest.log("SUCCESS: found all expected events."); |
| 66 InspectorTest.completeTest(); | 47 InspectorTest.completeTest(); |
| 67 } | 48 } |
| 68 | |
| 69 function findEvent(name, ph, condition) | |
| 70 { | |
| 71 for (var i = 0; i < devtoolsEvents.length; i++) { | |
| 72 var e = devtoolsEvents[i]; | |
| 73 if (e.name === name && e.ph === ph && (!condition || condition(e))) | |
| 74 return e; | |
| 75 } | |
| 76 throw new Error("Couldn't find event " + name + " / " + ph + "\n\n in "
+ JSON.stringify(devtoolsEvents, null, 2)); | |
| 77 } | |
| 78 | |
| 79 function onStop(response) | |
| 80 { | |
| 81 InspectorTest.log("Recording stopped"); | |
| 82 } | |
| 83 } | 49 } |
| 84 </script> | 50 </script> |
| 85 </head> | 51 </head> |
| 86 <body onLoad="runTest();"> | 52 <body onLoad="runTest();"> |
| 87 <div id="myDiv">DIV</div> | 53 <div id="myDiv">DIV</div> |
| 88 </body> | 54 </body> |
| 89 </html> | 55 </html> |
| OLD | NEW |