Add tests for new private browsing

This commit is contained in:
Florian Bruhin 2017-05-10 08:51:48 +02:00
parent eda95d7926
commit c3ac3ccdee
7 changed files with 188 additions and 57 deletions

View File

@ -177,21 +177,25 @@ def pdfjs_available():
def open_path(quteproc, httpbin, path):
"""Open a URL.
If used like "When I open ... in a new tab", the URL is opened in a new
tab. With "... in a new window", it's opened in a new window. With
"... as a URL", it's opened according to new-instance-open-target.
- If used like "When I open ... in a new tab", the URL is opened in a new
tab.
- With "... in a new window", it's opened in a new window.
- With "... in a private window" it's opened in a new private window.
- With "... as a URL", it's opened according to new-instance-open-target.
"""
path = path.replace('(port)', str(httpbin.port))
new_tab = False
new_bg_tab = False
new_window = False
private = False
as_url = False
wait = True
new_tab_suffix = ' in a new tab'
new_bg_tab_suffix = ' in a new background tab'
new_window_suffix = ' in a new window'
private_suffix = ' in a private window'
do_not_wait_suffix = ' without waiting'
as_url_suffix = ' as a URL'
@ -205,6 +209,9 @@ def open_path(quteproc, httpbin, path):
elif path.endswith(new_window_suffix):
path = path[:-len(new_window_suffix)]
new_window = True
elif path.endswith(private_suffix):
path = path[:-len(private_suffix)]
private = True
elif path.endswith(as_url_suffix):
path = path[:-len(as_url_suffix)]
as_url = True
@ -215,7 +222,8 @@ def open_path(quteproc, httpbin, path):
break
quteproc.open_path(path, new_tab=new_tab, new_bg_tab=new_bg_tab,
new_window=new_window, as_url=as_url, wait=wait)
new_window=new_window, private=private, as_url=as_url,
wait=wait)
@bdd.when(bdd.parsers.parse("I set {sect} -> {opt} to {value}"))

View File

@ -569,26 +569,6 @@ Feature: Various utility commands.
And I run :command-accept
Then the message "Hello World" should be shown
## https://github.com/qutebrowser/qutebrowser/issues/1219
@qtwebengine_todo: private browsing is not implemented yet @qtwebkit_ng_skip: private browsing is not implemented yet
Scenario: Sharing cookies with private browsing
When I set general -> private-browsing to true
And I open cookies/set?qute-test=42 without waiting
And I wait until cookies is loaded
And I open cookies in a new tab
And I set general -> private-browsing to false
Then the cookie qute-test should be set to 42
## https://github.com/qutebrowser/qutebrowser/issues/1742
@qtwebengine_todo: private browsing is not implemented yet @qtwebkit_ng_xfail: private browsing is not implemented yet
Scenario: Private browsing is activated in QtWebKit without restart
When I set general -> private-browsing to true
And I open data/javascript/localstorage.html
And I set general -> private-browsing to false
Then the page should contain the plaintext "Local storage status: not working"
@no_xvfb
Scenario: :window-only
Given I run :tab-only
@ -681,20 +661,6 @@ Feature: Various utility commands.
And I run :command-accept
Then the error "No command given" should be shown
@qtwebengine_todo: private browsing is not implemented yet @qtwebkit_ng_skip: private browsing is not implemented yet
Scenario: Calling previous command with private-browsing mode
When I run :set-cmd-text :message-info blah
And I run :command-accept
And I set general -> private-browsing to true
And I run :set-cmd-text :message-error "This should only be shown once"
And I run :command-accept
And I wait for the error "This should only be shown once"
And I run :set-cmd-text :
And I run :command-history-prev
And I run :command-accept
And I set general -> private-browsing to false
Then the message "blah" should be shown
## Modes blacklisted for :enter-mode
Scenario: Trying to enter command mode with :enter-mode

View File

@ -0,0 +1,112 @@
# vim: ft=cucumber fileencoding=utf-8 sts=4 sw=4 et:
Feature: Using private browsing
Background:
Given I open about:blank
And I clean up open tabs
@qtwebkit_ng_xfail: private browsing is not implemented yet
Scenario: Opening new tab in private window
When I open about:blank in a private window
And I run :window-only
And I open data/javascript/localstorage.html in a new tab
Then the page should contain the plaintext "Local storage status: not working"
@qtwebkit_ng_xfail: private browsing is not implemented yet
Scenario: Opening new tab in private window with :navigate next
When I open data/navigate in a private window
And I run :window-only
And I run :navigate -t next
And I wait until data/navigate/next.html is loaded
And I open data/javascript/localstorage.html
Then the page should contain the plaintext "Local storage status: not working"
Scenario: Using command history in a new private browsing window
When I run :set-cmd-text :message-info "Hello World"
And I run :command-accept
And I open about:blank in a private window
And I run :set-cmd-text :message-error "This should only be shown once"
And I run :command-accept
And I wait for the error "This should only be shown once"
And I run :close
And I run :set-cmd-text :
And I run :command-history-prev
And I run :command-accept
# Then the error should not be shown again
## https://github.com/qutebrowser/qutebrowser/issues/1219
@qtwebkit_ng_skip: private browsing is not implemented yet
Scenario: Sharing cookies with private browsing
When I open cookies/set?qute-test=42 without waiting in a private window
And I wait until cookies is loaded
And I open cookies in a new tab
And I set general -> private-browsing to false
Then the cookie qute-test should be set to 42
Scenario: Opening private window with :navigate increment
# Private window handled in commands.py
When I open data/numbers/1.txt in a private window
And I run :window-only
And I run :navigate -w increment
And I wait until data/numbers/2.txt is loaded
Then the session should look like:
windows:
- private: True
tabs:
- history:
- url: http://localhost:*/data/numbers/1.txt
- private: True
tabs:
- history:
- url: http://localhost:*/data/numbers/2.txt
Scenario: Opening private window with :navigate next
# Private window handled in navigate.py
When I open data/navigate in a private window
And I run :window-only
And I run :navigate -w next
And I wait until data/navigate/next.html is loaded
Then the session should look like:
windows:
- private: True
tabs:
- history:
- url: http://localhost:*/data/navigate
- private: True
tabs:
- history:
- url: http://localhost:*/data/navigate/next.html
Scenario: Opening private window with :tab-clone
When I open data/hello.txt in a private window
And I run :window-only
And I run :tab-clone -w
And I wait until data/hello.txt is loaded
Then the session should look like:
windows:
- private: True
tabs:
- history:
- url: http://localhost:*/data/hello.txt
- private: True
tabs:
- history:
- url: http://localhost:*/data/hello.txt
Scenario: Opening private window via :click-element
When I open data/click_element.html in a private window
And I run :window-only
And I run :click-element --target window id link
And I wait until data/hello.txt is loaded
Then the session should look like:
windows:
- private: True
tabs:
- history:
- url: http://localhost:*/data/click_element.html
- private: True
tabs:
- history:
- url: http://localhost:*/data/hello.txt

View File

@ -18,7 +18,6 @@
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import sys
import json
import os.path
import subprocess
@ -57,18 +56,6 @@ def update_documentation():
subprocess.call([sys.executable, update_script])
@bdd.then(bdd.parsers.parse('the cookie {name} should be set to {value}'))
def check_cookie(quteproc, name, value):
"""Check if a given cookie is set correctly.
This assumes we're on the httpbin cookies page.
"""
content = quteproc.get_content()
data = json.loads(content)
print(data)
assert data['cookies'][name] == value
@bdd.then(bdd.parsers.parse('the PDF {filename} should exist in the tmpdir'))
def pdf_exists(quteproc, tmpdir, filename):
path = tmpdir / filename

View File

@ -0,0 +1,36 @@
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import os.path
import json
import pytest_bdd as bdd
bdd.scenarios('private.feature')
@bdd.then(bdd.parsers.parse('the cookie {name} should be set to {value}'))
def check_cookie(quteproc, name, value):
"""Check if a given cookie is set correctly.
This assumes we're on the httpbin cookies page.
"""
content = quteproc.get_content()
data = json.loads(content)
print(data)
assert data['cookies'][name] == value

View File

@ -497,18 +497,20 @@ class QuteProc(testprocess.Process):
self.set_setting(sect, opt, old_value)
def open_path(self, path, *, new_tab=False, new_bg_tab=False,
new_window=False, as_url=False, port=None, https=False,
wait=True):
new_window=False, private=False, as_url=False, port=None,
https=False, wait=True):
"""Open the given path on the local webserver in qutebrowser."""
url = self.path_to_url(path, port=port, https=https)
self.open_url(url, new_tab=new_tab, new_bg_tab=new_bg_tab,
new_window=new_window, as_url=as_url, wait=wait)
new_window=new_window, private=private, as_url=as_url,
wait=wait)
def open_url(self, url, *, new_tab=False, new_bg_tab=False,
new_window=False, as_url=False, wait=True):
new_window=False, private=False, as_url=False, wait=True):
"""Open the given url in qutebrowser."""
if new_tab and new_window:
raise ValueError("new_tab and new_window given!")
if sum(1 for opt in [new_tab, new_bg_tab, new_window, private, as_url]
if opt) > 1:
raise ValueError("Conflicting options given!")
if as_url:
self.send_cmd(url, invalid=True)
@ -518,6 +520,8 @@ class QuteProc(testprocess.Process):
self.send_cmd(':open -b ' + url)
elif new_window:
self.send_cmd(':open -w ' + url)
elif private:
self.send_cmd(':open -p ' + url)
else:
self.send_cmd(':open ' + url)

View File

@ -267,3 +267,21 @@ def test_launching_with_python2():
assert proc.returncode == 1
error = "At least Python 3.4 is required to run qutebrowser"
assert stderr.decode('ascii').startswith(error)
def test_initial_private_browsing(request, quteproc_new):
"""Make sure the initial window is private when the setting is set."""
args = (_base_args(request.config) +
['--temp-basedir', '-s', 'general', 'private-browsing', 'true'])
quteproc_new.start(args)
quteproc_new.compare_session("""
windows:
- private: True
tabs:
- history:
- url: about:blank
""")
quteproc_new.send_cmd(':quit')
quteproc_new.wait_for_quit()