~uriboni/webbrowser-app/tab-context-menu

« back to all changes in this revision

Viewing changes to tests/unittests/qml/tst_Suggestions.qml

  • Committer: CI Train Bot
  • Author(s): Olivier Tilloy
  • Date: 2015-08-11 11:18:43 UTC
  • mfrom: (1115.1.5 highlightTerms-in-one-pass)
  • Revision ID: ci-train-bot@canonical.com-20150811111843-k6nferv7frcqxa2z
Highlight matching terms in one pass. Fixes: #1481206
Approved by: PS Jenkins bot, Ugo Riboni

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
4
 * This file is part of webbrowser-app.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.0
 
20
import QtTest 1.0
 
21
import Ubuntu.Test 1.0
 
22
import "../../../src/app/webbrowser"
 
23
 
 
24
Item {
 
25
    width: 300
 
26
    height: 300
 
27
 
 
28
    ListModel {
 
29
        id: model1
 
30
        readonly property bool displayUrl: true
 
31
        readonly property url icon: ""
 
32
    }
 
33
 
 
34
    readonly property var model2: []
 
35
 
 
36
    ListModel {
 
37
        id: model3
 
38
        readonly property bool displayUrl: true
 
39
        readonly property url icon: ""
 
40
    }
 
41
 
 
42
    Suggestions {
 
43
        id: suggestions
 
44
 
 
45
        focus: true
 
46
        anchors.fill: parent
 
47
 
 
48
        models: [model1, model2, model3]
 
49
        searchTerms: []
 
50
    }
 
51
 
 
52
    SignalSpy {
 
53
        id: activatedSpy
 
54
        target: suggestions
 
55
        signalName: "activated"
 
56
    }
 
57
 
 
58
    UbuntuTestCase {
 
59
        name: "Suggestions"
 
60
        when: windowShown
 
61
 
 
62
        function init() {
 
63
            model1.append({"title": "lorem ipsum", "url": "http://model1/item1"})
 
64
            model1.append({"title": "a+ rating", "url": "http://model1/item2"})
 
65
            model2.icon = ""
 
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)
 
72
            activatedSpy.clear()
 
73
        }
 
74
 
 
75
        function cleanup() {
 
76
            activatedSpy.clear()
 
77
            model3.clear()
 
78
            model2.splice(0, 3)
 
79
            model1.clear()
 
80
            compare(suggestions.count, 0)
 
81
        }
 
82
 
 
83
        function test_highlighting_data() {
 
84
            function highlight(term) {
 
85
                return "<font color=\"%1\">%2</font>".arg("#752571").arg(term)
 
86
            }
 
87
 
 
88
            return [
 
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 &amp; %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"))},
 
97
            ]
 
98
        }
 
99
 
 
100
        function test_highlighting(data) {
 
101
            suggestions.searchTerms = data.terms
 
102
            var delegate = findChild(suggestions, "suggestionDelegate_" + data.index)
 
103
            compare(delegate.title, data.title)
 
104
        }
 
105
 
 
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")
 
112
        }
 
113
 
 
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")
 
123
        }
 
124
    }
 
125
}