1 When /^I see and accept the Unsafe Browser start verification(?:| in the "([^"]+)" locale)$/ do |locale|
2 @screen.wait('GnomeQuestionDialogIcon.png', 30)
3 @screen.type(Sikuli::Key.TAB + Sikuli::Key.ENTER)
6 def supported_torbrowser_languages
7 localization_descriptions = "#{Dir.pwd}/config/chroot_local-includes/usr/share/tails/browser-localization/descriptions"
8 File.read(localization_descriptions).split("\n").map do |line|
9 # The line will be of the form "xx:YY:..." or "xx-YY:YY:..."
10 first, second = line.sub('-', '_').split(':')
11 candidates = ["#{first}_#{second}.UTF-8", "#{first}_#{second}.utf8",
12 "#{first}.UTF-8", "#{first}.utf8",
13 "#{first}_#{second}", first]
14 when_not_found = Proc.new { raise "Could not find a locale for '#{line}'" }
15 candidates.find(when_not_found) do |candidate|
16 $vm.directory_exist?("/usr/lib/locale/#{candidate}")
21 Then /^I start the Unsafe Browser in the "([^"]+)" locale$/ do |loc|
22 step "I run \"LANG=#{loc} LC_ALL=#{loc} sudo unsafe-browser\" in GNOME Terminal"
23 step "I see and accept the Unsafe Browser start verification in the \"#{loc}\" locale"
26 Then /^the Unsafe Browser works in all supported languages$/ do
28 supported_torbrowser_languages.sample(3).each do |lang|
29 step "I start the Unsafe Browser in the \"#{lang}\" locale"
31 step "the Unsafe Browser has started in the \"#{lang}\" locale"
36 step "I close the Unsafe Browser"
37 step "the Unsafe Browser chroot is torn down"
39 assert(failed.empty?, "Unsafe Browser failed to launch in the following locale(s): #{failed.join(', ')}")
42 Then /^the Unsafe Browser has no add-ons installed$/ do
43 step "I open the address \"about:addons\" in the Unsafe Browser"
44 step "I see \"UnsafeBrowserNoAddons.png\" after at most 30 seconds"
47 Then /^the Unsafe Browser has only Firefox's default bookmarks configured$/ do
48 info = xul_application_info("Unsafe Browser")
49 # "Show all bookmarks"
50 @screen.type("o", Sikuli::KeyModifier.SHIFT + Sikuli::KeyModifier.CTRL)
51 @screen.wait_and_click("UnsafeBrowserExportBookmarksButton.png", 20)
52 @screen.wait_and_click("UnsafeBrowserExportBookmarksMenuEntry.png", 20)
53 @screen.wait("UnsafeBrowserExportBookmarksSavePrompt.png", 20)
54 path = "/home/#{info[:user]}/bookmarks"
55 @screen.type(path + Sikuli::Key.ENTER)
56 chroot_path = "#{info[:chroot]}/#{path}.json"
57 try_for(10) { $vm.file_exist?(chroot_path) }
58 dump = JSON.load($vm.file_content(chroot_path))
60 def check_bookmarks_helper(a)
61 mozilla_uris_counter = 0
62 places_uris_counter = 0
66 m, p = check_bookmarks_helper(v)
67 mozilla_uris_counter += m
68 places_uris_counter += p
71 if uri.match("^https://(?:support|www)\.mozilla\.org/")
72 mozilla_uris_counter += 1
73 elsif uri.match("^place:(sort|folder|type)=")
74 places_uris_counter += 1
76 raise "Unexpected Unsafe Browser bookmark for '#{uri}'"
81 return [mozilla_uris_counter, places_uris_counter]
84 mozilla_uris_counter, places_uris_counter =
85 check_bookmarks_helper(dump["children"])
86 assert_equal(5, mozilla_uris_counter,
87 "Unexpected number (#{mozilla_uris_counter}) of mozilla " \
89 assert_equal(2, places_uris_counter,
90 "Unexpected number (#{places_uris_counter}) of places " \
92 @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
95 Then /^the Unsafe Browser has a red theme$/ do
96 @screen.wait("UnsafeBrowserRedTheme.png", 10)
99 Then /^the Unsafe Browser shows a warning as its start page(?: in the "([^"]+)" locale)?$/ do |locale|
101 # Languages that have a translated version of the Unsafe Browser homepage,
102 # and more specifically of the "You are currently using the Unsafe Browser"
104 when /\A(de|fa|fr|it)/
105 start_page_image = "UnsafeBrowserStartPage.#{$1}.png"
107 start_page_image = "UnsafeBrowserStartPage.png"
109 @screen.wait(start_page_image, 60)
112 Then /^the Unsafe Browser has started(?: in the "([^"]+)" locale)?$/ do |locale|
114 step "the Unsafe Browser shows a warning as its start page in the \"#{locale}\" locale"
116 step "the Unsafe Browser shows a warning as its start page"
120 Then /^I see a warning about another instance already running$/ do
121 @screen.wait('UnsafeBrowserWarnAlreadyRunning.png', 10)
124 Then /^I can start the Unsafe Browser again$/ do
125 step "I start the Unsafe Browser"
128 Then /^I open the Unsafe Browser proxy settings dialog$/ do
129 step "I open the address \"about:preferences\" in the Unsafe Browser"
130 @screen.wait('BrowserPreferencesPage.png', 10)
131 @screen.type('proxy')
132 @screen.wait('BrowserPreferencesProxyHeading.png', 10)
133 @screen.wait_and_click('BrowserPreferencesProxySettingsButton.png', 10)
134 @screen.wait('BrowserProxySettingsWindow.png', 10)
137 Then /^I cannot configure the Unsafe Browser to use any local proxies$/ do
138 socks_proxy = 'C' # Alt+Shift+c for socks proxy
140 $vm.execute_successfully('grep -w "^SocksPort" /etc/tor/torrc').stdout
141 assert(socksport_lines.size >= 4, "We got fewer than four Tor SocksPorts")
142 socksports = socksport_lines.scan(/^SocksPort\s([^:]+):(\d+)/)
143 proxies = socksports.map { |host, port| [socks_proxy, host, port] }
145 proxies.each do |proxy_type, proxy_host, proxy_port|
148 step "I open the Unsafe Browser proxy settings dialog"
150 # Ensure the desired proxy configuration
151 @screen.type("M", Sikuli::KeyModifier.ALT)
152 @screen.type(proxy_type, Sikuli::KeyModifier.ALT)
153 @screen.type(proxy_host + Sikuli::Key.TAB + proxy_port)
156 @screen.type(Sikuli::Key.ENTER)
157 @screen.waitVanish('BrowserProxySettingsWindow.png', 10)
159 # Test that the proxy settings work as they should
160 step 'I open Tails homepage in the Unsafe Browser'
161 @screen.wait('BrowserProxyRefused.png', 60)
165 Then /^the Unsafe Browser has no proxy configured$/ do
166 step "I open the Unsafe Browser proxy settings dialog"
167 @screen.wait('BrowserNoProxySelected.png', 10)
168 @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
169 @screen.type(Sikuli::Key.ESC)
172 Then /^the Unsafe Browser complains that no DNS server is configured$/ do
174 Dogtail::Application.new('zenity')
175 .child(roleName: 'label')
176 .text['No DNS server was obtained']
180 Then /^I configure the Unsafe Browser to check for updates more frequently$/ do
181 prefs = '/usr/share/tails/chroot-browsers/unsafe-browser/prefs.js'
182 $vm.file_append(prefs, 'pref("app.update.idletime", 1);')
183 $vm.file_append(prefs, 'pref("app.update.promptWaitTime", 1);')
184 $vm.file_append(prefs, 'pref("app.update.interval", 5);')
187 But /^checking for updates is disabled in the Unsafe Browser's configuration$/ do
188 prefs = '/usr/share/tails/chroot-browsers/common/prefs.js'
189 assert($vm.file_content(prefs).include?('pref("app.update.enabled", false)'))
192 Then /^the clearnet user has (|not )sent packets out to the Internet$/ do |sent|
193 uid = $vm.execute_successfully("id -u clearnet").stdout.chomp.to_i
194 pkts = ip4tables_packet_counter_sum(:tables => ['OUTPUT'], :uid => uid)
197 assert(pkts > 0, "Packets have not gone out to the internet.")
199 assert_equal(pkts, 0, "Packets have gone out to the internet.")