[Qt] [WK2] Support customizing popup menus with QML
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / qt / tests / qmltests / WebView / tst_itemSelector.qml
1 import QtQuick 2.0
2 import QtTest 1.0
3 import QtWebKit 3.0
4 import QtWebKit.experimental 3.0
5
6 // FIXME: used because we want to have mouseClick() to open the <select> tag. We can remove this
7 // when TestCase starts supporting touch events, see https://bugreports.qt.nokia.com/browse/QTBUG-23083.
8 import "../DesktopBehavior"
9
10 DesktopWebView {
11     id: webView
12
13     width: 400
14     height: 400
15
16     property int initialSelection
17     property int finalSelection
18     property bool useAcceptDirectly
19     property bool selectorLoaded
20
21     experimental.itemSelector: Item {
22         Component.onCompleted: {
23             if (WebView.view.initialSelection != -1)
24                 model.items.select(WebView.view.initialSelection)
25
26             if (WebView.view.finalSelection == -1)
27                 model.reject()
28             else {
29                 if (useAcceptDirectly) {
30                     model.accept(WebView.view.finalSelection)
31                 } else {
32                     model.items.select(WebView.view.finalSelection)
33                     model.accept()
34                 }
35             }
36
37             WebView.view.selectorLoaded = true
38         }
39     }
40
41     SignalSpy {
42         id: loadSpy
43         target: webView
44         signalName: "loadSucceeded"
45     }
46
47     SignalSpy {
48         id: titleSpy
49         target: webView
50         signalName: "titleChanged"
51     }
52
53     TestCase {
54         id: test
55         name: "WebViewItemSelector"
56         when: windowShown
57
58         function init() {
59             webView.initialSelection = -1
60             webView.finalSelection = -1
61             webView.useAcceptDirectly = false
62             webView.selectorLoaded = false
63             loadSpy.clear()
64             webView.load(Qt.resolvedUrl("../common/select.html"))
65             loadSpy.wait()
66             titleSpy.clear()
67         }
68
69         function openItemSelector() {
70             mouseClick(webView, 15, 15, Qt.LeftButton)
71         }
72
73         function test_accept() {
74             webView.finalSelection = 1
75             openItemSelector()
76             titleSpy.wait()
77             compare(webView.title, "__closed__")
78         }
79
80         function test_acceptDirectly() {
81             webView.finalSelection = 1
82             webView.useAcceptDirectly = true
83             openItemSelector()
84             titleSpy.wait()
85             compare(webView.title, "__closed__")
86         }
87
88         function test_selectFirstThenAccept() {
89             webView.initialSelection = 1
90             webView.finalSelection = 2
91             openItemSelector()
92             titleSpy.wait()
93             compare(webView.title, "__all__")
94         }
95
96         function test_selectFirstThenAcceptDirectly() {
97             webView.initialSelection = 1
98             webView.finalSelection = 2
99             webView.useAcceptDirectly = true
100             openItemSelector()
101             titleSpy.wait()
102             compare(webView.title, "__all__")
103         }
104
105         function test_reject() {
106             openItemSelector()
107             tryCompare(webView, "selectorLoaded", true)
108             compare(webView.title, "No new selection was made")
109         }
110
111         function test_selectFirstThenReject() {
112             webView.initialSelection = 1
113             webView.finalSelection = -1
114             openItemSelector()
115             tryCompare(webView, "selectorLoaded", true)
116             compare(webView.title, "No new selection was made")
117         }
118     }
119 }