| | 8 | |
| | 9 | = A simple example = |
| | 10 | |
| | 11 | Let'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 | |
| | 13 | First, 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 | |
| | 19 | then let's put in the viewport settings to test: |
| | 20 | {{{ |
| | 21 | <head> |
| | 22 | <meta name="viewport" content="initial-scale=1.0"> |
| | 23 | ... |
| | 24 | }}} |
| | 25 | |
| | 26 | Now 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 | {{{ |
| | 28 | interface TestRunner { |
| | 29 | ... |
| | 30 | // UI Process Testing |
| | 31 | void runUIScript(DOMString script, object callback); |
| | 32 | }}} |
| | 33 | |
| | 34 | so 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 | }}} |