<!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>[190260] 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/190260">190260</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2015-09-25 17:17:27 -0700 (Fri, 25 Sep 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS WK2] Add viewport tests and fix runUIScript() timing issues
https://bugs.webkit.org/show_bug.cgi?id=149577

Reviewed by Tim Horton.

Source/WebKit2:

When calling testRunner.runUIScript() from a page load event, the script could run
in the UI process before the current remote layer tree transaction had been handled
there. This meant that runUIScript() could query state which was about to change.

Fix by delaying the execution of the UI script until a layer tree transaction has
been handled by the UI process, leveraging the existing DrawingAreaProxy::dispatchAfterEnsuringDrawing().

This is done using a new C SPI function WKPageCallAfterNextPresentationUpdate(),
which is mirrored in the Obj-C SPI as -_doAfterNextPresentationUpdate:.

Move WKWebView SPI which is testing-related into a WKTesting category. It is expected
that this will grow significantly.

* UIProcess/API/C/WKPage.cpp:
(WKPageCallAfterNextPresentationUpdate):
* UIProcess/API/C/WKPagePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::callAfterNextPresentationUpdate):
* UIProcess/WebPageProxy.h:
* UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h:
* UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm:
(WebKit::TiledCoreAnimationDrawingAreaProxy::dispatchAfterEnsuringDrawing):

Tools:

When calling testRunner.runUIScript() from a page load event, the script could run
in the UI process before the current remote layer tree transaction had been handled
there. This meant that runUIScript() could query state which was about to change.

Fix by delaying the execution of the UI script until a layer tree transaction has
been handled by the UI process, leveraging the existing DrawingAreaProxy::dispatchAfterEnsuringDrawing().

* WebKitTestRunner/TestInvocation.cpp:
(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
(WTR::TestInvocation::runUISideScriptAfterUpdateCallback):
* WebKitTestRunner/TestInvocation.h:

LayoutTests:

New viewport tests which read the scale etc. in the UI process.

* TestExpectations:
* fast/viewport/ios/resources/viewport-test-utils.js: Added.
(getUIScript):
(tableFromJSON):
(getViewport):
(runTest):
* fast/viewport/ios/width-is-device-width-expected.txt: Added.
* fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall-expected.txt: Added.
* fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall.html: Added.
* fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden.html: Added.
* fast/viewport/ios/width-is-device-width-overflowing-expected.txt: Added.
* fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit-expected.txt: Added.
* fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit.html: Added.
* fast/viewport/ios/width-is-device-width-overflowing.html: Added.
* fast/viewport/ios/width-is-device-width.html: Added.
* platform/ios-simulator-wk2/TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsTestExpectations">trunk/LayoutTests/TestExpectations</a></li>
<li><a href="#trunkLayoutTestsplatformiossimulatorwk2TestExpectations">trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPagecpp">trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPagePrivateh">trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacTiledCoreAnimationDrawingAreaProxyh">trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacTiledCoreAnimationDrawingAreaProxymm">trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestInvocationcpp">trunk/Tools/WebKitTestRunner/TestInvocation.cpp</a></li>
<li><a href="#trunkToolsWebKitTestRunnerTestInvocationh">trunk/Tools/WebKitTestRunner/TestInvocation.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/LayoutTests/fast/viewport/ios/</li>
<li>trunk/LayoutTests/fast/viewport/ios/resources/</li>
<li><a href="#trunkLayoutTestsfastviewportiosresourcesviewporttestutilsjs">trunk/LayoutTests/fast/viewport/ios/resources/viewport-test-utils.js</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthexpectedtxt">trunk/LayoutTests/fast/viewport/ios/width-is-device-width-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingbodyoverflowhiddentallexpectedtxt">trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingbodyoverflowhiddentallhtml">trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall.html</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingbodyoverflowhiddenhtml">trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden.html</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingexpectedtxt">trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingnoshrinktofitexpectedtxt">trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingnoshrinktofithtml">trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit.html</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowinghtml">trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing.html</a></li>
<li><a href="#trunkLayoutTestsfastviewportioswidthisdevicewidthhtml">trunk/LayoutTests/fast/viewport/ios/width-is-device-width.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/LayoutTests/ChangeLog        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2015-09-25  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        [iOS WK2] Add viewport tests and fix runUIScript() timing issues
+        https://bugs.webkit.org/show_bug.cgi?id=149577
+
+        Reviewed by Tim Horton.
+        
+        New viewport tests which read the scale etc. in the UI process.
+
+        * TestExpectations:
+        * fast/viewport/ios/resources/viewport-test-utils.js: Added.
+        (getUIScript):
+        (tableFromJSON):
+        (getViewport):
+        (runTest):
+        * fast/viewport/ios/width-is-device-width-expected.txt: Added.
+        * fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall-expected.txt: Added.
+        * fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall.html: Added.
+        * fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden.html: Added.
+        * fast/viewport/ios/width-is-device-width-overflowing-expected.txt: Added.
+        * fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit-expected.txt: Added.
+        * fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit.html: Added.
+        * fast/viewport/ios/width-is-device-width-overflowing.html: Added.
+        * fast/viewport/ios/width-is-device-width.html: Added.
+        * platform/ios-simulator-wk2/TestExpectations:
+
</ins><span class="cx"> 2015-09-25  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Implement scoped styling for shadow DOM
</span></span></pre></div>
<a id="trunkLayoutTestsTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/TestExpectations (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/TestExpectations        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/LayoutTests/TestExpectations        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -15,6 +15,7 @@
</span><span class="cx"> tiled-drawing [ Skip ]
</span><span class="cx"> swipe [ Skip ]
</span><span class="cx"> fast/zooming/ios [ Skip ]
</span><ins>+fast/viewport/ios [ Skip ]
</ins><span class="cx"> 
</span><span class="cx"> fast/forms/attributed-strings.html [ Skip ]
</span><span class="cx"> fast/scrolling/latching [ Skip ]
</span></span></pre></div>
<a id="trunkLayoutTestsfastviewportiosresourcesviewporttestutilsjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/resources/viewport-test-utils.js (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/resources/viewport-test-utils.js                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/resources/viewport-test-utils.js        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,67 @@
</span><ins>+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+}
+
+function getUIScript()
+{
+    return &quot;(function() { \
+        var result = { \
+            'scale' : uiController.zoomScale, \
+            'maxScale' : uiController.maximumZoomScale, \
+            'minScale' : uiController.minimumZoomScale, \
+            'visibleRect' : uiController.contentVisibleRect \
+        }; \
+        return JSON.stringify(result, function(key, value) { \
+              if (typeof value === \&quot;number\&quot;) \
+                  return value.toFixed(5); \
+            return value; \
+        }); \
+    })();&quot;;
+}
+
+function tableFromJSON(value)
+{
+    var result = JSON.parse(value);
+    
+    var table = document.createElement('table');
+    
+    
+    for (var property in result) {
+        var row = document.createElement('tr');
+        
+        var th = document.createElement('th');
+        th.textContent = property;
+        
+        var td = document.createElement('td');
+        var value = result[property];
+        if (typeof value === &quot;object&quot;)
+            value = JSON.stringify(value);
+        
+        td.textContent = value;
+    
+        row.appendChild(th);
+        row.appendChild(td);
+        table.appendChild(row);
+    }
+    
+    return table;
+}
+
+function getViewport()
+{
+    var metaTag = document.head.querySelectorAll('meta')[0];
+    document.getElementById('viewport').textContent = metaTag.getAttribute('content');
+}
+
+function runTest()
+{
+    getViewport();
+    
+    if (testRunner.runUIScript) {
+        testRunner.runUIScript(getUIScript(), function(resultString) {
+            document.getElementById('result').appendChild(tableFromJSON(resultString));
+            testRunner.notifyDone();
+        });
+    }
+}
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width-expected.txt (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width-expected.txt        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,6 @@
</span><ins>+Viewport: width=device-width
+
+scale        1.00000
+maxScale        5.00000
+minScale        1.00000
+visibleRect        {&quot;left&quot;:&quot;0.00000&quot;,&quot;top&quot;:&quot;0.00000&quot;,&quot;width&quot;:&quot;320.00000&quot;,&quot;height&quot;:&quot;480.00000&quot;}
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingbodyoverflowhiddentallexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall-expected.txt (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall-expected.txt        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+Viewport: width=device-width
+
+scale        1.05263
+maxScale        5.00000
+minScale        1.05263
+visibleRect        {&quot;left&quot;:&quot;0.00000&quot;,&quot;top&quot;:&quot;0.00000&quot;,&quot;width&quot;:&quot;303.99999&quot;,&quot;height&quot;:&quot;455.99998&quot;}
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingbodyoverflowhiddentallhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall.html (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall.html                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden-tall.html        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,27 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
+    &lt;script src=&quot;resources/viewport-test-utils.js&quot;&gt;&lt;/script&gt;
+    &lt;style&gt;
+        body {
+            overflow: hidden;
+            height: 1000px;
+        }
+        .wide {
+            height: 1px;
+            width: 1000px;
+            background-color: gray;
+        }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+
+&lt;p&gt;Viewport: &lt;span id=&quot;viewport&quot;&gt;&lt;/span&gt;&lt;/p&gt;
+&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
+
+&lt;div class=&quot;wide&quot;&gt;&lt;/div&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingbodyoverflowhiddenhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden.html (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden.html                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-body-overflow-hidden.html        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,26 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
+    &lt;script src=&quot;resources/viewport-test-utils.js&quot;&gt;&lt;/script&gt;
+    &lt;style&gt;
+        body {
+            overflow: hidden;
+        }
+        .wide {
+            height: 1px;
+            width: 1000px;
+            background-color: gray;
+        }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+
+&lt;p&gt;Viewport: &lt;span id=&quot;viewport&quot;&gt;&lt;/span&gt;&lt;/p&gt;
+&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
+
+&lt;div class=&quot;wide&quot;&gt;&lt;/div&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-expected.txt (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-expected.txt        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+Viewport: width=device-width
+
+scale        0.31746
+maxScale        5.00000
+minScale        0.31746
+visibleRect        {&quot;left&quot;:&quot;0.00000&quot;,&quot;top&quot;:&quot;0.00000&quot;,&quot;width&quot;:&quot;1007.99997&quot;,&quot;height&quot;:&quot;1511.99995&quot;}
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingnoshrinktofitexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit-expected.txt (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit-expected.txt        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,7 @@
</span><ins>+Viewport: width=device-width, shrink-to-fit=no
+
+scale        1.00000
+maxScale        5.00000
+minScale        1.00000
+visibleRect        {&quot;left&quot;:&quot;0.00000&quot;,&quot;top&quot;:&quot;0.00000&quot;,&quot;width&quot;:&quot;320.00000&quot;,&quot;height&quot;:&quot;480.00000&quot;}
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowingnoshrinktofithtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit.html (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit.html                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing-no-shrink-to-fit.html        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, shrink-to-fit=no&quot;&gt;
+    &lt;script src=&quot;resources/viewport-test-utils.js&quot;&gt;&lt;/script&gt;
+    &lt;style&gt;
+        .wide {
+            height: 1px;
+            width: 1000px;
+            background-color: gray;
+        }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+
+&lt;p&gt;Viewport: &lt;span id=&quot;viewport&quot;&gt;&lt;/span&gt;&lt;/p&gt;
+&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
+
+&lt;div class=&quot;wide&quot;&gt;&lt;/div&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthoverflowinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing.html (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing.html                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width-overflowing.html        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
+    &lt;script src=&quot;resources/viewport-test-utils.js&quot;&gt;&lt;/script&gt;
+    &lt;style&gt;
+        .wide {
+            height: 1px;
+            width: 1000px;
+            background-color: gray;
+        }
+    &lt;/style&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+
+&lt;p&gt;Viewport: &lt;span id=&quot;viewport&quot;&gt;&lt;/span&gt;&lt;/p&gt;
+&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
+
+&lt;div class=&quot;wide&quot;&gt;&lt;/div&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastviewportioswidthisdevicewidthhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/viewport/ios/width-is-device-width.html (0 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/viewport/ios/width-is-device-width.html                                (rev 0)
+++ trunk/LayoutTests/fast/viewport/ios/width-is-device-width.html        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -0,0 +1,14 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+
+&lt;html&gt;
+&lt;head&gt;
+    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot;&gt;
+    &lt;script src=&quot;resources/viewport-test-utils.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+
+&lt;p&gt;Viewport: &lt;span id=&quot;viewport&quot;&gt;&lt;/span&gt;&lt;/p&gt;
+&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsplatformiossimulatorwk2TestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/LayoutTests/platform/ios-simulator-wk2/TestExpectations        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -9,6 +9,7 @@
</span><span class="cx"> fast/harness/ui-side-scripts.html [ Pass ]
</span><span class="cx"> fast/harness/concurrent-ui-side-scripts.html [ Pass ]
</span><span class="cx"> fast/zooming/ios [ Pass ]
</span><ins>+fast/viewport/ios [ Pass ]
</ins><span class="cx"> 
</span><span class="cx"> #//////////////////////////////////////////////////////////////////////////////////////////
</span><span class="cx"> # End platform-specific directories.
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/ChangeLog        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2015-09-25  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        [iOS WK2] Add viewport tests and fix runUIScript() timing issues
+        https://bugs.webkit.org/show_bug.cgi?id=149577
+
+        Reviewed by Tim Horton.
+        
+        When calling testRunner.runUIScript() from a page load event, the script could run
+        in the UI process before the current remote layer tree transaction had been handled
+        there. This meant that runUIScript() could query state which was about to change.
+        
+        Fix by delaying the execution of the UI script until a layer tree transaction has
+        been handled by the UI process, leveraging the existing DrawingAreaProxy::dispatchAfterEnsuringDrawing().
+        
+        This is done using a new C SPI function WKPageCallAfterNextPresentationUpdate(),
+        which is mirrored in the Obj-C SPI as -_doAfterNextPresentationUpdate:.
+        
+        Move WKWebView SPI which is testing-related into a WKTesting category. It is expected
+        that this will grow significantly.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageCallAfterNextPresentationUpdate):
+        * UIProcess/API/C/WKPagePrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::callAfterNextPresentationUpdate):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h:
+        * UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm:
+        (WebKit::TiledCoreAnimationDrawingAreaProxy::dispatchAfterEnsuringDrawing):
+
</ins><span class="cx"> 2015-09-25  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Mac] Media tests start to time out after a few days of bot uptime
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -2469,6 +2469,12 @@
</span><span class="cx">     toImpl(pageRef)-&gt;clearWheelEventTestTrigger();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WKPageCallAfterNextPresentationUpdate(WKPageRef pageRef, void* context, WKPagePostPresentationUpdateFunction callback)
+{
+    toImpl(pageRef)-&gt;callAfterNextPresentationUpdate([context, callback](WebKit::CallbackBase::Error error) {
+        callback(error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
+    });
+}
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETSCAPE_PLUGIN_API)
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPagePrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -121,6 +121,9 @@
</span><span class="cx"> 
</span><span class="cx"> WK_EXPORT void WKPageLoadURLWithShouldOpenExternalURLsPolicy(WKPageRef page, WKURLRef url, bool shouldOpenExternalURLs);
</span><span class="cx"> 
</span><ins>+typedef void (*WKPagePostPresentationUpdateFunction)(WKErrorRef, void*);
+WK_EXPORT void WKPageCallAfterNextPresentationUpdate(WKPageRef page, void* context, WKPagePostPresentationUpdateFunction function);
+
</ins><span class="cx"> #ifdef __cplusplus
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -3020,21 +3020,6 @@
</span><span class="cx">     return _viewportMetaTagWidth;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (CGRect)_contentVisibleRect
-{
-    return [self convertRect:[self bounds] toView:self._currentContentView];
-}
-
-- (CGPoint)_convertPointFromContentsToView:(CGPoint)point
-{
-    return [self convertPoint:point fromView:self._currentContentView];
-}
-
-- (CGPoint)_convertPointFromViewToContents:(CGPoint)point
-{
-    return [self convertPoint:point toView:self._currentContentView];
-}
-
</del><span class="cx"> - (_WKWebViewPrintFormatter *)_webViewPrintFormatter
</span><span class="cx"> {
</span><span class="cx">     UIViewPrintFormatter *viewPrintFormatter = self.viewPrintFormatter;
</span><span class="lines">@@ -3107,14 +3092,52 @@
</span><span class="cx">     return [_wkView _automaticallyAdjustsContentInsets];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#endif
</del><ins>+#endif // __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 101000
</ins><span class="cx"> 
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><del>-#if !TARGET_OS_IPHONE
</del><span class="cx"> 
</span><ins>+@implementation WKWebView (WKTesting)
+
+#if PLATFORM(IOS)
+
+- (CGRect)_contentVisibleRect
+{
+    return [self convertRect:[self bounds] toView:self._currentContentView];
+}
+
+- (CGPoint)_convertPointFromContentsToView:(CGPoint)point
+{
+    return [self convertPoint:point fromView:self._currentContentView];
+}
+
+- (CGPoint)_convertPointFromViewToContents:(CGPoint)point
+{
+    return [self convertPoint:point toView:self._currentContentView];
+}
+
+#endif // PLATFORM(IOS)
+
+// Execute the supplied block after the next transaction from the WebProcess.
+- (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock
+{
+    typeof(updateBlock) updateBlockCopy = nil;
+    if (updateBlock)
+        updateBlockCopy = Block_copy(updateBlock);
+
+    _page-&gt;callAfterNextPresentationUpdate([updateBlockCopy](WebKit::CallbackBase::Error error) {
+        updateBlockCopy();
+        Block_release(updateBlockCopy);
+    });
+}
+
+@end
+
+
+#if PLATFORM(MAC)
+
</ins><span class="cx"> @implementation WKWebView (WKIBActions)
</span><span class="cx"> 
</span><span class="cx"> - (BOOL)validateUserInterfaceItem:(id &lt;NSValidatedUserInterfaceItem&gt;)item
</span><span class="lines">@@ -3167,7 +3190,7 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><del>-#endif
</del><ins>+#endif // PLATFORM(MAC)
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> @implementation WKWebView (_WKWebViewPrintFormatter)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -125,13 +125,8 @@
</span><span class="cx"> // The viewport meta tag width is negative if the value is not defined.
</span><span class="cx"> @property (nonatomic, readonly) CGFloat _viewportMetaTagWidth;
</span><span class="cx"> 
</span><del>-@property (nonatomic, readonly) CGRect _contentVisibleRect;
-
</del><span class="cx"> @property (nonatomic, readonly) _WKWebViewPrintFormatter *_webViewPrintFormatter;
</span><span class="cx"> 
</span><del>-- (CGPoint)_convertPointFromContentsToView:(CGPoint)point;
-- (CGPoint)_convertPointFromViewToContents:(CGPoint)point;
-
</del><span class="cx"> - (void)_beginInteractiveObscuredInsetsChange;
</span><span class="cx"> - (void)_endInteractiveObscuredInsetsChange;
</span><span class="cx"> - (void)_hideContentUntilNextUpdate;
</span><span class="lines">@@ -217,4 +212,18 @@
</span><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span><ins>+
+@interface WKWebView (WKTesting)
+
+#if TARGET_OS_IPHONE
+@property (nonatomic, readonly) CGRect _contentVisibleRect WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+- (CGPoint)_convertPointFromContentsToView:(CGPoint)point WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+- (CGPoint)_convertPointFromViewToContents:(CGPoint)point WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
</ins><span class="cx"> #endif
</span><ins>+
+- (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
+@end
+
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -6084,6 +6084,11 @@
</span><span class="cx">     m_process-&gt;send(Messages::WebPage::ClearWheelEventTestTrigger(), m_pageID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::callAfterNextPresentationUpdate(std::function&lt;void (CallbackBase::Error)&gt; callback)
+{
+    m_drawingArea-&gt;dispatchAfterEnsuringDrawing(callback);
+}
+
</ins><span class="cx"> void WebPageProxy::setShouldScaleViewToFitDocument(bool shouldScaleViewToFitDocument)
</span><span class="cx"> {
</span><span class="cx">     if (m_shouldScaleViewToFitDocument == shouldScaleViewToFitDocument)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -1057,7 +1057,9 @@
</span><span class="cx">     void didChangeBackgroundColor();
</span><span class="cx">     void didLayoutForCustomContentProvider();
</span><span class="cx"> 
</span><ins>+    // For testing
</ins><span class="cx">     void clearWheelEventTestTrigger();
</span><ins>+    void callAfterNextPresentationUpdate(std::function&lt;void (CallbackBase::Error)&gt;);
</ins><span class="cx"> 
</span><span class="cx">     void didLayout(uint32_t layoutMilestones);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacTiledCoreAnimationDrawingAreaProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.h        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -53,6 +53,7 @@
</span><span class="cx">     virtual void commitTransientZoom(double scale, WebCore::FloatPoint origin) override;
</span><span class="cx"> 
</span><span class="cx">     virtual void waitForDidUpdateViewState() override;
</span><ins>+    virtual void dispatchAfterEnsuringDrawing(std::function&lt;void (CallbackBase::Error)&gt;) override;
</ins><span class="cx"> 
</span><span class="cx">     virtual void willSendUpdateGeometry() override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacTiledCoreAnimationDrawingAreaProxymm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Source/WebKit2/UIProcess/mac/TiledCoreAnimationDrawingAreaProxy.mm        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -206,6 +206,14 @@
</span><span class="cx">     m_webPageProxy.process().send(Messages::DrawingArea::CommitTransientZoom(scale, origin), m_webPageProxy.pageID());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void TiledCoreAnimationDrawingAreaProxy::dispatchAfterEnsuringDrawing(std::function&lt;void (CallbackBase::Error)&gt; callback)
+{
+    // This callback is primarily used for testing in RemoteLayerTreeDrawingArea. We could in theory wait for a CA commit here.
+    dispatch_async(dispatch_get_main_queue(), ^{
+        callback(CallbackBase::Error::None);
+    });
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // !PLATFORM(IOS)
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Tools/ChangeLog        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2015-09-25  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        [iOS WK2] Add viewport tests and fix runUIScript() timing issues
+        https://bugs.webkit.org/show_bug.cgi?id=149577
+
+        Reviewed by Tim Horton.
+        
+        When calling testRunner.runUIScript() from a page load event, the script could run
+        in the UI process before the current remote layer tree transaction had been handled
+        there. This meant that runUIScript() could query state which was about to change.
+        
+        Fix by delaying the execution of the UI script until a layer tree transaction has
+        been handled by the UI process, leveraging the existing DrawingAreaProxy::dispatchAfterEnsuringDrawing().
+
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
+        (WTR::TestInvocation::runUISideScriptAfterUpdateCallback):
+        * WebKitTestRunner/TestInvocation.h:
+
</ins><span class="cx"> 2015-09-25  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Mac] Media tests start to time out after a few days of bot uptime
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestInvocationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -668,10 +668,11 @@
</span><span class="cx">         WKRetainPtr&lt;WKStringRef&gt; scriptKey(AdoptWK, WKStringCreateWithUTF8CString(&quot;Script&quot;));
</span><span class="cx">         WKRetainPtr&lt;WKStringRef&gt; callbackIDKey(AdoptWK, WKStringCreateWithUTF8CString(&quot;CallbackID&quot;));
</span><span class="cx"> 
</span><del>-        unsigned callbackID = (unsigned)WKUInt64GetValue(static_cast&lt;WKUInt64Ref&gt;(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));
-        WKStringRef scriptString = static_cast&lt;WKStringRef&gt;(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));
-
-        runUISideScript(scriptString, callbackID);
</del><ins>+        UIScriptInvocationData* invocationData = new UIScriptInvocationData();
+        invocationData-&gt;testInvocation = this;
+        invocationData-&gt;callbackID = (unsigned)WKUInt64GetValue(static_cast&lt;WKUInt64Ref&gt;(WKDictionaryGetItemForKey(messageBodyDictionary, callbackIDKey.get())));
+        invocationData-&gt;scriptString = static_cast&lt;WKStringRef&gt;(WKDictionaryGetItemForKey(messageBodyDictionary, scriptKey.get()));
+        WKPageCallAfterNextPresentationUpdate(TestController::singleton().mainWebView()-&gt;page(), invocationData, runUISideScriptAfterUpdateCallback);
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -720,6 +721,13 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void TestInvocation::runUISideScriptAfterUpdateCallback(WKErrorRef, void* context)
+{
+    UIScriptInvocationData* data = static_cast&lt;UIScriptInvocationData*&gt;(context);
+    data-&gt;testInvocation-&gt;runUISideScript(data-&gt;scriptString.get(), data-&gt;callbackID);
+    delete data;
+}
+
</ins><span class="cx"> void TestInvocation::runUISideScript(WKStringRef script, unsigned scriptCallbackID)
</span><span class="cx"> {
</span><span class="cx">     if (!m_UIScriptContext)
</span></span></pre></div>
<a id="trunkToolsWebKitTestRunnerTestInvocationh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/WebKitTestRunner/TestInvocation.h (190259 => 190260)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/WebKitTestRunner/TestInvocation.h        2015-09-26 00:13:00 UTC (rev 190259)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.h        2015-09-26 00:17:27 UTC (rev 190260)
</span><span class="lines">@@ -74,6 +74,13 @@
</span><span class="cx">     bool compareActualHashToExpectedAndDumpResults(const char[33]);
</span><span class="cx"> 
</span><span class="cx">     static void forceRepaintDoneCallback(WKErrorRef, void* context);
</span><ins>+    
+    struct UIScriptInvocationData {
+        unsigned callbackID;
+        WebKit::WKRetainPtr&lt;WKStringRef&gt; scriptString;
+        TestInvocation* testInvocation;
+    };
+    static void runUISideScriptAfterUpdateCallback(WKErrorRef, void* context);
</ins><span class="cx"> 
</span><span class="cx">     bool shouldLogFrameLoadDelegates() const;
</span><span class="cx">     bool shouldLogHistoryClientCallbacks() const;
</span></span></pre>
</div>
</div>

</body>
</html>