<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[176239] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/176239">176239</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2014-11-17 17:14:46 -0800 (Mon, 17 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add initial layout testing coverage for timer throttling
https://bugs.webkit.org/show_bug.cgi?id=138809

Reviewed by Simon Fraser.

Source/WebCore:

Add isTimerThrottled() API to Internals so that we can add layout test
coverage for timer throttling.

Tests: fast/dom/nested-timer-invisible-element-throttling.html
       fast/dom/nested-timer-visible-element-throttling.html
       fast/dom/repeating-timer-invisible-element-throttling.html
       fast/dom/repeating-timer-visible-element-throttling.html

* page/DOMTimer.h:
* testing/Internals.cpp:
(WebCore::Internals::isTimerThrottled):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

Add initial layout test coverage for timer throttling. It currently
covers the following cases:
- Repeating timer changes the style of an Element that is visible
- Repeating timer changes the style of an Element that is not visible
  (i.e. &quot;display: none&quot;).
- Repeating timer doing DOM mutations
- Nested timer changes the style of an Element that is visible
- Nested timer changes the style of an Element that is not visible
  (i.e. &quot;display: none&quot;).
- Nested timer doing DOM mutations

More layout tests are coming. In particular, we should add coverage for
changing the style of an Element outside the viewport. We should also
Test that the timer gets unthrottled if necessary on scrolling / layout.

* fast/dom/nested-timer-invisible-element-throttling-expected.txt: Added.
* fast/dom/nested-timer-invisible-element-throttling.html: Added.
* fast/dom/nested-timer-visible-element-throttling-expected.txt: Added.
* fast/dom/nested-timer-visible-element-throttling.html: Added.
* fast/dom/repeating-timer-invisible-element-throttling-expected.txt: Added.
* fast/dom/repeating-timer-invisible-element-throttling.html: Added.
* fast/dom/repeating-timer-visible-element-throttling-expected.txt: Added.
* fast/dom/repeating-timer-visible-element-throttling.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageDOMTimerh">trunk/Source/WebCore/page/DOMTimer.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsidl">trunk/Source/WebCore/testing/Internals.idl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastdomnestedtimerinvisibleelementthrottlingexpectedtxt">trunk/LayoutTests/fast/dom/nested-timer-invisible-element-throttling-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomnestedtimerinvisibleelementthrottlinghtml">trunk/LayoutTests/fast/dom/nested-timer-invisible-element-throttling.html</a></li>
<li><a href="#trunkLayoutTestsfastdomnestedtimervisibleelementthrottlingexpectedtxt">trunk/LayoutTests/fast/dom/nested-timer-visible-element-throttling-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomnestedtimervisibleelementthrottlinghtml">trunk/LayoutTests/fast/dom/nested-timer-visible-element-throttling.html</a></li>
<li><a href="#trunkLayoutTestsfastdomrepeatingtimerinvisibleelementthrottlingexpectedtxt">trunk/LayoutTests/fast/dom/repeating-timer-invisible-element-throttling-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomrepeatingtimerinvisibleelementthrottlinghtml">trunk/LayoutTests/fast/dom/repeating-timer-invisible-element-throttling.html</a></li>
<li><a href="#trunkLayoutTestsfastdomrepeatingtimervisibleelementthrottlingexpectedtxt">trunk/LayoutTests/fast/dom/repeating-timer-visible-element-throttling-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastdomrepeatingtimervisibleelementthrottlinghtml">trunk/LayoutTests/fast/dom/repeating-timer-visible-element-throttling.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (176238 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-11-18 01:13:16 UTC (rev 176238)
+++ trunk/LayoutTests/ChangeLog        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -1,3 +1,34 @@
</span><ins>+2014-11-17  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Add initial layout testing coverage for timer throttling
+        https://bugs.webkit.org/show_bug.cgi?id=138809
+
+        Reviewed by Simon Fraser.
+
+        Add initial layout test coverage for timer throttling. It currently
+        covers the following cases:
+        - Repeating timer changes the style of an Element that is visible
+        - Repeating timer changes the style of an Element that is not visible
+          (i.e. &quot;display: none&quot;).
+        - Repeating timer doing DOM mutations
+        - Nested timer changes the style of an Element that is visible
+        - Nested timer changes the style of an Element that is not visible
+          (i.e. &quot;display: none&quot;).
+        - Nested timer doing DOM mutations
+
+        More layout tests are coming. In particular, we should add coverage for
+        changing the style of an Element outside the viewport. We should also
+        Test that the timer gets unthrottled if necessary on scrolling / layout.
+
+        * fast/dom/nested-timer-invisible-element-throttling-expected.txt: Added.
+        * fast/dom/nested-timer-invisible-element-throttling.html: Added.
+        * fast/dom/nested-timer-visible-element-throttling-expected.txt: Added.
+        * fast/dom/nested-timer-visible-element-throttling.html: Added.
+        * fast/dom/repeating-timer-invisible-element-throttling-expected.txt: Added.
+        * fast/dom/repeating-timer-invisible-element-throttling.html: Added.
+        * fast/dom/repeating-timer-visible-element-throttling-expected.txt: Added.
+        * fast/dom/repeating-timer-visible-element-throttling.html: Added.
+
</ins><span class="cx"> 2014-11-17  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         media/track/track-in-band-cues-added-once.html fails sometimes
</span></span></pre></div>
<a id="trunkLayoutTestsfastdomnestedtimerinvisibleelementthrottlingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/nested-timer-invisible-element-throttling-expected.txt (0 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/nested-timer-invisible-element-throttling-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/dom/nested-timer-invisible-element-throttling-expected.txt        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+Tests that a nested timer changing the style of a non-visible element gets throttled.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+The timer should initially not be throttled.
+PASS internals.isTimerThrottled(timeoutId) is false
+5th iteration, timer should have been throttled.
+PASS wasThrottled is true
+6th iteration, timer should still be throttled.
+PASS internals.isTimerThrottled(timeoutId) is true
+Timer mutated the DOM tree.
+7th iteration, timer should no longer be throttled.
+PASS internals.isTimerThrottled(timeoutId) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomnestedtimerinvisibleelementthrottlinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/nested-timer-invisible-element-throttling.html (0 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/nested-timer-invisible-element-throttling.html                                (rev 0)
+++ trunk/LayoutTests/fast/dom/nested-timer-invisible-element-throttling.html        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -0,0 +1,58 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;body&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;div id=&quot;testElement&quot; style=&quot;display: none&quot;&gt;Test&lt;/div&gt;
+&lt;script&gt;
+description(&quot;Tests that a nested timer changing the style of a non-visible element gets throttled.&quot;);
+jsTestIsAsync = true;
+
+var iterationCount = 0;
+var timeoutId;
+var testElement = document.getElementById(&quot;testElement&quot;);
+var wasThrottled = false;
+
+function checkTimerThrottleState()
+{
+  if (iterationCount == 5) {
+    // Do not use shouldBeTrue() here because it would cause a DOM tree mutation and
+    // unthrottle the DOM Timer.
+    wasThrottled = internals.isTimerThrottled(timeoutId);
+  } else if (iterationCount == 6) {
+    debug(&quot;5th iteration, timer should have been throttled.&quot;);
+    shouldBeTrue(&quot;wasThrottled&quot;);
+    debug(&quot;6th iteration, timer should still be throttled.&quot;);
+    shouldBeTrue(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+  } else if (iterationCount &gt;= 6) {
+    // Timer should be unthrottled due to the DOM tree mutation caused by shouldBeTrue() in
+    // the previous iteration.
+    debug(&quot;&quot; + iterationCount + &quot;th iteration, timer should no longer be throttled.&quot;);
+    shouldBeFalse(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+    clearTimeout(timeoutId);
+    finishJSTest();
+  }
+}
+
+function timerCallback()
+{
+  ++iterationCount;
+  // Interact with the style of the element.
+  testElement.style[&quot;left&quot;] = &quot;&quot; + iterationCount + &quot;px&quot;;
+
+  // 5 iterations should be sufficient to throttle the timer.
+  if (iterationCount &gt;= 5) {
+    setTimeout(checkTimerThrottleState, 0);
+    if (iterationCount == 7) {
+      // The call to debug() mutates the DOM tree.
+      debug(&quot;Timer mutated the DOM tree.&quot;);
+    }
+  }
+
+  timeoutId = setTimeout(timerCallback, 0);
+}
+
+timeoutId = setTimeout(timerCallback, 0);
+debug(&quot;The timer should initially not be throttled.&quot;);
+shouldBeFalse(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomnestedtimervisibleelementthrottlingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/nested-timer-visible-element-throttling-expected.txt (0 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/nested-timer-visible-element-throttling-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/dom/nested-timer-visible-element-throttling-expected.txt        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+Tests that a nested timer changing the style of a visible element does not get throttled.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+The timer should initially not be throttled.
+PASS internals.isTimerThrottled(timeoutId) is false
+5th iteration, timer should not have been throttled.
+PASS wasThrottled is false
+6th iteration, timer should still be unthrottled.
+PASS internals.isTimerThrottled(timeoutId) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Test
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomnestedtimervisibleelementthrottlinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/nested-timer-visible-element-throttling.html (0 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/nested-timer-visible-element-throttling.html                                (rev 0)
+++ trunk/LayoutTests/fast/dom/nested-timer-visible-element-throttling.html        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -0,0 +1,47 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;body&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;div id=&quot;testElement&quot;&gt;Test&lt;/div&gt;
+&lt;script&gt;
+description(&quot;Tests that a nested timer changing the style of a visible element does not get throttled.&quot;);
+jsTestIsAsync = true;
+
+var iterationCount = 0;
+var timeoutId;
+var testElement = document.getElementById(&quot;testElement&quot;);
+var wasThrottled = false;
+
+function checkTimerThrottlingState() {
+  if (iterationCount == 5) {
+    // Do not use shouldBeTrue() here because it would cause a DOM tree mutation and
+    // unthrottle the DOM Timer.
+    wasThrottled = internals.isTimerThrottled(timeoutId);
+  } else if (iterationCount == 6) {
+    debug(&quot;5th iteration, timer should not have been throttled.&quot;);
+    shouldBeFalse(&quot;wasThrottled&quot;);
+    debug(&quot;6th iteration, timer should still be unthrottled.&quot;);
+    shouldBeFalse(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+    clearTimeout(timeoutId);
+    finishJSTest();
+  }
+}
+
+function timerCallback()
+{
+  ++iterationCount;
+  // Interact with the style of the element.
+  testElement.style[&quot;left&quot;] = &quot;&quot; + iterationCount + &quot;px&quot;;
+
+  // 5 iterations should suffice to throttle the timer.
+  if (iterationCount &gt;= 5)
+    setTimeout(checkTimerThrottlingState, 0);
+
+  timeoutId = setTimeout(timerCallback, 0);
+}
+
+timeoutId = setTimeout(timerCallback, 0);
+debug(&quot;The timer should initially not be throttled.&quot;);
+shouldBeFalse(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomrepeatingtimerinvisibleelementthrottlingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/repeating-timer-invisible-element-throttling-expected.txt (0 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/repeating-timer-invisible-element-throttling-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/dom/repeating-timer-invisible-element-throttling-expected.txt        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -0,0 +1,18 @@
</span><ins>+Tests that a repeating timer changing the style of a non-visible element gets throttled.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+The timer should initially not be throttled.
+PASS internals.isTimerThrottled(timeoutId) is false
+5th iteration, timer should have been throttled.
+PASS wasThrottled is true
+6th iteration, timer should still be throttled.
+PASS internals.isTimerThrottled(timeoutId) is true
+Timer mutated the DOM tree.
+7th iteration, timer should no longer be throttled.
+PASS internals.isTimerThrottled(timeoutId) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomrepeatingtimerinvisibleelementthrottlinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/repeating-timer-invisible-element-throttling.html (0 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/repeating-timer-invisible-element-throttling.html                                (rev 0)
+++ trunk/LayoutTests/fast/dom/repeating-timer-invisible-element-throttling.html        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -0,0 +1,46 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;body&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;div id=&quot;testElement&quot; style=&quot;display: none&quot;&gt;Test&lt;/div&gt;
+&lt;script&gt;
+description(&quot;Tests that a repeating timer changing the style of a non-visible element gets throttled.&quot;);
+jsTestIsAsync = true;
+
+var iterationCount = 0;
+var timeoutId;
+var testElement = document.getElementById(&quot;testElement&quot;);
+var wasThrottled = false;
+
+function timerCallback()
+{
+  ++iterationCount;
+  // Interact with the style of the element.
+  testElement.style[&quot;left&quot;] = &quot;&quot; + iterationCount + &quot;px&quot;;
+
+  // 5 iterations should suffice to throttle the timer.
+  if (iterationCount == 5) {
+    // Do not use shouldBeTrue() here because it would cause a DOM tree mutation and
+    // unthrottle the DOM Timer.
+    wasThrottled = internals.isTimerThrottled(timeoutId);
+  } else if (iterationCount == 6) {
+    debug(&quot;5th iteration, timer should have been throttled.&quot;);
+    shouldBeTrue(&quot;wasThrottled&quot;);
+    debug(&quot;6th iteration, timer should still be throttled.&quot;);
+    shouldBeTrue(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+    debug(&quot;Timer mutated the DOM tree.&quot;);
+  } else if (iterationCount &gt;= 6) {
+    // Timer should be unthrottled due to the DOM tree mutation caused by shouldBeTrue() in
+    // the previous iteration.
+    debug(&quot;&quot; + iterationCount + &quot;th iteration, timer should no longer be throttled.&quot;);
+    shouldBeFalse(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+    clearInterval(timeoutId);
+    finishJSTest();
+  }
+}
+
+timeoutId = setInterval(timerCallback, 0);
+debug(&quot;The timer should initially not be throttled.&quot;);
+shouldBeFalse(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomrepeatingtimervisibleelementthrottlingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/repeating-timer-visible-element-throttling-expected.txt (0 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/repeating-timer-visible-element-throttling-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/dom/repeating-timer-visible-element-throttling-expected.txt        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -0,0 +1,15 @@
</span><ins>+Tests that a repeating timer changing the style of a visible element does not get throttled.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+The timer should initially not be throttled.
+PASS internals.isTimerThrottled(timeoutId) is false
+5th iteration, timer should not have been throttled.
+PASS wasThrottled is false
+6th iteration, timer should still be unthrottled.
+PASS internals.isTimerThrottled(timeoutId) is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Test
</ins></span></pre></div>
<a id="trunkLayoutTestsfastdomrepeatingtimervisibleelementthrottlinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/dom/repeating-timer-visible-element-throttling.html (0 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/dom/repeating-timer-visible-element-throttling.html                                (rev 0)
+++ trunk/LayoutTests/fast/dom/repeating-timer-visible-element-throttling.html        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -0,0 +1,40 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;body&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;div id=&quot;testElement&quot;&gt;Test&lt;/div&gt;
+&lt;script&gt;
+description(&quot;Tests that a repeating timer changing the style of a visible element does not get throttled.&quot;);
+jsTestIsAsync = true;
+
+var iterationCount = 0;
+var timeoutId;
+var testElement = document.getElementById(&quot;testElement&quot;);
+var wasThrottled = false;
+
+function timerCallback()
+{
+  ++iterationCount;
+  // Interact with the style of the element.
+  testElement.style[&quot;left&quot;] = &quot;&quot; + iterationCount + &quot;px&quot;;
+
+  // 5 iterations should suffice to throttle the timer.
+  if (iterationCount == 5) {
+    // Do not use shouldBeTrue() here because it would cause a DOM tree mutation and
+    // unthrottle the DOM Timer.
+    wasThrottled = internals.isTimerThrottled(timeoutId);
+  } else if (iterationCount == 6) {
+    debug(&quot;5th iteration, timer should not have been throttled.&quot;);
+    shouldBeFalse(&quot;wasThrottled&quot;);
+    debug(&quot;6th iteration, timer should still be unthrottled.&quot;);
+    shouldBeFalse(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+    clearInterval(timeoutId);
+    finishJSTest();
+  }
+}
+
+timeoutId = setInterval(timerCallback, 0);
+debug(&quot;The timer should initially not be throttled.&quot;);
+shouldBeFalse(&quot;internals.isTimerThrottled(timeoutId)&quot;);
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (176238 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-18 01:13:16 UTC (rev 176238)
+++ trunk/Source/WebCore/ChangeLog        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2014-11-17  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        Add initial layout testing coverage for timer throttling
+        https://bugs.webkit.org/show_bug.cgi?id=138809
+
+        Reviewed by Simon Fraser.
+
+        Add isTimerThrottled() API to Internals so that we can add layout test
+        coverage for timer throttling.
+
+        Tests: fast/dom/nested-timer-invisible-element-throttling.html
+               fast/dom/nested-timer-visible-element-throttling.html
+               fast/dom/repeating-timer-invisible-element-throttling.html
+               fast/dom/repeating-timer-visible-element-throttling.html
+
+        * page/DOMTimer.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::isTimerThrottled):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
</ins><span class="cx"> 2014-11-17  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Simple line layout: Rename FlowContentIterator and move implementation to SimpleLineLayoutFlowContents.cpp
</span></span></pre></div>
<a id="trunkSourceWebCorepageDOMTimerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/DOMTimer.h (176238 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/DOMTimer.h        2014-11-18 01:13:16 UTC (rev 176238)
+++ trunk/Source/WebCore/page/DOMTimer.h        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -61,6 +61,8 @@
</span><span class="cx"> 
</span><span class="cx">     private:
</span><span class="cx">         DOMTimer(ScriptExecutionContext&amp;, std::unique_ptr&lt;ScheduledAction&gt;, int interval, bool singleShot);
</span><ins>+        friend class Internals;
+
</ins><span class="cx">         double intervalClampedToMinimum() const;
</span><span class="cx"> 
</span><span class="cx">         bool isIntervalDependentOnViewport() const { return m_throttleState == ShouldThrottle &amp;&amp; !m_elementsCausingThrottling.isEmpty(); }
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (176238 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2014-11-18 01:13:16 UTC (rev 176238)
+++ trunk/Source/WebCore/testing/Internals.cpp        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -626,6 +626,16 @@
</span><span class="cx">     return element-&gt;setPseudo(id);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool Internals::isTimerThrottled(int timeoutId, ExceptionCode&amp; ec)
+{
+    DOMTimer* timer = scriptExecutionContext()-&gt;findTimeout(timeoutId);
+    if (!timer) {
+        ec = NOT_FOUND_ERR;
+        return false;
+    }
+    return timer-&gt;m_throttleState == DOMTimer::ShouldThrottle;
+}
+
</ins><span class="cx"> String Internals::visiblePlaceholder(Element* element)
</span><span class="cx"> {
</span><span class="cx">     if (is&lt;HTMLTextFormControlElement&gt;(element)) {
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (176238 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h        2014-11-18 01:13:16 UTC (rev 176238)
+++ trunk/Source/WebCore/testing/Internals.h        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -92,6 +92,9 @@
</span><span class="cx">     String shadowPseudoId(Element*, ExceptionCode&amp;);
</span><span class="cx">     void setShadowPseudoId(Element*, const String&amp;, ExceptionCode&amp;);
</span><span class="cx"> 
</span><ins>+    // DOMTimers throttling testing.
+    bool isTimerThrottled(int timeoutId, ExceptionCode&amp;);
+
</ins><span class="cx">     // Spatial Navigation testing.
</span><span class="cx">     unsigned lastSpatialNavigationCandidateCount(ExceptionCode&amp;) const;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (176238 => 176239)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl        2014-11-18 01:13:16 UTC (rev 176238)
+++ trunk/Source/WebCore/testing/Internals.idl        2014-11-18 01:14:46 UTC (rev 176239)
</span><span class="lines">@@ -238,6 +238,9 @@
</span><span class="cx">     [RaisesException] void startTrackingRepaints();
</span><span class="cx">     [RaisesException] void stopTrackingRepaints();
</span><span class="cx"> 
</span><ins>+    // Query if a timer is currently throttled, to debug timer throttling.
+    [RaisesException] boolean isTimerThrottled(long timerHandle);
+
</ins><span class="cx">     // |node| should be Document, HTMLIFrameElement, or unspecified.
</span><span class="cx">     // If |node| is an HTMLIFrameElement, it assumes node.contentDocument is
</span><span class="cx">     // specified without security checks. Unspecified means this document.
</span></span></pre>
</div>
</div>

</body>
</html>