2011-11-23 Yury Semikhatsky <yurys@chromium.org>
[WebKit.git] / Source / WebKit2 / UIProcess / API / qt / tests / qmltests / DesktopBehavior / tst_navigationRequested.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         onNavigationRequested: {
12             if (request.button == Qt.MiddleButton && request.modifiers & Qt.ControlModifier) {
13                 otherWebView.load(request.url)
14                 request.action = WebView.IgnoreRequest
15             }
16         }
17     }
18
19     SignalSpy {
20         id: spy
21         target: webView
22         signalName: "loadSucceeded"
23     }
24
25     DesktopWebView {
26         id: otherWebView
27     }
28
29     SignalSpy {
30         id: otherSpy
31         target: otherWebView
32         signalName: "loadSucceeded"
33     }
34
35     TestCase {
36         name: "DesktopWebViewNavigationRequested"
37
38         // Delayed windowShown to workaround problems with Qt5 in debug mode.
39         when: false
40         Timer {
41             running: parent.windowShown
42             repeat: false
43             interval: 1
44             onTriggered: parent.when = true
45         }
46
47         function test_usePolicy() {
48             webView.load(Qt.resolvedUrl("../common/test2.html"))
49             spy.wait()
50             spy.clear()
51             mouseClick(webView, 100, 100, Qt.LeftButton)
52             spy.wait()
53             compare(spy.count, 1)
54             compare(webView.title, "Test page 1")
55         }
56
57         function test_ignorePolicy() {
58             webView.load(Qt.resolvedUrl("../common/test2.html"))
59             spy.wait()
60             spy.clear()
61             compare(spy.count, 0)
62             compare(otherSpy.count, 0)
63             mouseClick(webView, 100, 100, Qt.MiddleButton, Qt.ControlModifier)
64             otherSpy.wait()
65             compare(spy.count, 0)
66             compare(otherSpy.count, 1)
67             compare(otherWebView.title, "Test page 1")
68         }
69     }
70 }