thunderbird.rb 8.02 KB
Newer Older
1
2
def thunderbird_app
  Dogtail::Application.new('Thunderbird')
anonym's avatar
anonym committed
3
4
end

5
def thunderbird_main
6
7
8
9
10
  # Thunderbird has an empty, unnamed frame; so use a search on all
  # children and match whatever frame has a non-empty name:
  thunderbird_app.children(roleName: 'frame', recursive: false).find do |e|
    e.name.match(/^(.+)$/)
  end
anonym's avatar
anonym committed
11
12
end

13
def thunderbird_wizard
14
  thunderbird_app.child('Set Up an Existing Email Account', roleName: 'frame')
anonym's avatar
anonym committed
15
16
end

17
def thunderbird_inbox
18
  folder_view = thunderbird_main.child($config['Icedove']['address'],
19
20
21
22
23
24
                                   roleName: 'table row').parent
  folder_view.children(roleName: 'table row', recursive: false).find do |e|
    e.name.match(/^Inbox( .*)?$/)
  end
end

25
When /^I start Thunderbird$/ do
26
27
  workaround_pref_lines = [
    # When we generate a random subject line it may contain one of the
28
    # keywords that will make Thunderbird show an extra prompt when trying
29
30
31
32
    # to send an email. Let's disable this feature.
    'pref("mail.compose.attachment_reminder", false);'
  ]
  workaround_pref_lines.each do |line|
33
    $vm.file_append('/etc/thunderbird/pref/thunderbird.js', line)
34
  end
anonym's avatar
anonym committed
35
  step 'I start "Thunderbird" via GNOME Activities Overview'
36
  try_for(60) { thunderbird_main }
kytv's avatar
kytv committed
37
38
39
end

When /^I have not configured an email account$/ do
40
  conf_path = "/home/#{LIVE_USER}/.thunderbird/profile.default/prefs.js"
anonym's avatar
anonym committed
41
  if $vm.file_exist?(conf_path)
42
43
    thunderbird_prefs = $vm.file_content(conf_path).chomp
    assert(!thunderbird_prefs.include?('mail.accountmanager.accounts'))
anonym's avatar
anonym committed
44
  end
kytv's avatar
kytv committed
45
46
47
end

Then /^I am prompted to setup an email account$/ do
48
  thunderbird_wizard
kytv's avatar
kytv committed
49
50
51
end

Then /^I cancel setting up an email account$/ do
52
  thunderbird_wizard.button('Cancel').click
kytv's avatar
kytv committed
53
54
end

55
Then /^I open Thunderbird's Add-ons Manager$/ do
56
57
58
  # Make sure AppMenu is available, even if it seems hard to click its
  # "Add-ons" menu + menu item...
  thunderbird_main.button('AppMenu')
59
60
  # ... then use keyboard shortcuts, with a little delay between both
  # so that the menu has a chance to pop up:
61
  @screen.type('t', Sikuli::KeyModifier.ALT)
62
  sleep(1)
63
  @screen.type('a')
64
  @thunderbird_addons = thunderbird_app.child(
65
    'Add-ons Manager - Mozilla Thunderbird', roleName: 'frame'
anonym's avatar
anonym committed
66
  )
kytv's avatar
kytv committed
67
68
69
end

Then /^I click the extensions tab$/ do
70
  @thunderbird_addons.child('Extensions', roleName: 'list item').click
kytv's avatar
kytv committed
71
72
end

73
Then /^I see that only the (.+) addons are enabled in Thunderbird$/ do |addons|
74
75
  expected_addons = addons.split(/, | and /)
  actual_addons =
76
    @thunderbird_addons.child('TorBirdy', roleName: 'label')
77
78
79
80
81
82
    .parent.parent.children(roleName: 'list item', recursive: false)
    .map { |item| item.name }
  expected_addons.each do |addon|
    result = actual_addons.find { |e| e.start_with?(addon) }
    assert_not_nil(result)
    actual_addons.delete(result)
kytv's avatar
kytv committed
83
  end
84
  assert_equal(0, actual_addons.size)
kytv's avatar
kytv committed
85
86
end

87
Then /^I see that Torbirdy is configured to use Tor$/ do
88
  thunderbird_main.child(roleName: 'status bar')
89
    .child('TorBirdy Enabled:    Tor', roleName: 'label')
kytv's avatar
kytv committed
90
end
91
92

When /^I enter my email credentials into the autoconfiguration wizard$/ do
93
94
95
96
97
98
  address = $config['Icedove']['address']
  name = address.split('@').first
  password = $config['Icedove']['password']
  thunderbird_wizard.child('Your name:', roleName: 'entry').typeText(name)
  thunderbird_wizard.child('Email address:', roleName: 'entry').typeText(address)
  thunderbird_wizard.child('Password:', roleName: 'entry').typeText(password)
99
  thunderbird_wizard.button('Continue').click
100
  # This button is shown if and only if a configuration has been found
101
  try_for(120) { thunderbird_wizard.button('Done') }
102
103
end

104
Then /^the autoconfiguration wizard's choice for the (incoming|outgoing) server is secure (.+)$/ do |type, protocol|
105
106
  type = type.capitalize + ':'
  assert_not_nil(
107
    thunderbird_wizard.child(type, roleName: 'entry').text
anonym's avatar
anonym committed
108
      .match(/^#{protocol},[^,]+, (SSL|STARTTLS)$/)
109
110
  )
end
anonym's avatar
anonym committed
111
112

When /^I fetch my email$/ do
113
  account = thunderbird_main.child($config['Icedove']['address'],
anonym's avatar
anonym committed
114
115
                               roleName: 'table row')
  account.click
116
  thunderbird_main = thunderbird_app.child("#{$config['Icedove']['address']} - Mozilla Thunderbird", roleName: 'frame')
anonym's avatar
anonym committed
117

118
  thunderbird_main.child('Mail Toolbar', roleName: 'tool bar')
anonym's avatar
anonym committed
119
    .button('Get Messages').click
120
121
  try_for(120) do
    begin
122
      thunderbird_main.child(roleName: 'status bar', retry: false)
123
124
125
126
127
128
        .child(roleName: 'progress bar', retry: false)
      false
    rescue
      true
    end
  end
anonym's avatar
anonym committed
129
130
end

131
When /^I accept the (?:autoconfiguration wizard's|manual) configuration$/ do
132
133
134
  # The password check can fail due to bad Tor circuits.
  retry_tor do
    try_for(120) do
135
      begin
136
137
        # Spam the button, even if it is disabled (while it is still
        # testing the password).
138
        thunderbird_wizard.button('Done').click
139
        false
140
      rescue
141
142
143
        true
      end
    end
144
    true
145
  end
anonym's avatar
anonym committed
146
147
  # The account isn't fully created before we fetch our mail. For
  # instance, if we'd try to send an email before this, yet another
anonym's avatar
anonym committed
148
  # wizard will start, indicating (incorrectly) that we do not have an
anonym's avatar
anonym committed
149
150
151
152
  # account set up yet.
  step 'I fetch my email'
end

153
154
155
156
157
158
When /^I select the autoconfiguration wizard's (IMAP|POP3) choice$/ do |protocol|
  if protocol == 'IMAP'
    choice = 'IMAP (remote folders)'
  else
    choice = 'POP3 (keep mail on your computer)'
  end
159
  thunderbird_wizard.child(choice, roleName: 'radio button').click
160
161
162
end

When /^I select manual configuration$/ do
163
  thunderbird_wizard.button('Manual config').click
164
165
end

anonym's avatar
anonym committed
166
167
168
169
170
171
172
173
174
When /^I alter the email configuration to use (.*) over a hidden services$/ do |protocol|
  case protocol.upcase
  when 'IMAP', 'POP3'
    entry_name = 'Incoming:'
  when 'SMTP'
    entry_name = 'Outgoing:'
  else
    raise "Unknown mail protocol '#{protocol}'"
  end
175
  entry = thunderbird_wizard.child(entry_name, roleName: 'entry')
anonym's avatar
anonym committed
176
  entry.text = ''
177
  entry.typeText($config['Icedove']["#{protocol.downcase}_hidden_service"])
anonym's avatar
anonym committed
178
179
end

anonym's avatar
anonym committed
180
When /^I send an email to myself$/ do
181
  thunderbird_main.child('Mail Toolbar', roleName: 'tool bar').button('Write').click
182
  compose_window = thunderbird_app.child('Write: (no subject) - Thunderbird')
anonym's avatar
anonym committed
183
  compose_window.child('To:', roleName: 'autocomplete').child(roleName: 'entry')
184
    .typeText($config['Icedove']['address'])
anonym's avatar
anonym committed
185
186
187
188
189
190
  # The randomness of the subject will make it easier for us to later
  # find *exactly* this email. This makes it safe to run several tests
  # in parallel.
  @subject = "Automated test suite: #{random_alnum_string(32)}"
  compose_window.child('Subject:', roleName: 'entry')
    .typeText(@subject)
191
  compose_window = thunderbird_app.child("Write: #{@subject} - Thunderbird")
192
  compose_window.child('', roleName: 'internal frame')
anonym's avatar
anonym committed
193
194
195
    .typeText('test')
  compose_window.child('Composition Toolbar', roleName: 'tool bar')
    .button('Send').click
196
197
198
  try_for(120) do
    not compose_window.exist?
  end
anonym's avatar
anonym committed
199
200
201
end

Then /^I can find the email I sent to myself in my inbox$/ do
202
203
  recovery_proc = Proc.new { step 'I fetch my email' }
  retry_tor(recovery_proc) do
204
205
    thunderbird_inbox.click
    filter = thunderbird_main.child('Filter these messages <Ctrl+Shift+K>',
206
207
                                roleName: 'entry')
    filter.typeText(@subject)
208
    hit_counter = thunderbird_main.child('1 message')
209
210
    inbox_view = hit_counter.parent
    message_list = inbox_view.child(roleName: 'table')
211
    the_message = message_list.child(@subject, roleName: 'table cell')
212
213
214
215
    assert_not_nil(the_message)
    # Let's clean up
    the_message.click
    inbox_view.button('Delete').click
anonym's avatar
anonym committed
216
217
  end
end
218

219
220
Then /^my Thunderbird inbox is non-empty$/ do
  thunderbird_inbox.click
221
222
  # The button is located on the first row in the message list, the
  # one that shows the column labels (Subject, From, ...).
223
  message_list = thunderbird_main.child('Select columns to display',
224
225
226
227
228
229
230
231
232
                                    roleName: 'push button')
                 .parent.parent
  visible_messages = message_list.children(recursive: false,
                                           roleName: 'table row')
  # The first element is the column label row, which is not a message,
  # so let's remove it.
  visible_messages.shift
  assert(visible_messages.size > 0)
end