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.Components 1.3
22
import Ubuntu.Components.ListItems 1.3 as ListItems
23
import Ubuntu.Test 1.0
24
import "../../../src/app/webbrowser"
35
historyModel: HistoryModel {
37
databasePath: ":memory:"
43
target: historyViewWide
48
id: newTabRequestedSpy
49
target: historyViewWide
50
signalName: "newTabRequested"
54
id: historyEntryClickedSpy
55
target: historyViewWide
56
signalName: "historyEntryClicked"
60
id: historyEntryRemovedSpy
61
target: historyViewWide
62
signalName: "historyEntryRemoved"
66
name: "HistoryViewWide"
69
function clickItem(item) {
70
var center = centerOf(item)
71
mouseClick(item, center.x, center.y)
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)
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)
86
function initTestCase() {
87
for (var i = 0; i < 3; ++i) {
88
historyMockModel.add("http://example.org/" + i, "Example Domain " + i, "")
90
var urlsList = findChild(historyViewWide, "urlsListView")
91
tryCompare(urlsList, "count", 3)
92
waitForRendering(urlsList)
95
function test_done_button() {
96
var doneButton = findChild(historyViewWide, "doneButton")
97
verify(doneButton != null)
99
compare(doneSpy.count, 0)
100
clickItem(doneButton)
101
compare(doneSpy.count, 1)
104
function test_new_tab_button() {
105
var newTabButton = findChild(historyViewWide, "newTabButton")
106
verify(newTabButton != null)
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)
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)
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)
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)
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)
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)