Add test expectation for one more test having color space issues after r156793.
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / qt / tests / qmltests / WebView / tst_resize.qml
1 import QtQuick 2.0
2 import QtTest 1.0
3 import QtWebKit 3.0
4 import QtWebKit.experimental 1.0
5 import Test 1.0
6 import "../common"
7
8 Item {
9     TestWebView {
10         id: webView
11         width: 320
12         height: 480
13
14         property variant result
15
16         property variant content: "data:text/html," +
17             "<head>" +
18             "    <meta name='viewport' content='width=device-width'>" +
19             "</head>" +
20             "<body>" +
21             "    <div id='target' style='width: 240px; height: 360px;'>" +
22             "    </div>" +
23             "</body>"
24
25         signal resultReceived
26     }
27
28     SignalSpy {
29         id: resultSpy
30         target: webView
31         signalName: "resultReceived"
32     }
33
34     SignalSpy {
35         id: scaleSpy
36         target: webView.experimental.test
37         signalName: "contentsScaleCommitted"
38     }
39
40     SignalSpy {
41         id: sizeSpy
42         target: webView.experimental.test
43         signalName: "contentsSizeChanged"
44     }
45
46     TestCase {
47         name: "Resize"
48         when: windowShown
49
50         property variant test: webView.experimental.test
51
52         function init() {
53             resultSpy.clear()
54             scaleSpy.clear()
55             sizeSpy.clear()
56         }
57
58         function run(signalSpy, script) {
59             signalSpy.clear();
60             var result;
61             webView.experimental.evaluateJavaScript(
62                 script,
63                 function(value) { webView.resultReceived(); result = value });
64             signalSpy.wait();
65             return result;
66         }
67
68         function contentsSize() {
69             return test.contentsSize.width + "x" + test.contentsSize.height;
70         }
71
72         function elementRect(id) {
73             return JSON.parse(run(resultSpy, "JSON.stringify(document.getElementById('" + id + "').getBoundingClientRect());"))
74         }
75
76         function doubleTapAtPoint(x, y) {
77             scaleSpy.clear()
78             test.touchDoubleTap(webView, x, y)
79             scaleSpy.wait()
80         }
81
82         function resize(w, h) {
83             sizeSpy.clear()
84             webView.width = w
85             sizeSpy.wait()
86             webView.height = h
87             sizeSpy.wait()
88         }
89
90         function test_basic() {
91             webView.url = webView.content
92             verify(webView.waitForViewportReady())
93
94             compare(contentsSize(), "320x480")
95             compare(test.contentsScale, 1.0)
96
97             resize(480, 720)
98             compare(contentsSize(), "480x720")
99             compare(test.contentsScale, 1.0)
100
101             resize(320, 480)
102             compare(contentsSize(), "320x480")
103             compare(test.contentsScale, 1.0)
104
105         }
106
107         function test_resizeAfterNeutralZoom() {
108             webView.url = webView.content
109             verify(webView.waitForViewportReady())
110
111             compare(contentsSize(), "320x480")
112             compare(test.contentsScale, 1.0)
113
114             var target = elementRect("target");
115             var targetScale = webView.width / (target.width + 2 * 10) // inflated by 10px
116
117             // Zoom in and out.
118             doubleTapAtPoint(100, 50)
119
120             compare(test.contentsScale, targetScale)
121
122             doubleTapAtPoint(100, 50)
123
124             compare(test.contentsScale, 1.0)
125
126             // Now check resizing still works as expected.
127             resize(480, 720)
128             compare(contentsSize(), "480x720")
129             compare(test.contentsScale, 1.0)
130
131             resize(320, 480)
132             compare(contentsSize(), "320x480")
133             compare(test.contentsScale, 1.0)
134         }
135
136         function test_resizeZoomedIn() {
137             // Note that if we change the behavior of resize on zoomed-in content, for instance
138             // to preserve the visible width (like rotate), this test will need to be updated.
139             webView.url = webView.content
140             verify(webView.waitForViewportReady())
141
142             compare(contentsSize(), "320x480")
143             compare(test.contentsScale, 1.0)
144
145             var target = elementRect("target");
146             var targetScale = webView.width / (target.width + 2 * 10) // inflated by 10px
147
148             // Double tap to zoom in.
149             doubleTapAtPoint(100, 50)
150
151             compare(test.contentsScale, targetScale)
152
153             // Resize just a small bit, not changing scale.
154             resize(288, 432)
155             compare(contentsSize(), "288x432")
156             compare(test.contentsScale, targetScale)
157
158             // And double tap to reset zoom.
159             target = elementRect("target");
160             targetScale = webView.width / (target.width + 2 * 10)
161             doubleTapAtPoint(100, 50)
162             compare(test.contentsScale, targetScale)
163
164             // Double tap again to zoom out.
165             doubleTapAtPoint(100, 50)
166             compare(contentsSize(), "288x432")
167             compare(test.contentsScale, 1.0)
168
169             // And reset
170             resize(320, 480)
171             compare(contentsSize(), "320x480")
172             compare(test.contentsScale, 1.0)
173         }
174     }
175 }