Changes between Version 1 and Version 2 of Writing Layout Tests to test iOS UI features


Ignore:
Timestamp:
Sep 30, 2015 3:08:47 PM (7 years ago)
Author:
Simon Fraser
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Writing Layout Tests to test iOS UI features

    v1 v2  
    66
    77The UI script itself runs asynchronously, and many of the UIScriptController functions are asynchronous. Callbacks are used to tell the test when something completes.
     8
     9= A simple example =
     10
     11Let's say we want to write a test that reads back the zoom scale of the WKWebView's UIScrollView (e.g. to test viewport scale).
     12
     13First, since we're testing viewport zooming, we need to have the test opt into iOS-style viewport behavior with an HTML comment after the doctype:
     14
     15{{{
     16<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
     17}}}
     18
     19then let's put in the viewport settings to test:
     20{{{
     21<head>
     22    <meta name="viewport" content="initial-scale=1.0">
     23...
     24}}}
     25
     26Now we want to write some script to read the zoom scale in the UI process. TestRunner now has a runUIScript() function, which takes a string and a callback:
     27{{{
     28interface TestRunner {
     29    ...
     30    // UI Process Testing
     31    void runUIScript(DOMString script, object callback);
     32}}}
     33
     34so we can use this in our test in some script that would run from the onload handler:
     35{{{
     36        function runTest()
     37        {
     38            testRunner.waitUntilDone();
     39            if (testRunner.runUIScript) {
     40                testRunner.runUIScript("...", function(result) {
     41                    document.getElementById('target').innerText = result;
     42                    testRunner.notifyDone();
     43                });
     44            }
     45        }
     46}}}