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

« back to all changes in this revision

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

  • Committer: CI Train Bot
  • Author(s): Arthur Mello, Ugo Riboni, Olivier Tilloy
  • Date: 2015-08-12 19:53:13 UTC
  • mfrom: (1126.1.5 wide-views-newtab-history)
  • Revision ID: ci-train-bot@canonical.com-20150812195313-u5v7kzrj8hfiacsj
Wide screen versions of the history view and new tab view, per design specification.
This adds a build dependency on qml-module-qt-labs-settings (for unit tests). Fixes: #1351157, #1481647

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.4
 
20
import QtTest 1.0
 
21
import Ubuntu.Components 1.3
 
22
import Ubuntu.Components.ListItems 1.3 as ListItems
 
23
import Ubuntu.Test 1.0
 
24
import "../../../src/app/webbrowser"
 
25
 
 
26
Item {
 
27
    id: root
 
28
 
 
29
    width: 700
 
30
    height: 500
 
31
 
 
32
    HistoryViewWide {
 
33
        id: historyViewWide
 
34
        anchors.fill: parent
 
35
        historyModel: HistoryModel {
 
36
            id: historyMockModel
 
37
            databasePath: ":memory:"
 
38
        }
 
39
    }
 
40
 
 
41
    SignalSpy {
 
42
        id: doneSpy
 
43
        target: historyViewWide
 
44
        signalName: "done"
 
45
    }
 
46
 
 
47
    SignalSpy {
 
48
        id: newTabRequestedSpy
 
49
        target: historyViewWide
 
50
        signalName: "newTabRequested"
 
51
    }
 
52
 
 
53
    SignalSpy {
 
54
        id: historyEntryClickedSpy
 
55
        target: historyViewWide
 
56
        signalName: "historyEntryClicked"
 
57
    }
 
58
 
 
59
    SignalSpy {
 
60
        id: historyEntryRemovedSpy
 
61
        target: historyViewWide
 
62
        signalName: "historyEntryRemoved"
 
63
    }
 
64
 
 
65
    UbuntuTestCase {
 
66
        name: "HistoryViewWide"
 
67
        when: windowShown
 
68
 
 
69
        function clickItem(item) {
 
70
            var center = centerOf(item)
 
71
            mouseClick(item, center.x, center.y)
 
72
        }
 
73
 
 
74
        function longPressItem(item) {
 
75
            var center = centerOf(item)
 
76
            mousePress(item, center.x, center.y)
 
77
            mouseRelease(item, center.x, center.y, Qt.LeftButton, Qt.NoModifier, 2000)
 
78
        }
 
79
 
 
80
        function swipeItemRight(item) {
 
81
            var center = centerOf(item)
 
82
            mousePress(item, center.x, center.y)
 
83
            mouseRelease(item, center.x + 100, center.y, Qt.LeftButton, Qt.NoModifier, 2000)
 
84
        }
 
85
 
 
86
        function initTestCase() {
 
87
            for (var i = 0; i < 3; ++i) {
 
88
                historyMockModel.add("http://example.org/" + i, "Example Domain " + i, "")
 
89
            }
 
90
            var urlsList = findChild(historyViewWide, "urlsListView")
 
91
            tryCompare(urlsList, "count", 3)
 
92
            waitForRendering(urlsList)
 
93
        }
 
94
 
 
95
        function test_done_button() {
 
96
            var doneButton = findChild(historyViewWide, "doneButton")
 
97
            verify(doneButton != null)
 
98
            doneSpy.clear()
 
99
            compare(doneSpy.count, 0)
 
100
            clickItem(doneButton)
 
101
            compare(doneSpy.count, 1)
 
102
        }
 
103
 
 
104
        function test_new_tab_button() {
 
105
            var newTabButton = findChild(historyViewWide, "newTabButton")
 
106
            verify(newTabButton != null)
 
107
            doneSpy.clear()
 
108
            newTabRequestedSpy.clear()
 
109
            compare(doneSpy.count, 0)
 
110
            compare(newTabRequestedSpy.count, 0)
 
111
            clickItem(newTabButton)
 
112
            compare(newTabRequestedSpy.count, 1)
 
113
            compare(doneSpy.count, 1)
 
114
        }
 
115
 
 
116
        function test_history_entry_clicked() {
 
117
            var urlsList = findChild(historyViewWide, "urlsListView")
 
118
            compare(urlsList.count, 3)
 
119
            compare(historyEntryClickedSpy.count, 0)
 
120
            clickItem(urlsList.children[0])
 
121
            compare(historyEntryClickedSpy.count, 1)
 
122
            var args = historyEntryClickedSpy.signalArguments[0]
 
123
            var entry = urlsList.model.get(0)
 
124
            compare(args[0], entry.url)
 
125
        }
 
126
 
 
127
        function test_selection_mode() {
 
128
            var urlsList = findChild(historyViewWide, "urlsListView")
 
129
            compare(urlsList.count, 3)
 
130
            var backButton = findChild(historyViewWide, "backButton")
 
131
            var selectButton = findChild(historyViewWide, "selectButton")
 
132
            var deleteButton = findChild(historyViewWide, "deleteButton")
 
133
            verify(!backButton.visible)
 
134
            verify(!selectButton.visible)
 
135
            verify(!deleteButton.visible)
 
136
            longPressItem(urlsList.children[0])
 
137
            verify(backButton.visible)
 
138
            verify(selectButton.visible)
 
139
            verify(deleteButton.visible)
 
140
            clickItem(backButton)
 
141
            verify(!backButton.visible)
 
142
            verify(!selectButton.visible)
 
143
            verify(!deleteButton.visible)
 
144
        }
 
145
 
 
146
        function test_toggle_select_button() {
 
147
            var urlsList = findChild(historyViewWide, "urlsListView")
 
148
            compare(urlsList.count, 3)
 
149
            longPressItem(urlsList.children[0])
 
150
            var selectedIndices = urlsList.ViewItems.selectedIndices
 
151
            compare(selectedIndices.length, 1)
 
152
            var selectButton = findChild(historyViewWide, "selectButton")
 
153
            clickItem(selectButton)
 
154
            compare(selectedIndices.length, urlsList.count)
 
155
            clickItem(selectButton)
 
156
            var backButton = findChild(historyViewWide, "backButton")
 
157
            clickItem(backButton)
 
158
        }
 
159
 
 
160
        function test_delete_button() {
 
161
            var urlsList = findChild(historyViewWide, "urlsListView")
 
162
            compare(urlsList.count, 3)
 
163
            longPressItem(urlsList.children[0])
 
164
            var deleteButton = findChild(historyViewWide, "deleteButton")
 
165
            compare(historyEntryRemovedSpy.count, 0)
 
166
            clickItem(deleteButton)
 
167
            compare(historyEntryRemovedSpy.count, 1)
 
168
            var args = historyEntryRemovedSpy.signalArguments[0]
 
169
            var entry = urlsList.model.get(0)
 
170
            compare(args[0], entry.url)
 
171
        }
 
172
 
 
173
        function test_keyboard_navigation_between_lists() {
 
174
            var lastVisitDateList = findChild(historyViewWide, "lastVisitDateListView")
 
175
            var urlsList = findChild(historyViewWide, "urlsListView")
 
176
            verify(!lastVisitDateList.activeFocus)        
 
177
            keyClick(Qt.Key_Left)
 
178
            verify(lastVisitDateList.activeFocus)        
 
179
            verify(!urlsList.activeFocus)        
 
180
            keyClick(Qt.Key_Right)
 
181
            verify(urlsList.activeFocus)        
 
182
        }
 
183
    }
 
184
}