OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 |
| 4 <script src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></s
cript> |
| 5 |
| 6 <style> |
| 7 body { |
| 8 margin: 0; |
| 9 overflow: hidden; |
| 10 min-width: 2000px; |
| 11 min-height: 10000px; |
| 12 } |
| 13 |
| 14 div#layoutViewportDiv { |
| 15 position: fixed; |
| 16 z-index: 100; |
| 17 width: 100%; |
| 18 height: 100%; |
| 19 } |
| 20 </style> |
| 21 |
| 22 <script> |
| 23 function dumpMetrics() |
| 24 { |
| 25 return JSON.stringify({ |
| 26 visualWidth: window.innerWidth, |
| 27 visualHeight: window.innerHeight, |
| 28 layoutWidth: document.getElementById("layoutViewportDiv").clientWidth, |
| 29 layoutHeight: document.getElementById("layoutViewportDiv").clientHeight, |
| 30 scrollX: window.visualViewport.pageX - window.visualViewport.scrollLeft, |
| 31 scrollY: window.visualViewport.pageY - window.visualViewport.scrollTop, |
| 32 visualScrollX: window.visualViewport.scrollLeft, |
| 33 visualScrollY: window.visualViewport.scrollTop, |
| 34 visualScale: window.visualViewport.scale |
| 35 }, null, 4); |
| 36 } |
| 37 |
| 38 function test() |
| 39 { |
| 40 function printMetrics(callback) |
| 41 { |
| 42 InspectorTest.evaluateInPage("dumpMetrics()", print); |
| 43 |
| 44 function print(metrics) |
| 45 { |
| 46 InspectorTest.log(metrics); |
| 47 callback(); |
| 48 } |
| 49 } |
| 50 |
| 51 function testOverrides(width, height, visualWidth, visualHeight, scrollX, sc
rollY, visualX, visualY, visualScale, next) |
| 52 { |
| 53 var metricsParams = { |
| 54 width: width, |
| 55 height: height, |
| 56 visualViewportWidth: visualWidth, |
| 57 visualViewportHeight: visualHeight, |
| 58 deviceScaleFactor: 0, |
| 59 mobile: false, |
| 60 fitWindow: false |
| 61 }; |
| 62 var scrollParams = {}; |
| 63 if (scrollX >= 0) |
| 64 scrollParams['scrollPositionX'] = scrollX; |
| 65 if (scrollY >= 0) |
| 66 scrollParams['scrollPositionY'] = scrollY; |
| 67 if (visualX >= 0) |
| 68 scrollParams['visualViewportPositionX'] = visualX; |
| 69 if (visualY >= 0) |
| 70 scrollParams['visualViewportPositionY'] = visualY; |
| 71 if (visualScale > 0) |
| 72 scrollParams['visualViewportScale'] = visualScale; |
| 73 InspectorTest.log("Device metrics overrides: " + JSON.stringify(metricsP
arams)); |
| 74 InspectorTest.log("Scroll/scale overrides: " + JSON.stringify(scrollPara
ms)); |
| 75 |
| 76 InspectorTest.sendCommandOrDie("Emulation.setDeviceMetricsOverride", met
ricsParams, metricsOverrideActive); |
| 77 |
| 78 function metricsOverrideActive() |
| 79 { |
| 80 InspectorTest.sendCommandOrDie("Emulation.setScrollAndScaleOverride"
, scrollParams, printMetrics.bind(null, allOverridesActive)); |
| 81 } |
| 82 |
| 83 function allOverridesActive() |
| 84 { |
| 85 InspectorTest.log("Clearing overrides."); |
| 86 InspectorTest.sendCommandOrDie("Emulation.clearScrollAndScaleOverrid
e", {}, scrollOverrideCleared); |
| 87 |
| 88 function scrollOverrideCleared() |
| 89 { |
| 90 InspectorTest.sendCommandOrDie("Emulation.clearDeviceMetricsOver
ride", {}, printMetrics.bind(null, next)); |
| 91 } |
| 92 } |
| 93 } |
| 94 |
| 95 InspectorTest.runTestSuite([ |
| 96 function noOverrides(next) |
| 97 { |
| 98 testOverrides(0, 0, 0, 0, -1, -1, -1, -1, 0, next); |
| 99 }, |
| 100 |
| 101 function frameScrollX(next) |
| 102 { |
| 103 testOverrides(400, 200, 0, 0, 200, -1, -1, -1, 0, next); |
| 104 }, |
| 105 |
| 106 function frameScrollY(next) |
| 107 { |
| 108 testOverrides(400, 200, 0, 0, -1, 600, -1, -1, 0, next); |
| 109 }, |
| 110 |
| 111 function frameScrollXWithResizedVisualViewport(next) |
| 112 { |
| 113 testOverrides(400, 200, 200, 100, 200, -1, -1, -1, 0, next); |
| 114 }, |
| 115 |
| 116 function frameScrollYWithResizedVisualViewport(next) |
| 117 { |
| 118 testOverrides(400, 200, 200, 100, -1, 600, -1, -1, 0, next); |
| 119 }, |
| 120 |
| 121 function visualScrollX(next) |
| 122 { |
| 123 testOverrides(400, 200, 200, 100, -1, -1, 100, -1, 0, next); |
| 124 }, |
| 125 |
| 126 function visualScrollY(next) |
| 127 { |
| 128 testOverrides(400, 200, 200, 100, -1, -1, -1, 50, 0, next); |
| 129 }, |
| 130 |
| 131 function visualScale(next) |
| 132 { |
| 133 testOverrides(400, 200, 200, 100, -1, -1, -1, -1, 2.0, next); |
| 134 }, |
| 135 |
| 136 function visualScrollAndScale(next) |
| 137 { |
| 138 testOverrides(400, 200, 200, 100, -1, -1, 100, 50, 2.0, next); |
| 139 }, |
| 140 |
| 141 function scrollFrameAndVisual(next) |
| 142 { |
| 143 testOverrides(400, 200, 200, 100, 200, 600, 100, 50, 0, next); |
| 144 }, |
| 145 |
| 146 function scrollFrameAndVisualMax(next) |
| 147 { |
| 148 testOverrides(400, 200, 200, 100, 100000, 100000, 100000, 100000, 0,
next); |
| 149 }, |
| 150 |
| 151 function scrollAndScaleFrameAndVisual(next) |
| 152 { |
| 153 testOverrides(400, 200, 200, 100, 200, 600, 100, 50, 2.0, next); |
| 154 }, |
| 155 |
| 156 function scrollAndScaleFrameAndVisualMax(next) |
| 157 { |
| 158 testOverrides(400, 200, 200, 100, 100000, 100000, 100000, 100000, 2.
0, next); |
| 159 }, |
| 160 ]); |
| 161 } |
| 162 </script> |
| 163 |
| 164 </head> |
| 165 <body onload="runTest()"> |
| 166 <div id="layoutViewportDiv"></div> |
| 167 <p> |
| 168 Tests overrides for frame scroll position and visual viewport scroll position an
d scale. |
| 169 </p> |
| 170 </body> |
| 171 </html> |
OLD | NEW |