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

5
def thunderbird_main
anonym's avatar
anonym committed
6
7
  # The main window title depends on context so without regexes it
  # will be hard to find it, but it so happens that it is always the
8
9
  # first frame of Thunderbird, so we do not have to be specific.
  thunderbird_app.child(roleName: 'frame')
anonym's avatar
anonym committed
10
11
end

12
13
def thunderbird_wizard
  thunderbird_app.child('Mail Account Setup', roleName: 'frame')
anonym's avatar
anonym committed
14
15
end

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

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

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

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

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

54
55
56
57
58
Then /^I open Thunderbird's Add-ons Manager$/ do
  thunderbird_main.button('AppMenu').click
  thunderbird_main.child('Add-ons', roleName: 'menu item').click
  @thunderbird_addons = thunderbird_app.child(
    'Add-ons Manager - Thunderbird Mail/News', roleName: 'frame'
anonym's avatar
anonym committed
59
  )
kytv's avatar
kytv committed
60
61
62
end

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

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

80
Then /^I see that Torbirdy is configured to use Tor$/ do
81
  thunderbird_main.child(roleName: 'status bar')
82
    .child('TorBirdy Enabled:    Tor', roleName: 'label')
kytv's avatar
kytv committed
83
end
84
85

When /^I enter my email credentials into the autoconfiguration wizard$/ do
86
87
88
89
90
  thunderbird_wizard.child('Email address:', roleName: 'entry')
    .typeText($config['Thunderbird']['address'])
  thunderbird_wizard.child('Password:', roleName: 'entry')
    .typeText($config['Thunderbird']['password'])
  thunderbird_wizard.button('Continue').click
91
  # This button is shown if and only if a configuration has been found
92
  try_for(120) { thunderbird_wizard.button('Done') }
93
94
end

95
Then /^the autoconfiguration wizard's choice for the (incoming|outgoing) server is secure (.+)$/ do |type, protocol|
96
97
  type = type.capitalize + ':'
  assert_not_nil(
98
    thunderbird_wizard.child(type, roleName: 'entry').text
anonym's avatar
anonym committed
99
      .match(/^#{protocol},[^,]+, (SSL|STARTTLS)$/)
100
101
  )
end
anonym's avatar
anonym committed
102
103

When /^I fetch my email$/ do
104
  account = thunderbird_main.child($config['Thunderbird']['address'],
anonym's avatar
anonym committed
105
106
                               roleName: 'table row')
  account.click
107
  thunderbird_main = thunderbird_app.child("#{$config['Thunderbird']['address']} - Thunderbird Mail/News", roleName: 'frame')
anonym's avatar
anonym committed
108

109
  thunderbird_main.child('Mail Toolbar', roleName: 'tool bar')
anonym's avatar
anonym committed
110
    .button('Get Messages').click
111
112
  try_for(120) do
    begin
113
      thunderbird_main.child(roleName: 'status bar', retry: false)
114
115
116
117
118
119
        .child(roleName: 'progress bar', retry: false)
      false
    rescue
      true
    end
  end
anonym's avatar
anonym committed
120
121
end

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

144
145
146
147
148
149
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
150
  thunderbird_wizard.child(choice, roleName: 'radio button').click
151
152
153
end

When /^I select manual configuration$/ do
154
  thunderbird_wizard.button('Manual config').click
155
156
end

anonym's avatar
anonym committed
157
158
159
160
161
162
163
164
165
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
166
  entry = thunderbird_wizard.child(entry_name, roleName: 'entry')
anonym's avatar
anonym committed
167
  entry.text = ''
168
  entry.typeText($config['Thunderbird']["#{protocol.downcase}_hidden_service"])
anonym's avatar
anonym committed
169
170
end

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

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

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