Cleanup after SK_SUPPORT_LEGACY_COLOR32_MATH rebaseline
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / throttler.html
blobaf743c6458988dd1e7db6d56ca3de7b89452a06e
1 <html>
2 <head>
3 <script src="../http/tests/inspector/inspector-test.js"></script>
4 <script>
6 function test()
8 var ProcessMock = function(name, runnable)
10 this._runnable = runnable;
11 this._processName = name;
12 this._call = this._call.bind(this);
13 this._call.finish = this._finish.bind(this);
14 this._call.processName = name;
17 ProcessMock.create = function(name, runnable)
19 var processMock = new ProcessMock(name, runnable);
20 return processMock._call;
23 ProcessMock.prototype = {
24 _call: function(finishCallback)
26 InspectorTest.addResult("Process '" + this._processName + "' STARTED.");
27 this._finishCallback = finishCallback;
28 if (this._runnable)
29 this._runnable.call(null);
32 _finish: function()
34 InspectorTest.addResult("Process '" + this._processName + "' FINISHED.");
35 this._finishCallback();
36 delete this._finishCallback();
40 var throttler = new WebInspector.Throttler(1989);
41 var timeoutMock = new InspectorTest.TimeoutMock();
42 throttler._setTimeout = timeoutMock.setTimeout;
43 throttler._clearTimeout = timeoutMock.clearTimeout;
44 InspectorTest.addSniffer(throttler, "schedule", logSchedule, true);
46 function testSimpleSchedule(next, runningProcess)
48 assertThrottlerIdle();
49 throttler.schedule(ProcessMock.create("operation #1"), false);
50 var process = ProcessMock.create("operation #2");
51 throttler.schedule(process);
52 if (runningProcess)
53 runningProcess.finish();
55 assertThrottlerTimeout();
56 timeoutMock.fireAllTimers();
57 process.finish();
58 next();
61 function testAsSoonAsPossibleOverrideTimeout(next, runningProcess)
63 assertThrottlerIdle();
64 throttler.schedule(ProcessMock.create("operation #1"));
65 var process = ProcessMock.create("operation #2");
66 throttler.schedule(process, true);
67 if (runningProcess)
68 runningProcess.finish();
70 assertThrottlerTimeout();
71 timeoutMock.fireAllTimers();
72 process.finish();
73 next();
76 function testAlwaysExecuteLastScheduled(next, runningProcess)
78 assertThrottlerIdle();
79 var process = null;
80 for (var i = 0; i < 4; ++i) {
81 process = ProcessMock.create("operation #" + i);
82 throttler.schedule(process, i % 2 === 0);
84 if (runningProcess)
85 runningProcess.finish();
87 assertThrottlerTimeout();
88 timeoutMock.fireAllTimers();
89 process.finish();
90 next();
93 InspectorTest.runTestSuite([
94 testSimpleSchedule,
96 testAsSoonAsPossibleOverrideTimeout,
98 testAlwaysExecuteLastScheduled,
100 function testSimpleScheduleDuringProcess(next)
102 var runningProcess = throttlerToRunningState();
103 testSimpleSchedule(next, runningProcess);
106 function testAsSoonAsPossibleOverrideDuringProcess(next)
108 var runningProcess = throttlerToRunningState();
109 testAsSoonAsPossibleOverrideTimeout(next, runningProcess);
112 function testAlwaysExecuteLastScheduledDuringProcess(next)
114 var runningProcess = throttlerToRunningState();
115 testAlwaysExecuteLastScheduled(next, runningProcess);
118 function testScheduleFromProcess(next)
120 var nextProcess;
121 assertThrottlerIdle();
122 var process = ProcessMock.create("operation #1", processBody);
123 throttler.schedule(process);
124 assertThrottlerTimeout();
125 timeoutMock.fireAllTimers();
126 process.finish();
127 assertThrottlerTimeout();
128 timeoutMock.fireAllTimers();
129 nextProcess.finish();
130 next();
132 function processBody()
134 nextProcess = ProcessMock.create("operation #2");
135 throttler.schedule(nextProcess, false);
139 function testExceptionFromProcess(next)
141 var process = ProcessMock.create("operation #1", processBody);
142 throttler.schedule(process);
143 timeoutMock.fireAllTimers();
144 assertThrottlerIdle();
145 next();
147 function processBody()
149 throw new Error("Exception during process execution.");
154 function throttlerToRunningState()
156 assertThrottlerIdle();
157 var process = ProcessMock.create("long operation");
158 throttler.schedule(process);
159 assertThrottlerTimeout();
160 timeoutMock.fireAllTimers();
161 return process;
164 function assertThrottlerIdle()
166 var timeouts = timeoutMock.activeTimersTimeouts();
167 if (timeouts.length !== 0) {
168 InspectorTest.addResult("ERROR: throttler is not in idle state. Scheduled timers timeouts: [" + timeouts.sort().join(", ") + "]");
169 InspectorTest.completeTest();
170 return;
172 InspectorTest.addResult("Throttler is in IDLE state (doesn't have any timers set up)");
175 function assertThrottlerTimeout()
177 var timeouts = timeoutMock.activeTimersTimeouts();
178 if (timeouts.length === 0) {
179 InspectorTest.addResult("ERROR: throttler is not in timeout state. Scheduled timers timeouts are empty!");
180 InspectorTest.completeTest();
181 return;
183 InspectorTest.addResult("Throttler is in TIMEOUT state. Scheduled timers timeouts: [" + timeouts.sort().join(", ") + "]");
186 function logSchedule(operation, asSoonAsPossible)
188 InspectorTest.addResult("SCHEDULED: '" + operation.processName + "' asSoonAsPossible: " + asSoonAsPossible);
192 </script>
193 </head>
195 <body onload="runTest()">
196 <p>This test verifies throttler behavior.</p>
197 </body>
198 </html>