~josephjamesmills/u2t/trunk

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
#!/usr/bin/env ruby1.8
=begin
/*
 * This file is part of unity-2d
 *
 * Copyright 2012 Canonical Ltd.
 *
 * 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 'xdo/mouse'
require 'tmpwindow'

############################# Test Suite #############################
context "Dash Tests" do
  # Run once at the beginning of this test suite
  startup do
    $SUT.execute_shell_command 'killall unity-2d-shell'
    $SUT.execute_shell_command 'killall unity-2d-shell'

    # Minimize all windows
    XDo::XWindow.toggle_minimize_all
  end

  # Run once at the end of this test suite
  shutdown do
  end

  # Run before each test case begins
  setup do
    # Execute the application 
    @app = $SUT.run( :name => UNITY_2D_SHELL,
                     :arguments => "-testability",
                     :sleeptime => 2 )
  end

  # Run after each test case completes
  teardown do
    TmpWindow.close_all_windows
    #Need to kill Launcher as it does not shutdown when politely asked
    $SUT.execute_shell_command 'pkill -nf unity-2d-spread'
    $SUT.execute_shell_command 'pkill -nf unity-2d-shell'
  end

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

  # Test case objectives:
  #   * Check Dash moving with Alt+F2
  # Pre-conditions
  #   * Desktop with no running applications
  #   * You have two screens, the second on the right of the first
  # Test steps
  #   * Verify dash is not showing
  #   * Move mouse to the first screen
  #   * Press Alt+F2
  #   * Verify dash is showing in the first screen
  #   * Move mouse to the second screen
  #   * Press Alt+F2
  #   * Verify dash is showing in the second screen
  #   * Move mouse to the first screen
  #   * Press Alt+F2
  #   * Verify dash is showing in the first screen
  # Post-conditions
  #   * None
  # References
  #   * None
  test "Check Dash moving with Alt+F2" do
    verify_equal("false", 0, 'There should not be a Dash declarative view on startup') {
      @app.Dash()['active']
    }

    XDo::Mouse.move(100, 200, 0, true)
    XDo::Keyboard.alt_F2 #Must use uppercase F to indicate function keys
    verify_equal("true", TIMEOUT, 'There should be a Dash declarative view after pressing Alt+F2') {
      @app.Dash()['active']
    }
    verify_equal(LAUNCHER_WIDTH, TIMEOUT, 'The Dash should be in the first screen') {
      @app.Dash()['x_absolute'].to_i
    }

    XDo::Mouse.move(XDo::XWindow.display_geometry()[0] + 100, 200, 0, true)
    verify_equal(XDo::XWindow.display_geometry()[0] + 100, TIMEOUT, 'The Dash should be in the second screen') {
      XDo::Mouse.position[0]
    }

    XDo::Keyboard.alt_F2
    verify_equal("true", TIMEOUT, 'There should be a Dash declarative view after pressing Alt+F2') {
      @app.Dash()['active']
    }
    verify_equal(XDo::XWindow.display_geometry()[0] + LAUNCHER_WIDTH, TIMEOUT, 'The Dash should be in the second screen') {
      @app.Dash()['x_absolute'].to_i
    }
    XDo::Keyboard.a
    XDo::Keyboard.s
    verify_equal( "as", TIMEOUT, 'Text in the search field should be "as"' ) {
      @app.Dash().SearchEntry().QDeclarativeTextInput()['text']
    }

    XDo::Mouse.move(100, 200, 0, true)
    XDo::Keyboard.alt_F2
    verify_equal("true", TIMEOUT, 'There should be a Dash declarative view after pressing Alt+F2') {
      @app.Dash()['active']
    }
    verify_equal(LAUNCHER_WIDTH, TIMEOUT, 'The Dash should be in the first screen') {
      @app.Dash()['x_absolute'].to_i
    }
    XDo::Keyboard.a
    XDo::Keyboard.s
    verify_equal( "asas", TIMEOUT, 'Text in the search field should be "as"' ) {
      @app.Dash().SearchEntry().QDeclarativeTextInput()['text']
    }

  end
end