~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: 480
 
12
        height: 720
 
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 style='margin: 0px'>" +
 
21
            "    <div id='target' style='display:none; width:960px; height:1440px;'></div>" +
 
22
            "</body>"
 
23
 
 
24
        signal resultReceived
 
25
    }
 
26
 
 
27
    SignalSpy {
 
28
        id: resultSpy
 
29
        target: webView
 
30
        signalName: "resultReceived"
 
31
    }
 
32
 
 
33
    SignalSpy {
 
34
        id: scaleSpy
 
35
        target: webView.experimental.test
 
36
        signalName: "contentsScaleCommitted"
 
37
    }
 
38
 
 
39
    TestCase {
 
40
        name: "FitToView"
 
41
        when: windowShown
 
42
 
 
43
        property variant test: webView.experimental.test
 
44
 
 
45
        function init() {
 
46
            resultSpy.clear()
 
47
            scaleSpy.clear()
 
48
        }
 
49
 
 
50
        function run(signalSpy, script) {
 
51
            signalSpy.clear();
 
52
            var result;
 
53
             webView.experimental.evaluateJavaScript(
 
54
                script, function(value) { webView.resultReceived(); result = value });
 
55
            signalSpy.wait();
 
56
            return result;
 
57
        }
 
58
 
 
59
        function documentSize() {
 
60
            return run(resultSpy, "document.width + 'x' + document.height");
 
61
        }
 
62
 
 
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 + "';");
 
69
        }
 
70
 
 
71
        function test_basic() {
 
72
            webView.url = webView.content
 
73
            verify(webView.waitForViewportReady())
 
74
 
 
75
            compare(documentSize(), "480x720")
 
76
            compare(test.contentsScale, 1.0)
 
77
 
 
78
            setDisplay("target", "block")
 
79
            compare(documentSize(), "960x1440")
 
80
            compare(test.contentsScale, 0.5)
 
81
 
 
82
            // Add user interaction.
 
83
            test.touchTap(webView, 10, 10)
 
84
 
 
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)
 
90
 
 
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)
 
95
        }
 
96
 
 
97
        function test_localPageDeviceWidth() {
 
98
            webView.url = "about:blank"
 
99
            verify(webView.waitForLoadSucceeded())
 
100
 
 
101
            webView.url = "../common/test5.html"
 
102
            verify(webView.waitForLoadSucceeded())
 
103
            compare(test.contentsScale, 0.5)
 
104
 
 
105
            // Add user interaction.
 
106
            test.touchTap(webView, 10, 10)
 
107
 
 
108
            webView.reload()
 
109
            verify(webView.waitForLoadSucceeded())
 
110
            // The page should still fit to view after a reload
 
111
            compare(test.contentsScale, 0.5)
 
112
        }
 
113
 
 
114
        function test_localPageInitialScale() {
 
115
            webView.url = "about:blank"
 
116
            verify(webView.waitForLoadSucceeded())
 
117
 
 
118
            webView.url = "../common/test4.html"
 
119
            verify(webView.waitForLoadSucceeded())
 
120
 
 
121
            compare(test.contentsScale, 2.0)
 
122
 
 
123
            // Add user interaction.
 
124
            test.touchTap(webView, 10, 10)
 
125
 
 
126
            webView.reload()
 
127
            verify(webView.waitForLoadSucceeded())
 
128
            compare(test.contentsScale, 2.0)
 
129
        }
 
130
    }
 
131
}