4
import QtWebKit.experimental 1.0
14
property variant result
16
property variant content: "data:text/html," +
18
" <meta name='viewport' content='width=device-width'>" +
20
"<body style='margin: 0px'>" +
21
" <div id='target' style='display:none; width:960px; height:1440px;'></div>" +
30
signalName: "resultReceived"
35
target: webView.experimental.test
36
signalName: "contentsScaleCommitted"
43
property variant test: webView.experimental.test
50
function run(signalSpy, script) {
53
webView.experimental.evaluateJavaScript(
54
script, function(value) { webView.resultReceived(); result = value });
59
function documentSize() {
60
return run(resultSpy, "document.width + 'x' + document.height");
63
function setDisplay(id, value) {
64
// When changing to/from 'none' to 'block', this will result in a
65
// contentsScaleCommitted scale, even if it results in the same
66
// scale, making it possible to check whether user interaction
67
// blocks fit-to-view or not.
68
run(scaleSpy, "document.getElementById('" + id + "').style.display = '" + value + "';");
71
function test_basic() {
72
webView.url = webView.content
73
verify(webView.waitForViewportReady())
75
compare(documentSize(), "480x720")
76
compare(test.contentsScale, 1.0)
78
setDisplay("target", "block")
79
compare(documentSize(), "960x1440")
80
compare(test.contentsScale, 0.5)
82
// Add user interaction.
83
test.touchTap(webView, 10, 10)
85
// We are no longer within valid bounds after this change
86
// so we have to change our scale back to 1.0.
87
setDisplay("target", "none")
88
compare(documentSize(), "480x720")
89
compare(test.contentsScale, 1.0)
91
// We had user interaction, size should change but not scale.
92
setDisplay("target", "block")
93
compare(documentSize(), "960x1440")
94
compare(test.contentsScale, 1.0)
97
function test_localPageDeviceWidth() {
98
webView.url = "about:blank"
99
verify(webView.waitForLoadSucceeded())
101
webView.url = "../common/test5.html"
102
verify(webView.waitForLoadSucceeded())
103
compare(test.contentsScale, 0.5)
105
// Add user interaction.
106
test.touchTap(webView, 10, 10)
109
verify(webView.waitForLoadSucceeded())
110
// The page should still fit to view after a reload
111
compare(test.contentsScale, 0.5)
114
function test_localPageInitialScale() {
115
webView.url = "about:blank"
116
verify(webView.waitForLoadSucceeded())
118
webView.url = "../common/test4.html"
119
verify(webView.waitForLoadSucceeded())
121
compare(test.contentsScale, 2.0)
123
// Add user interaction.
124
test.touchTap(webView, 10, 10)
127
verify(webView.waitForLoadSucceeded())
128
compare(test.contentsScale, 2.0)