unsafe_browser.rb 4.72 KB
Newer Older
1
When /^I see and accept the Unsafe Browser start verification$/ do
2
  next if @skip_steps_while_restoring_background
Tails developers's avatar
Tails developers committed
3
  @screen.wait("UnsafeBrowserStartVerification.png", 30)
4
  @screen.type("l", Sikuli::KeyModifier.ALT)
5 6 7
end

Then /^the Unsafe Browser has started$/ do
8
  next if @skip_steps_while_restoring_background
9
  @screen.wait("UnsafeBrowserHomepage.png", 360)
10 11 12
end

Then /^the Unsafe Browser has a red theme$/ do
13
  next if @skip_steps_while_restoring_background
14 15 16 17
  @screen.wait("UnsafeBrowserRedTheme.png", 10)
end

Then /^the Unsafe Browser has Wikipedia pre-selected in the search bar$/ do
18
  next if @skip_steps_while_restoring_background
19 20 21 22
  @screen.wait("UnsafeBrowserSearchBar.png", 10)
end

Then /^the Unsafe Browser shows a warning as its start page$/ do
23
  next if @skip_steps_while_restoring_background
24 25 26 27
  @screen.wait("UnsafeBrowserStartPage.png", 10)
end

When /^I start the Unsafe Browser$/ do
28
  next if @skip_steps_while_restoring_background
29 30 31 32 33 34 35
  unsafe_browser_cmd = nil
  @vm.execute("cat /usr/share/applications/unsafe-browser.desktop").stdout.chomp.each_line { |line|
    next if ! line.start_with? "Exec="
    unsafe_browser_cmd = line[/^Exec=(.*)/,1]
  }
  assert(!unsafe_browser_cmd.nil?, "failed to extract the unsafe browser command")
  step "I run \"#{unsafe_browser_cmd}\""
36 37 38 39
  step "I see and accept the Unsafe Browser start verification"
end

Then /^I see a warning about another instance already running$/ do
40
  next if @skip_steps_while_restoring_background
41 42 43
  @screen.wait('UnsafeBrowserWarnAlreadyRunning.png', 10)
end

Tails developers's avatar
Tails developers committed
44
When /^I close the Unsafe Browser$/ do
45
  next if @skip_steps_while_restoring_background
46
  @screen.type("q", Sikuli::KeyModifier.CTRL)
47 48 49
end

Then /^I can start the Unsafe Browser again$/ do
50
  next if @skip_steps_while_restoring_background
51 52 53 54 55
  step "I start the Unsafe Browser"
end

When /^I open a new tab in the Unsafe Browser$/ do
  next if @skip_steps_while_restoring_background
56
  @screen.wait_and_click("UnsafeBrowserWindow.png", 10)
57
  @screen.type("t", Sikuli::KeyModifier.CTRL)
58 59 60 61 62
end

When /^I open the address "([^"]*)" in the Unsafe Browser$/ do |address|
  next if @skip_steps_while_restoring_background
  step "I open a new tab in the Unsafe Browser"
63
  @screen.type("l", Sikuli::KeyModifier.CTRL)
64
  sleep 0.5
65
  @screen.type(address + Sikuli::Key.ENTER)
66
end
67 68

Then /^I cannot configure the Unsafe Browser to use any local proxies$/ do
69
  next if @skip_steps_while_restoring_background
70
  @screen.wait_and_click("UnsafeBrowserWindow.png", 10)
Tails developers's avatar
Tails developers committed
71
  sleep 0.5
72 73
  # First we open the proxy settings page to prepare it with the
  # correct open tabs for the loop below.
74
  @screen.type("e", Sikuli::KeyModifier.ALT)
75 76
  @screen.type("n")
  @screen.wait('UnsafeBrowserPreferences.png', 10)
77 78
  @screen.wait_and_click('UnsafeBrowserAdvancedSettings.png', 10)
  @screen.wait_and_click('UnsafeBrowserNetworkTab.png', 10)
79
  sleep 0.5
80
  @screen.type(Sikuli::Key.ESC)
81 82
#  @screen.waitVanish('UnsafeBrowserPreferences.png', 10)
  sleep 0.5
83 84 85 86 87 88 89 90 91 92 93

  http_proxy  = 'x' # Alt+x is the shortcut to select http proxy
  socks_proxy = 'c' # Alt+c for socks proxy
  no_proxy    = 'y' # Alt+y for no proxy

  # Note: the loop below depends on that http_proxy is done after any
  # other proxy types since it will set "Use this proxy server for all
  # protocols", which will make the other proxy types unselectable.
  proxies = [[socks_proxy, 9050],
             [socks_proxy, 9061],
             [socks_proxy, 9062],
94
             [socks_proxy, 9151],
95 96 97 98 99 100 101 102
             [http_proxy,  8118],
             [no_proxy,       0]]

  proxies.each do |proxy|
    proxy_type = proxy[0]
    proxy_port = proxy[1]

    # Open proxy settings and select manual proxy configuration
103
    @screen.type("e", Sikuli::KeyModifier.ALT)
104 105
    @screen.type("n")
    @screen.wait('UnsafeBrowserPreferences.png', 10)
106
    @screen.type("e", Sikuli::KeyModifier.ALT)
107
    @screen.wait('UnsafeBrowserProxySettings.png', 10)
108
    @screen.type("m", Sikuli::KeyModifier.ALT)
109 110

    # Configure the proxy
111 112
    @screen.type(proxy_type, Sikuli::KeyModifier.ALT)  # Select correct proxy type
    @screen.type("127.0.0.1" + Sikuli::Key.TAB + "#{proxy_port}") if proxy_type != no_proxy
113
    # For http proxy we set "Use this proxy server for all protocols"
114
    @screen.type("s", Sikuli::KeyModifier.ALT) if proxy_type == http_proxy
115

Tails developers's avatar
Tails developers committed
116
    # Close settings
117
    @screen.type(Sikuli::Key.ENTER)
118 119
#    @screen.waitVanish('UnsafeBrowserProxySettings.png', 10)
    sleep 0.5
120
    @screen.type(Sikuli::Key.ESC)
121 122
#    @screen.waitVanish('UnsafeBrowserPreferences.png', 10)
    sleep 0.5
123 124 125 126 127 128 129 130 131 132

    # Test that the proxy settings work as they should
    step "I open the address \"https://check.torproject.org\" in the Unsafe Browser"
    if proxy_type == no_proxy
      @screen.wait('UnsafeBrowserTorCheckFail.png', 60)
    else
      @screen.wait('UnsafeBrowserProxyRefused.png', 60)
    end
  end
end