Commit 77aa42f0 authored by intrigeri's avatar intrigeri
Browse files

Use Tor Browser even for offline documentation, drop the custom documentation...

Use Tor Browser even for offline documentation, drop the custom documentation browser, and adjust the test suite accordingly (refs: #15720).

Incidentally, this brings back test suite robustness workarounds
that commit:74536c6a had removed,
which might help fix another bug (refs: #15321).
parent b2eb36d8
#!/usr/bin/env python3
import gettext
import gi
import locale
import os
import os.path
import sys
import tailsgreeter.gui
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk # NOQA: E402
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk # NOQA: E402
gi.require_version('WebKit2', '4.0')
from gi.repository import WebKit2 # NOQA: E402
# We'll only use a single translation, "Tails documentation", which
# already is translated for the launcher. For this reason, this script
# is not managed by `refresh-translations`.
gettext.textdomain('tails')
# The browser from the Greeter is good as-is, but a button for
# navigating backwards in the history would be nice.
class DocumentationWindow(tailsgreeter.gui.GreeterHelpWindow):
def _build_ui(self):
super()._build_ui()
# The super class' headerbar is not exposed as an instance
# variable, but we need it!
headerbar = next(child for child in self.get_children() \
if isinstance(child, Gtk.HeaderBar))
back_button = Gtk.Button.new_from_icon_name('back', Gtk.IconSize.BUTTON)
back_button.connect("clicked", lambda x: self.webview.go_back())
headerbar.pack_start(back_button)
back_button.show()
self.webview.connect(
"load-changed",
lambda webview, e: back_button.set_visible(webview.can_go_back())
)
self.find_entry = Gtk.Entry(visible=False, no_show_all=True)
self.find_entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY,
"search")
self.find_entry.connect("activate", self.find_forward)
self.find_entry.connect("changed", self.find_forward)
self.find_entry.connect("key-press-event", self.cb_find_entry_key_press)
headerbar.pack_end(self.find_entry)
self.connect("key-press-event", self.cb_window_key_press)
def cb_window_key_press(self, window, event):
if event.keyval == Gdk.KEY_f and event.state & Gdk.ModifierType.CONTROL_MASK:
self.find_entry.show()
self.find_entry.grab_focus()
def cb_load_started(self, webview, ressource, request):
super().cb_load_started(webview, ressource, request)
if not request.get_uri().startswith("file://"):
# An external link was clicked, let's abort following it
# in our WebKit browser; any configured external protocol
# handler will still open the link's uri.
webview.stop_loading()
def find_forward(self, entry, user_data=None):
find_controller = self.webview.get_find_controller()
find_options = WebKit2.FindOptions.CASE_INSENSITIVE | \
WebKit2.FindOptions.WRAP_AROUND
find_controller.search(self.find_entry.get_text(), find_options, 32)
def find_previous(self):
find_controller = self.webview.get_find_controller()
find_controller.search_previous()
def find_finish(self):
find_controller = self.webview.get_find_controller()
find_controller.search_finish()
self.find_entry.set_text('')
self.find_entry.hide()
self.webview.grab_focus()
def cb_find_entry_key_press(self, entry, event, user_data=None):
if event.keyval == Gdk.KEY_Return and event.state & Gdk.ModifierType.SHIFT_MASK:
self.find_previous()
if event.keyval == Gdk.KEY_Escape:
self.find_finish()
# Main
......@@ -105,27 +27,22 @@ if os.system('/usr/local/sbin/tor-has-bootstrapped') == 0:
uri = 'https://tails.boum.org/' + page + '/index.' + lang_code + '.html'
else:
uri = 'https://tails.boum.org/' + page
if anchor is not None:
uri = uri + '#' + anchor
os.execv('/usr/local/bin/tor-browser',
['/usr/local/bin/tor-browser', '--new-tab',
uri])
else:
trials = [
os.path.join(wiki_path, page + code + ".html")
for code in ['.' + lang_code, '.en', '']
]
try:
uri = 'file://' + next(
trial for trial in trials if os.path.isfile(trial)
)
except StopIteration:
sys.exit('error: could not find the requested documentation page')
trials = [
os.path.join(wiki_path, page + code + ".html")
for code in ['.' + lang_code, '.en', '']
]
try:
uri = 'file://' + next(trial for trial in trials if os.path.isfile(trial))
except StopIteration:
sys.exit('error: could not find the requested documentation page')
if anchor is not None:
uri = uri + '#' + anchor
if '..' in uri.split(os.sep):
sys.exit('error: cannot escape from {}'.format(wiki_path))
helpwindow = DocumentationWindow(uri)
helpwindow.connect("delete-event", Gtk.main_quit)
helpwindow.window.set_title(gettext.gettext('Tails documentation'))
helpwindow.show()
Gtk.main()
os.environ['TOR_BROWSER_SKIP_OFFLINE_WARNING'] = 'yes'
os.execv('/usr/local/bin/tor-browser',
['/usr/local/bin/tor-browser', '--new-tab',
uri])
......@@ -6,19 +6,18 @@ Feature: Tails documentation
Scenario: The Tails documentation launcher on the desktop works when offline
Given I have started Tails from DVD without network and logged in
When I double-click on the Tails documentation launcher on the desktop
Then the documentation viewer opens the "Documentation" page
Then "Tails - Documentation" has loaded in the Tor Browser
#15514
@fragile
Scenario: The Tails documentation launcher on the desktop works when online
Given I have started Tails from DVD and logged in and the network is connected
When I double-click on the Tails documentation launcher on the desktop
Then the Tor Browser starts
And "Tails - Documentation" has loaded in the Tor Browser
Then "Tails - Documentation" has loaded in the Tor Browser
#15321
@fragile
Scenario: The Report an Error launcher will open the support documentation
Given I have started Tails from DVD without network and logged in
When I double-click on the Report an Error launcher on the desktop
Then the documentation viewer opens the "Support" page
Then the support documentation page opens in Tor Browser
......@@ -94,26 +94,22 @@ Then /^the VirtualBox guest modules are available$/ do
"The vboxguest module is not available.")
end
Then /^the documentation viewer opens the "(Support|Documentation)" page$/ do |page|
if @language == 'German'
expected_title = 'Tails-Dokumentation'
if page == 'Support'
expected_heading = 'Die Dokumentation durchsuchen'
else
expected_heading = 'Einen Fehler gefunden?'
end
else
expected_title = 'Tails documentation'
if page == 'Support'
expected_heading = 'Search the documentation'
else
expected_heading = 'First steps with Tails'
end
end
app = Dogtail::Application.new('tails-documentation')
app.child(expected_title, roleName: 'frame', recursive: false)
app.child(expected_heading, roleName: 'heading')
end
Then /^the support documentation page opens in Tor Browser$/ do
if @language == 'German'
expected_title = 'Tails - Hilfe & Support'
expected_heading = 'Die Dokumentation durchsuchen'
else
expected_title = 'Tails - Support'
expected_heading = 'Search the documentation'
end
step "\"#{expected_title}\" has loaded in the Tor Browser"
headings = @torbrowser
.child(expected_title, roleName: 'document frame')
.children(roleName: 'heading')
assert(
headings.any? { |heading| heading.text == expected_heading }
)
end
Given /^I plug and mount a USB drive containing a sample PNG$/ do
@png_dir = share_host_files(Dir.glob("#{MISC_FILES_DIR}/*.png"))
......
......@@ -733,9 +733,11 @@ end
When /^I double-click on the (Tails documentation|Report an Error) launcher on the desktop$/ do |launcher|
image = 'Desktop' + launcher.split.map { |s| s.capitalize } .join + '.png'
info = xul_application_info('Tor Browser')
# Sometimes the double-click is lost (#12131).
retry_action(10) do
@screen.wait_and_double_click(image, 10) if $vm.execute("pgrep --uid #{LIVE_USER} --full --full tails-documentation").failure?
@screen.wait_and_double_click(image, 10) if $vm.execute("pgrep --uid #{info[:user]} --full --exact '#{info[:cmd_regex]}'").failure?
step 'the Tor Browser has started'
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment