~gerboland/unity-2d/dash-test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env ruby1.8
=begin
/*
 * This file is part of unity-2d
 *
 * Copyright 2011 Canonical Ltd.
 *
 * Authors:
 * - Gerry Boland <gerry.boland@canonical.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
=end

require '../run-tests.rb' unless $INIT_COMPLETED
require 'xdo/xwindow'
require 'xdo/keyboard'

require 'timeout'

############################# Test Suite #############################
context "Dash Show and Hide Tests" do

  # Run once at the beginning of this test suite
  startup do
    system 'killall unity-2d-places > /dev/null 2>&1'

    # Need launcher running to summon dash
    @@sut = TDriver.sut(:Id => "sut_qt")
    @@launcher = @@sut.run( :name => UNITY_2D_LAUNCHER, 
    		          :arguments => "-testability" )
  end
  
  # Run once at the end of this test suite
  shutdown do
    #Need to kill Launcher as it does not shutdown when politely asked
    system "pkill -nf unity-2d-launcher"
  end

  # Run before each test case begins
  setup do
    # Execute the Dash
    @app = @@sut.run( :name => UNITY_2D_PLACES, 
    		     :arguments => "-testability" )
  end

  # Run after each test case completes
  teardown do
    @app.close
  end

  #####################################################################################
  # Test cases


  # Test case objectives:
  #   * Check the Dash is hidden at launch
  # Pre-conditions
  #   * Launcher running
  # Test steps
  #   * Verify Dash starts hidden
  # Post-conditions
  #   * None
  # References
  #   * None
  test "Hidden at Startup" do
    verify_not(10, 'Dash should be hidden at startup') {
      #this should throw an exception, as the DeclarativeView does not exist when Dash hidden
      @app.DashDeclarativeView()
    }
  end


  # Test case objectives:
  #   * Check the Dash is summoned and hidden by the Super key
  # Pre-conditions
  #   * Launcher running
  # Test steps
  #   * Verify Dash starts hidden
  #   * Tap the Super key and check Dash is visible
  #   * Tap the Super key again and check Dash is hidden
  # Post-conditions
  #   * None
  # References
  #   * None
  test "Show and hide with Super key" do
    verify_not(10, 'Dash should be hidden at startup') {
      @app.DashDeclarativeView()
    }
    XDo::Keyboard.super
    verify_equal('true', 10, 'Super key hit, Dash should be visible but is not') {
      @app.DashDeclarativeView()['visible']
    }
    XDo::Keyboard.super
    verify_not(10, 'Super key should hide visible Dash') {
      @app.DashDeclarativeView()
    }
  end


  # Test case objectives:
  #   * Check the Dash is hidden by the Escape key
  # Pre-conditions
  #   * Launcher running
  # Test steps
  #   * Verify Dash starts hidden
  #   * Tap the Super key and check Dash is visible
  #   * Tap the Escape key and check Dash is hidden
  # Post-conditions
  #   * None
  # References
  #   * None
  test "Show with Super key, hide with Escape" do
    verify_not(10, 'Dash should be hidden at startup') {
      @app.DashDeclarativeView()
    }
    XDo::Keyboard.super
    verify_equal('true', 10, 'Super key hit, Dash should be visible but is not') {
      @app.DashDeclarativeView()['visible']
    }
    XDo::Keyboard.escape
    verify_not(10, 'Escape key should hide visible Dash') {
      @app.DashDeclarativeView()
    }
  end


  # Test case objectives:
  #   * Check the Dash is summoned and hidden by the BFB of the Launcher
  # Pre-conditions
  #   * Launcher running
  # Test steps
  #   * Verify Dash starts hidden
  #   * Click the BFB and check Dash is visible
  #   * Click the BFB again and check Dash is hidden
  # Post-conditions
  #   * None
  # References
  #   * None
  test "Show and hide using BFB" do
    verify_not(10, 'Dash should be hidden at startup') {
      @app.DashDeclarativeView()
    }

    #Click the BFB
    @@launcher.LauncherList( :name => 'main' ).LauncherList( :isBfb => 'true' ).tap
    verify_equal('true', 10, 'BFB clicked, Dash should be visible but is not') {
      @app.DashDeclarativeView()['visible']
    }

    @@launcher.LauncherList( :name => 'main' ).LauncherList( :isBfb => 'true' ).tap
    verify_not(10, 'BFB should hide visible Dash') {
      @app.DashDeclarativeView()
    }
  end


  # Test case objectives:
  #   * Check the Dash Console lens is summoned by Alt+F2
  # Pre-conditions
  #   * Launcher running
  # Test steps
  #   * Verify Dash starts hidden
  #   * Press Alt+F2 and check Dash is visible
  #   * Check the Console lens is visible by looking for a 'History' header
  #   * Tap the Escape key and check Dash is hidden
  # Post-conditions
  #   * None
  # References
  #   * None  
  test "Show and hide using Alt+F2" do
    verify_not(10, 'Dash should be hidden at startup') {
      @app.DashDeclarativeView()
    }

    XDo::Keyboard.alt_F2 #need function key with uppercase F
    verify_equal('true', 10, 'Alt+F2 pressed, Dash should be visible but is not') {
      @app.DashDeclarativeView()['visible']
    }
=begin #FIXME: how to identify console lens is active?
    #Check that Console lens is open
    verify(10) {
      @app.QDeclarativeItem( :name => 'content' ) \
          .QDeclarativeFocusScope( :name => 'History' ) #FIXME
    }
=end
    XDo::Keyboard.escape
    verify_not(10, 'Escape should hide visible Dash') {
      @app.DashDeclarativeView()
    }
  end


  # Test case objectives:
  #   * Check the Dash hides when you click on an file/application
  # Pre-conditions
  #   * Launcher running
  # Test steps
  #   * Verify Dash starts hidden
  #   * Click the BFB button on the Launcher and check Dash is visible
  #   * Type in the string "calc"
  #   * Verify Search box contains the string "calc"
  #   * Search through the list of returned applications for one with the name "Calculator"
  #   * Click the "Calculator" application
  #   * Verify the Dash hides
  # Post-conditions
  #   * "Calculator" application running
  # References
  #   * None  
  test "Dash hides when you click on application" do
    verify_not(10, 'Dash should be hidden at startup') {
      @app.DashDeclarativeView()
    }

    #Click the BFB
    @@launcher.LauncherList( :name => 'main' ).LauncherList( :isBfb => 'true' ).tap
    verify_equal('true', 10, 'BFB clicked, Dash should be visible but is not') {
      @app.DashDeclarativeView()['visible']
    }

    #Lets search for a hopefully international name: Mahjongg
    desired_app = 'Mahjongg'
    search_string = desired_app.slice(0,3).downcase #search for first few chars: 'mah'
    XDo::Keyboard.type(search_string)

    #Verify text box contains this string
    verify_equal(search_string, 10, "Dash search box does not contain typed text '#{search_string}'") {
      @app.DashDeclarativeView() \
          .QDeclarativeItem( :name => 'content' ) \
          .QDeclarativeTextInput()['displayText']
    }

    #Search through results for Mahjongg and click it
    verify(10, "Failed to find #{desired_app}") {
      @app.DashDeclarativeView \
          .QDeclarativeItem( :name => 'content' ) \
          .QDeclarativeFocusScope( :name => 'Applications' ) \
          .QDeclarativeLoader( :name => 'body' ) \
          .child( :text => desired_app ) \
          .tap 
    } 

    #Dash should now be hidden
    verify_not(10, 'Dash failed to hide after application was clicked') {
      @app.DashDeclarativeView()
    }
    #Check Mahjongg appears
    window_id = -1
    Timeout.timeout(20){window_id = XDo::XWindow.wait_for_window(desired_app, :onlyvisible)}
    verify_true(0, "#{desired_app} window not found") { window_id != -1 }

    #Close it
    XDo::XWindow.new(window_id).close!
  end
end