@@ -1,239 +0,0 @@
2− * Copyright 2013 Canonical Ltd.
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
20−import "../../../qml/Hud"
22−import Unity.Test 0.1 as UT
29− // Mock shell to shut up some warnings
30− property QtObject shell: QtObject {
31− property QtObject applicationManager: QtObject {
32− id: applicationManager
33− property bool keyboardVisible: false
45− function resetToInitialState() {
46− var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
49− hud.resetToInitialState()
50− hudClientStub.reset()
51− tryCompare(parametrizedActionsPage, "x", hud.width) // Make sure the parametrized page action animation is finished
54− function test_hud_toolbar() {
55− var toolBar = findChild(hud, "toolBar")
56− resetToInitialState()
58− var toolBarIconCount = 0
59− for (var i in toolBar.children) {
60− if (UT.Util.isInstanceOf(toolBar.children[i], "ToolBarIcon")) {
64− compare(toolBarIconCount, 4, "toolbar item count")
66− mouseClick(toolBar.children[0], 0, 0)
67− compare(hudClientStub.lastExecutedToolbarItem, hudClientStub.undoToolbarItemValue(), "Click on undo")
69− mouseClick(toolBar.children[1], 0, 0)
70− compare(hudClientStub.lastExecutedToolbarItem, hudClientStub.helpToolbarItemValue(), "Click on help")
72− mouseClick(toolBar.children[2], 0, 0)
73− compare(hudClientStub.lastExecutedToolbarItem, hudClientStub.fullScreenToolbarItemValue(), "Click on fullscreen")
75− mouseClick(toolBar.children[3], 0, 0)
76− compare(hudClientStub.lastExecutedToolbarItem, hudClientStub.preferencesToolbarItemValue(), "Click on preferences")
78− compare(toolBar.children[0].enabled, true)
79− compare(toolBar.children[1].enabled, true)
80− compare(toolBar.children[2].enabled, true)
81− compare(toolBar.children[3].enabled, true)
83− hudClientStub.setHelpToolbarItemEnabled(false);
84− compare(toolBar.children[0].enabled, true)
85− compare(toolBar.children[1].enabled, false)
86− compare(toolBar.children[2].enabled, true)
87− compare(toolBar.children[3].enabled, true)
90− function test_hud_results() {
91− var resultListRepeater = findChild(hud, "resultListRepeater")
92− resetToInitialState()
94− tryCompare(resultListRepeater, "count", 5)
96− compare(resultListRepeater.itemAt(0).children[1].nameText, "Help", "First result name")
97− compare(resultListRepeater.itemAt(0).children[1].contextSnippetText, "Get Help", "First result description")
99− compare(resultListRepeater.itemAt(1).children[1].nameText, "About", "Second result name")
100− compare(resultListRepeater.itemAt(1).children[1].contextSnippetText, "Show About", "Second result description")
102− compare(resultListRepeater.itemAt(2).children[1].nameText, "Foo", "Third result name")
103− compare(resultListRepeater.itemAt(2).children[1].contextSnippetText, "Show Foo", "Third result description")
105− compare(resultListRepeater.itemAt(3).children[1].nameText, "Bar", "Fourth result name")
106− compare(resultListRepeater.itemAt(3).children[1].contextSnippetText, "Show Bar", "Fourth result description")
108− compare(resultListRepeater.itemAt(4).children[1].nameText, "FooBar", "Fifth result name")
109− compare(resultListRepeater.itemAt(4).children[1].contextSnippetText, "Show FooBar", "Fifth result description")
112− function test_hud_set_query() {
113− var searchBar = findChild(hud, "searchBar")
114− resetToInitialState()
116− compare(hudClientStub.lastSetQuery, "", "Query should be empty at start")
118− searchBar.text = "Hi"
119− compare(hudClientStub.lastSetQuery, "Hi", "Query should be updated")
121− searchBar.text = "Ho"
122− compare(hudClientStub.lastSetQuery, "Ho", "Query should be updated")
125− function compareItemAnchoredAtTopOf(itemA, itemB, spacing, text) {
126− compare(itemA.y - spacing, itemB.y, text)
129− function compareItemAnchoredAtBottomOf(itemA, itemB, spacing, text) {
130− compare(itemA.y + itemA.height + spacing, itemB.y + itemB.height, text)
133− function compareItemAnchoredUnderItem(itemUnder, itemTop, spacing, text) {
134− compare(itemUnder.y - spacing, itemTop.y + itemTop.height, text)
137− function compareItemAnchoredOverItem(itemTop, itemUnder, spacing, text) {
138− compareItemAnchoredUnderItem(itemUnder, itemTop, spacing, text)
141− function test_hud_elements_positioning() {
142− var searchBar = findChild(hud, "searchBar")
143− var searchBarContainer = findChild(hud, "searchBarAnimator")
144− var resultListContainer = findChild(hud, "resultsCardAnimator")
145− var toolBarContainer = findChild(hud, "toolBarAnimator")
146− var toolBar = findChild(hud, "toolBar")
147− var handle = findChild(hud, "handle")
148− resetToInitialState()
150− compare(toolBar.visible, true, "Toolbar is initially visible")
151− compareItemAnchoredAtTopOf(handle, hud, 0, "Handle is anchored at the top")
152− compareItemAnchoredAtBottomOf(searchBarContainer, hud, hud.elementsPadding, "SearchBar is anchored at the bottom")
153− compareItemAnchoredOverItem(toolBarContainer, searchBarContainer, 2 * hud.elementsPadding, "Toolbar is anchored over the searchBar")
154− compareItemAnchoredOverItem(resultListContainer, toolBarContainer, hud.elementsPadding, "ResultsList is anchored over the toolBar")
156− mouseClick(searchBar, 0, 0)
158− tryCompare(toolBar, "visible", false)
159− compareItemAnchoredAtTopOf(handle, hud, 0, "Handle is anchored at the top")
160− compareItemAnchoredUnderItem(searchBarContainer, handle, hud.elementsPadding + units.dp(1), "SearchBar is anchored under the handle")
161− compareItemAnchoredUnderItem(resultListContainer, searchBarContainer, hud.elementsPadding, "ResultsList is anchored under the searchBar")
164− function test_hud_result_suggestion_execution() {
165− var resultListRepeater = findChild(hud, "resultListRepeater")
166− resetToInitialState()
168− mouseClick(resultListRepeater.itemAt(1), 0, 0)
169− compare(hudClientStub.lastExecutedCommandRow, 1, "Last executed row was 1")
170− compare(hud.shown, false, "Should not be shown after executing")
173− function number_of_activated_actions(activatedActionsObject) {
174− var activatedActions = 0
175− for(var key in activatedActionsObject) {
178− return activatedActions
181− function test_hud_result_suggestion_parametrized_execution_and_back() {
182− var resultListRepeater = findChild(hud, "resultListRepeater")
183− var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
184− var backButton = parametrizedActionsPage.children[1].children[0]
185− resetToInitialState()
187− compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden at start")
188− tryCompare(parametrizedActionsPage, "x", hud.width)
190− mouseClick(resultListRepeater.itemAt(2), 0, 0)
191− compare(hudClientStub.lastExecutedCommandRow, -1, "We executed a param action not a regular one")
192− compare(hudClientStub.lastExecutedParametrizedCommandRow, 2, "Last executed row was 2")
193− compare(parametrizedActionsPage.shown, true, "Parametrized action page should be shown after executing a parametrized action")
194− tryCompare(parametrizedActionsPage, "x", 0)
196− var sliderLabel = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[0]
197− var slider = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[1]
198− compare(sliderLabel.text, "Item1Label")
199− compare(slider.minimumValue, 10)
200− compare(slider.maximumValue, 80)
201− compare(slider.live, true)
202− compare(number_of_activated_actions(hudClientStub.activatedActions), 0)
204− // Since it's live moving the slider will activate it already
205− var slider = parametrizedActionsPage.children[0].children[0].children[0].children[1].children[1]
206− mouseClick(slider, units.gu(1), units.gu(1))
207− compare(number_of_activated_actions(hudClientStub.activatedActions), 1)
208− compare(hudClientStub.activatedActions["costAction"], 10)
210− mouseClick(backButton, 0, 0)
211− compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden after going back")
212− compare(hudClientStub.lastParametrizedCommandCommited, false, "Cancelling does not commit")
213− tryCompare(parametrizedActionsPage, "x", hud.width)
216− function test_hud_result_suggestion_parametrized_execution_and_confirm() {
217− var resultListRepeater = findChild(hud, "resultListRepeater")
218− var parametrizedActionsPage = findChild(hud, "parametrizedActionsPage")
219− var confirmButton = parametrizedActionsPage.children[1].children[2]
220− resetToInitialState()
222− compare(parametrizedActionsPage.shown, false, "Parametrized action page should be hidden at start")
223− tryCompare(parametrizedActionsPage, "x", hud.width)
225− mouseClick(resultListRepeater.itemAt(2), 0, 0)
226− compare(hudClientStub.lastExecutedCommandRow, -1, "We executed a param action not a regular one")
227− compare(hudClientStub.lastExecutedParametrizedCommandRow, 2, "Last executed row was 2")
228− compare(parametrizedActionsPage.shown, true, "Parametrized action page should be shown after executing a parametrized action")
229− tryCompare(parametrizedActionsPage, "x", 0)
230− compare(number_of_activated_actions(hudClientStub.activatedActions), 0)
232− mouseClick(confirmButton, 0, 0)
233− compare(hud.shown, false, "Should not be shown after executing")
234− compare(number_of_activated_actions(hudClientStub.activatedActions), 1)
235− compare(hudClientStub.activatedActions["costAction"], 75)
236− compare(hudClientStub.lastParametrizedCommandCommited, true, "Confirming does commit")