browser.rb 8.31 KB
Newer Older
anonym's avatar
anonym committed
1
2
Then /^the Unsafe Browser has started$/ do
  @screen.wait("UnsafeBrowserHomepage.png", 360)
kytv's avatar
kytv committed
3
4
end

anonym's avatar
anonym committed
5
6
When /^I start the Unsafe Browser(?: through the GNOME menu)?$/ do
  step "I start \"Unsafe Browser\" via the GNOME \"Internet\" applications menu"
kytv's avatar
kytv committed
7
8
end

9
10
Then /^I see the Unsafe Browser start notification and wait for it to close$/ do
  robust_notification_wait("UnsafeBrowserStartNotification.png", 60)
kytv's avatar
kytv committed
11
12
end

anonym's avatar
anonym committed
13
14
15
16
17
When /^I successfully start the Unsafe Browser$/ do
  step "I start the Unsafe Browser"
  step "I see and accept the Unsafe Browser start verification"
  step "I see the Unsafe Browser start notification and wait for it to close"
  step "the Unsafe Browser has started"
kytv's avatar
kytv committed
18
19
end

anonym's avatar
anonym committed
20
When /^I close the Unsafe Browser$/ do
kytv's avatar
kytv committed
21
22
23
  @screen.type("q", Sikuli::KeyModifier.CTRL)
end

anonym's avatar
anonym committed
24
25
Then /^I see the Unsafe Browser stop notification$/ do
  robust_notification_wait("UnsafeBrowserStopNotification.png", 60)
kytv's avatar
kytv committed
26
27
28
29
30
31
end

def xul_application_info(application)
  binary = $vm.execute_successfully(
    'echo ${TBB_INSTALL}/firefox', :libs => 'tor-browser'
  ).stdout.chomp
anonym's avatar
anonym committed
32
  address_bar_image = "BrowserAddressBar.png"
33
  unused_tbb_libs = ['libnssdbm3.so']
kytv's avatar
kytv committed
34
35
36
37
38
39
40
41
42
43
44
45
46
  case application
  when "Tor Browser"
    user = LIVE_USER
    cmd_regex = "#{binary} .* -profile /home/#{user}/\.tor-browser/profile\.default"
    chroot = ""
    new_tab_button_image = "TorBrowserNewTabButton.png"
  when "Unsafe Browser"
    user = "clearnet"
    cmd_regex = "#{binary} .* -profile /home/#{user}/\.unsafe-browser/profile\.default"
    chroot = "/var/lib/unsafe-browser/chroot"
    new_tab_button_image = "UnsafeBrowserNewTabButton.png"
  when "Tor Launcher"
    user = "tor-launcher"
47
48
49
50
51
52
    # We do not enable AppArmor confinement for the Tor Launcher.
    binary = "#{binary}-unconfined"
    tor_launcher_install = $vm.execute_successfully(
      'echo ${TOR_LAUNCHER_INSTALL}', :libs => 'tor-browser'
    ).stdout.chomp
    cmd_regex = "#{binary}\s+-app #{tor_launcher_install}/application\.ini.*"
kytv's avatar
kytv committed
53
54
55
    chroot = ""
    new_tab_button_image = nil
    address_bar_image = nil
56
57
58
    # The standalone Tor Launcher uses fewer libs than the full
    # browser.
    unused_tbb_libs.concat(["libfreebl3.so", "libnssckbi.so", "libsoftokn3.so"])
kytv's avatar
kytv committed
59
60
61
62
63
64
65
66
67
  else
    raise "Invalid browser or XUL application: #{application}"
  end
  return {
    :user => user,
    :cmd_regex => cmd_regex,
    :chroot => chroot,
    :new_tab_button_image => new_tab_button_image,
    :address_bar_image => address_bar_image,
68
    :unused_tbb_libs => unused_tbb_libs,
kytv's avatar
kytv committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  }
end

When /^I open a new tab in the (.*)$/ do |browser|
  info = xul_application_info(browser)
  @screen.click(info[:new_tab_button_image])
  @screen.wait(info[:address_bar_image], 10)
end

When /^I open the address "([^"]*)" in the (.*)$/ do |address, browser|
  step "I open a new tab in the #{browser}"
  info = xul_application_info(browser)
  open_address = Proc.new do
    @screen.click(info[:address_bar_image])
83
84
    # This static here since we have no reliable visual indicators
    # that we can watch to know when typing is "safe".
85
    sleep 5
86
    # The browser sometimes loses keypresses when suggestions are
intrigeri's avatar
intrigeri committed
87
    # shown, which we work around by pasting the address from the
88
89
90
91
    # clipboard, in one go.
    $vm.set_clipboard(address)
    @screen.type('v', Sikuli::KeyModifier.CTRL)
    @screen.type(Sikuli::Key.ENTER)
kytv's avatar
kytv committed
92
  end
93
94
95
96
97
  recovery_on_failure = Proc.new do
    @screen.type(Sikuli::Key.ESC)
    @screen.waitVanish('BrowserReloadButton.png', 3)
    open_address.call
  end
kytv's avatar
kytv committed
98
  if browser == "Tor Browser"
99
100
101
102
103
104
105
    retry_method = method(:retry_tor)
  else
    retry_method = Proc.new { |p, &b| retry_action(10, recovery_proc: p, &b) }
  end
  open_address.call
  retry_method.call(recovery_on_failure) do
    @screen.wait('BrowserReloadButton.png', 120)
kytv's avatar
kytv committed
106
107
108
  end
end

109
110
# This step is limited to the Tor Browser due to #7502 since dogtail
# uses the same interface.
anonym's avatar
anonym committed
111
Then /^"([^"]+)" has loaded in the Tor Browser$/ do |title|
112
113
114
115
116
117
  if @language == 'German'
    browser_name = 'Tor-Browser'
    reload_action = 'Aktuelle Seite neu laden'
  else
    browser_name = 'Tor Browser'
    reload_action = 'Reload current page'
118
  end
119
  expected_title = "#{title} - #{browser_name}"
120
  try_for(60) { @torbrowser.child(expected_title, roleName: 'frame') }
121
122
  # The 'Reload current page' button (graphically shown as a looping
  # arrow) is only shown when a page has loaded, so once we see the
anonym's avatar
anonym committed
123
  # expected title *and* this button has appeared, then we can be sure
124
  # that the page has fully loaded.
125
  try_for(60) { @torbrowser.child(reload_action, roleName: 'push button') }
126
127
end

kytv's avatar
kytv committed
128
129
130
131
132
Then /^the (.*) has no plugins installed$/ do |browser|
  step "I open the address \"about:plugins\" in the #{browser}"
  step "I see \"TorBrowserNoPlugins.png\" after at most 30 seconds"
end

133
def xul_app_shared_lib_check(pid, chroot, expected_absent_tbb_libs = [])
kytv's avatar
kytv committed
134
135
  absent_tbb_libs = []
  unwanted_native_libs = []
136
137
138
  tbb_libs = $vm.execute_successfully("ls -1 #{chroot}${TBB_INSTALL}/*.so",
                                      :libs => 'tor-browser').stdout.split
  firefox_pmap_info = $vm.execute("pmap --show-path #{pid}").stdout
kytv's avatar
kytv committed
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
  for lib in tbb_libs do
    lib_name = File.basename lib
    if not /\W#{lib}$/.match firefox_pmap_info
      absent_tbb_libs << lib_name
    end
    native_libs = $vm.execute_successfully(
                       "find /usr/lib /lib -name \"#{lib_name}\""
                                           ).stdout.split
    for native_lib in native_libs do
      if /\W#{native_lib}$"/.match firefox_pmap_info
        unwanted_native_libs << lib_name
      end
    end
  end
  absent_tbb_libs -= expected_absent_tbb_libs
  assert(absent_tbb_libs.empty? && unwanted_native_libs.empty?,
         "The loaded shared libraries for the firefox process are not the " +
         "way we expect them.\n" +
         "Expected TBB libs that are absent: #{absent_tbb_libs}\n" +
         "Native libs that we don't want: #{unwanted_native_libs}")
end

Then /^the (.*) uses all expected TBB shared libraries$/ do |application|
  info = xul_application_info(application)
  pid = $vm.execute_successfully("pgrep --uid #{info[:user]} --full --exact '#{info[:cmd_regex]}'").stdout.chomp
  assert(/\A\d+\z/.match(pid), "It seems like #{application} is not running")
165
  xul_app_shared_lib_check(pid, info[:chroot], info[:unused_tbb_libs])
kytv's avatar
kytv committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
end

Then /^the (.*) chroot is torn down$/ do |browser|
  info = xul_application_info(browser)
  try_for(30, :msg => "The #{browser} chroot '#{info[:chroot]}' was " \
                      "not removed") do
    !$vm.execute("test -d '#{info[:chroot]}'").success?
  end
end

Then /^the (.*) runs as the expected user$/ do |browser|
  info = xul_application_info(browser)
  assert_vmcommand_success($vm.execute(
    "pgrep --full --exact '#{info[:cmd_regex]}'"),
    "The #{browser} is not running")
  assert_vmcommand_success($vm.execute(
    "pgrep --uid #{info[:user]} --full --exact '#{info[:cmd_regex]}'"),
    "The #{browser} is not running as the #{info[:user]} user")
end
185
186
187
188
189
190
191
192
193

When /^I download some file in the Tor Browser$/ do
  @some_file = 'tails-signing.key'
  some_url = "https://tails.boum.org/#{@some_file}"
  step "I open the address \"#{some_url}\" in the Tor Browser"
end

Then /^I get the browser download dialog$/ do
  @screen.wait('BrowserDownloadDialog.png', 60)
194
  @screen.wait('BrowserDownloadDialogSaveAsButton.png', 10)
195
196
197
198
199
200
201
202
203
204
205
206
207
end

When /^I save the file to the default Tor Browser download directory$/ do
  @screen.click('BrowserDownloadDialogSaveAsButton.png')
  @screen.wait('BrowserDownloadFileToDialog.png', 10)
  @screen.type(Sikuli::Key.ENTER)
end

Then /^the file is saved to the default Tor Browser download directory$/ do
  assert_not_nil(@some_file)
  expected_path = "/home/#{LIVE_USER}/Tor Browser/#{@some_file}"
  try_for(10) { $vm.file_exist?(expected_path) }
end
208

209
210
211
212
213
214
When /^I open Tails homepage in the (.+)$/ do |browser|
  step "I open the address \"https://tails.boum.org\" in the #{browser}"
end

Then /^Tails homepage loads in the Tor Browser$/ do
  title = 'Tails - Privacy for anyone anywhere'
anonym's avatar
anonym committed
215
  step "\"#{title}\" has loaded in the Tor Browser"
216
217
218
219
end

Then /^Tails homepage loads in the Unsafe Browser$/ do
  @screen.wait('TailsHomepage.png', 60)
220
end
anonym's avatar
anonym committed
221
222

Then /^the Tor Browser shows the "([^"]+)" error$/ do |error|
223
  page = @torbrowser.child("Problem loading page", roleName: "document frame")
anonym's avatar
anonym committed
224
225
226
227
  headers = page.children(roleName: "heading")
  found = headers.any? { |heading| heading.text == error }
  raise "Could not find the '#{error}' error in the Tor Browser" unless found
end