2011-11-23 Yury Semikhatsky <yurys@chromium.org>
[WebKit.git] / Source / WebKit2 / UIProcess / API / qt / tests / qmltests / DesktopBehavior / tst_navigationPolicyForUrl.qml
1 import QtQuick 2.0
2 import QtTest 1.0
3 import QtWebKit 3.0
4 import QtWebKitTest 1.0
5
6 Item {
7     DesktopWebView {
8         id: webView
9         width: 200
10         height: 200
11         function navigationPolicyForUrl(url, button, modifiers) {
12             if (button == Qt.MiddleButton && modifiers & Qt.ControlModifier) {
13                 otherWebView.load(url)
14                 return DesktopWebView.IgnorePolicy
15             }
16             return DesktopWebView.UsePolicy
17         }
18     }
19
20     SignalSpy {
21         id: spy
22         target: webView
23         signalName: "loadSucceeded"
24     }
25
26     DesktopWebView {
27         id: otherWebView
28     }
29
30     SignalSpy {
31         id: otherSpy
32         target: otherWebView
33         signalName: "loadSucceeded"
34     }
35
36     TestCase {
37         name: "DesktopWebViewNavigationPolicyForUrl"
38
39         // Delayed windowShown to workaround problems with Qt5 in debug mode.
40         when: false
41         Timer {
42             running: parent.windowShown
43             repeat: false
44             interval: 1
45             onTriggered: parent.when = true
46         }
47
48         function test_usePolicy() {
49             webView.load(Qt.resolvedUrl("../common/test2.html"))
50             spy.wait()
51             spy.clear()
52             compare(spy.count, 0)
53             mouseClick(webView, 100, 100, Qt.LeftButton)
54             spy.wait()
55             compare(spy.count, 1)
56             compare(webView.title, "Test page 1")
57         }
58
59         function test_ignorePolicy() {
60             webView.load(Qt.resolvedUrl("../common/test2.html"))
61             spy.wait()
62             spy.clear()
63             compare(spy.count, 0)
64             compare(otherSpy.count, 0)
65             mouseClick(webView, 100, 100, Qt.MiddleButton, Qt.ControlModifier)
66             otherSpy.wait()
67             compare(spy.count, 0)
68             compare(otherSpy.count, 1)
69             compare(otherWebView.title, "Test page 1")
70         }
71     }
72 }