thunderbird.rb 7.93 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
59
60
61
  # Make sure AppMenu is available, even if it seems hard to click its
  # "Add-ons" menu + menu item...
  thunderbird_main.button('AppMenu')
  # ... then use keyboard shortcuts:
  @screen.type('t', Sikuli::KeyModifier.ALT)
  @screen.type('a')
62
  @thunderbird_addons = thunderbird_app.child(
63
    'Add-ons Manager - Mozilla Thunderbird', roleName: 'frame'
anonym's avatar
anonym committed
64
  )
kytv's avatar
kytv committed
65
66
67
end

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

71
Then /^I see that only the (.+) addons are enabled in Thunderbird$/ do |addons|
72
73
  expected_addons = addons.split(/, | and /)
  actual_addons =
74
    @thunderbird_addons.child('TorBirdy', roleName: 'label')
75
76
77
78
79
80
    .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
81
  end
82
  assert_equal(0, actual_addons.size)
kytv's avatar
kytv committed
83
84
end

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

When /^I enter my email credentials into the autoconfiguration wizard$/ do
91
92
93
94
95
96
  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)
97
  thunderbird_wizard.button('Continue').click
98
  # This button is shown if and only if a configuration has been found
99
  try_for(120) { thunderbird_wizard.button('Done') }
100
101
end

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

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

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

129
When /^I accept the (?:autoconfiguration wizard's|manual) configuration$/ do
130
131
132
  # The password check can fail due to bad Tor circuits.
  retry_tor do
    try_for(120) do
133
      begin
134
135
        # Spam the button, even if it is disabled (while it is still
        # testing the password).
136
        thunderbird_wizard.button('Done').click
137
        false
138
      rescue
139
140
141
        true
      end
    end
142
    true
143
  end
anonym's avatar
anonym committed
144
145
  # 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
146
  # wizard will start, indicating (incorrectly) that we do not have an
anonym's avatar
anonym committed
147
148
149
150
  # account set up yet.
  step 'I fetch my email'
end

151
152
153
154
155
156
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
157
  thunderbird_wizard.child(choice, roleName: 'radio button').click
158
159
160
end

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

anonym's avatar
anonym committed
164
165
166
167
168
169
170
171
172
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
173
  entry = thunderbird_wizard.child(entry_name, roleName: 'entry')
anonym's avatar
anonym committed
174
  entry.text = ''
175
  entry.typeText($config['Icedove']["#{protocol.downcase}_hidden_service"])
anonym's avatar
anonym committed
176
177
end

anonym's avatar
anonym committed
178
When /^I send an email to myself$/ do
179
  thunderbird_main.child('Mail Toolbar', roleName: 'tool bar').button('Write').click
180
  compose_window = thunderbird_app.child('Write: (no subject) - Thunderbird')
anonym's avatar
anonym committed
181
  compose_window.child('To:', roleName: 'autocomplete').child(roleName: 'entry')
182
    .typeText($config['Icedove']['address'])
anonym's avatar
anonym committed
183
184
185
186
187
188
  # 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)
189
  compose_window = thunderbird_app.child("Write: #{@subject} - Thunderbird")
190
  compose_window.child('', roleName: 'internal frame')
anonym's avatar
anonym committed
191
192
193
    .typeText('test')
  compose_window.child('Composition Toolbar', roleName: 'tool bar')
    .button('Send').click
194
195
196
  try_for(120) do
    not compose_window.exist?
  end
anonym's avatar
anonym committed
197
198
199
end

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

217
218
Then /^my Thunderbird inbox is non-empty$/ do
  thunderbird_inbox.click
219
220
  # The button is located on the first row in the message list, the
  # one that shows the column labels (Subject, From, ...).
221
  message_list = thunderbird_main.child('Select columns to display',
222
223
224
225
226
227
228
229
230
                                    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