Manual test suite: use more precise data when comparing image size.
[tails.git] / features / step_definitions / unsafe_browser.rb
blob3f9f1b54d70fb9a0793d4af8684a673c19eca9cf
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)
4 end
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}")
17     end
18   end
19 end
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"
24 end
26 Then /^the Unsafe Browser works in all supported languages$/ do
27   failed = Array.new
28   supported_torbrowser_languages.sample(3).each do |lang|
29     step "I start the Unsafe Browser in the \"#{lang}\" locale"
30     begin
31       step "the Unsafe Browser has started in the \"#{lang}\" locale"
32     rescue RuntimeError
33       failed << lang
34       next
35     end
36     step "I close the Unsafe Browser"
37     step "the Unsafe Browser chroot is torn down"
38   end
39   assert(failed.empty?, "Unsafe Browser failed to launch in the following locale(s): #{failed.join(', ')}")
40 end
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"
45 end
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
63     a.each do |h|
64       h.each_pair do |k, v|
65         if k == "children"
66           m, p = check_bookmarks_helper(v)
67           mozilla_uris_counter += m
68           places_uris_counter += p
69         elsif k == "uri"
70           uri = v
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
75           else
76             raise "Unexpected Unsafe Browser bookmark for '#{uri}'"
77           end
78         end
79       end
80     end
81     return [mozilla_uris_counter, places_uris_counter]
82   end
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 " \
88                "bookmarks")
89   assert_equal(2, places_uris_counter,
90                "Unexpected number (#{places_uris_counter}) of places " \
91                "bookmarks")
92   @screen.type(Sikuli::Key.F4, Sikuli::KeyModifier.ALT)
93 end
95 Then /^the Unsafe Browser has a red theme$/ do
96   @screen.wait("UnsafeBrowserRedTheme.png", 10)
97 end
99 Then /^the Unsafe Browser shows a warning as its start page(?: in the "([^"]+)" locale)?$/ do |locale|
100   case 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"
103   # string.
104   when /\A(de|fa|fr|it)/
105     start_page_image = "UnsafeBrowserStartPage.#{$1}.png"
106   else
107     start_page_image = "UnsafeBrowserStartPage.png"
108   end
109   @screen.wait(start_page_image, 60)
112 Then /^the Unsafe Browser has started(?: in the "([^"]+)" locale)?$/ do |locale|
113   if locale
114     step "the Unsafe Browser shows a warning as its start page in the \"#{locale}\" locale"
115   else
116     step "the Unsafe Browser shows a warning as its start page"
117   end
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
139   socksport_lines =
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|
146     @screen.hide_cursor
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)
155     # Close settings
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)
162   end
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
173   assert_not_nil(
174     Dogtail::Application.new('zenity')
175     .child(roleName: 'label')
176     .text['No DNS server was obtained']
177   )
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)
195   case sent
196   when ''
197     assert(pkts > 0, "Packets have not gone out to the internet.")
198   when 'not'
199     assert_equal(pkts, 0, "Packets have gone out to the internet.")
200   end