2
* Copyright 2015 Canonical Ltd.
4
* This file is part of webbrowser-app.
6
* webbrowser-app is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* webbrowser-app is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
import Ubuntu.Test 1.0
22
import "../../../src/app/webbrowser"
30
readonly property bool displayUrl: true
31
readonly property url icon: ""
34
readonly property var model2: []
38
readonly property bool displayUrl: true
39
readonly property url icon: ""
48
models: [model1, model2, model3]
55
signalName: "activated"
63
model1.append({"title": "lorem ipsum", "url": "http://model1/item1"})
64
model1.append({"title": "a+ rating", "url": "http://model1/item2"})
66
model2.push({"title": "Tom & Jerry", "url": "http://model2/item1"})
67
model2.push({"title": "$1 in €", "url": "http://model2/item2"})
68
model2.push({"title": "foo | bar | baz", "url": "http://model2/item3"})
69
model3.append({"title": "(a+b)^2", "url": "http://model3/item1"})
70
model3.append({"title": "Çà et là", "url": "http://model3/item2"})
71
compare(suggestions.count, 7)
80
compare(suggestions.count, 0)
83
function test_highlighting_data() {
84
function highlight(term) {
85
return "<font color=\"%1\">%2</font>".arg("#752571").arg(term)
89
{terms: [], index: 0, title: "lorem ipsum"},
90
{terms: ["a+"], index: 1, title: "<html>%1 rating</html>".arg(highlight("a+"))},
91
{terms: ["a+"], index: 5, title: "<html>(%1b)^2</html>".arg(highlight("a+"))},
92
{terms: ["tom", "jerry"], index: 2, title: "<html>%1 & %2</html>".arg(highlight("Tom")).arg(highlight("Jerry"))},
93
{terms: ["$"], index: 3, title: "<html>%991 in €</html>".arg(highlight("$"))},
94
{terms: ["|"], index: 4, title: "<html>foo %1 bar %1 baz</html>".arg(highlight("|"))},
95
{terms: ["(", ")"], index: 5, title: "<html>%1a+b%2^2</html>".arg(highlight("(")).arg(highlight(")"))},
96
{terms: ["à", "ET"], index: 6, title: "<html>Ç%1 %2 l%1</html>".arg(highlight("à")).arg(highlight("et"))},
100
function test_highlighting(data) {
101
suggestions.searchTerms = data.terms
102
var delegate = findChild(suggestions, "suggestionDelegate_" + data.index)
103
compare(delegate.title, data.title)
106
function test_mouseActivation() {
107
var delegate = findChild(suggestions, "suggestionDelegate_4")
108
var center = centerOf(delegate)
109
mouseClick(delegate, center.x, center.y)
110
compare(activatedSpy.count, 1)
111
compare(activatedSpy.signalArguments[0][0], "http://model2/item3")
114
function test_keyboardActivation() {
115
var listview = findChild(suggestions, "suggestionsList")
116
compare(listview.currentIndex, 0)
117
keyClick(Qt.Key_Down)
118
keyClick(Qt.Key_Down)
119
compare(listview.currentIndex, 2)
120
keyClick(Qt.Key_Return)
121
compare(activatedSpy.count, 1)
122
compare(activatedSpy.signalArguments[0][0], "http://model2/item1")