2016-06-11 18:43:37 +02:00
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2018-02-05 12:19:50 +01:00
# Copyright 2016-2018 Ryan Roden-Corrent (rcorre) <ryan@rcorre.net>
2016-06-11 18:43:37 +02:00
#
# 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/>.
""" Tests for completion models. """
2016-06-14 04:20:25 +02:00
import collections
2018-09-03 23:27:09 +02:00
import random
import string
2016-06-16 05:41:14 +02:00
from datetime import datetime
2016-06-14 04:20:25 +02:00
2016-06-16 05:41:14 +02:00
import pytest
from PyQt5 . QtCore import QUrl
2017-09-04 19:55:30 +02:00
from qutebrowser . completion import completer
2017-02-13 00:14:46 +01:00
from qutebrowser . completion . models import miscmodels , urlmodel , configmodel
2017-08-12 21:07:17 +02:00
from qutebrowser . config import configdata , configtypes
2018-02-27 15:55:00 +01:00
from qutebrowser . utils import objreg , usertypes
2017-08-12 21:07:17 +02:00
from qutebrowser . browser import history
from qutebrowser . commands import cmdutils
2016-06-16 05:41:14 +02:00
2016-08-10 04:06:03 +02:00
def _check_completions ( model , expected ) :
""" Check that a model contains the expected items in any order.
Args :
expected : A dict of form
{
CategoryName : [ ( name , desc , misc ) , . . . ] ,
CategoryName : [ ( name , desc , misc ) , . . . ] ,
. . .
}
2016-06-30 13:24:55 +02:00
"""
2017-11-13 08:27:31 +01:00
__tracebackhide__ = True
2017-04-18 13:48:11 +02:00
actual = { }
2016-09-14 18:46:17 +02:00
assert model . rowCount ( ) == len ( expected )
2016-06-30 13:24:55 +02:00
for i in range ( 0 , model . rowCount ( ) ) :
2017-02-12 14:39:24 +01:00
catidx = model . index ( i , 0 )
catname = model . data ( catidx )
2017-04-18 13:48:11 +02:00
actual [ catname ] = [ ]
2017-02-12 14:39:24 +01:00
for j in range ( model . rowCount ( catidx ) ) :
name = model . data ( model . index ( j , 0 , parent = catidx ) )
desc = model . data ( model . index ( j , 1 , parent = catidx ) )
misc = model . data ( model . index ( j , 2 , parent = catidx ) )
2017-04-18 13:48:11 +02:00
actual [ catname ] . append ( ( name , desc , misc ) )
assert actual == expected
2016-09-16 21:41:54 +02:00
# sanity-check the column_widths
assert len ( model . column_widths ) == 3
assert sum ( model . column_widths ) == 100
2016-06-30 13:24:55 +02:00
2017-08-12 21:07:17 +02:00
@pytest.fixture ( )
def cmdutils_stub ( monkeypatch , stubs ) :
2016-06-30 13:24:55 +02:00
""" Patch the cmdutils module to provide fake commands. """
2017-08-12 21:07:17 +02:00
return monkeypatch . setattr ( cmdutils , ' cmd_dict ' , {
' quit ' : stubs . FakeCommand ( name = ' quit ' , desc = ' quit qutebrowser ' ) ,
' open ' : stubs . FakeCommand ( name = ' open ' , desc = ' open a url ' ) ,
' prompt-yes ' : stubs . FakeCommand ( name = ' prompt-yes ' , deprecated = True ) ,
2017-11-13 07:59:54 +01:00
' scroll ' : stubs . FakeCommand (
name = ' scroll ' ,
2017-08-12 21:07:17 +02:00
desc = ' Scroll the current tab in the given direction. ' ,
2017-11-13 07:59:54 +01:00
modes = ( ) ) ,
2017-11-26 13:07:41 +01:00
' tab-close ' : stubs . FakeCommand (
name = ' tab-close ' ,
desc = ' Close the current tab. ' ) ,
2016-06-30 13:24:55 +02:00
} )
2017-08-12 21:07:17 +02:00
@pytest.fixture ( )
2018-02-19 19:16:50 +01:00
def configdata_stub ( config_stub , monkeypatch , configdata_init ) :
2016-06-30 13:24:55 +02:00
""" Patch the configdata module to provide fake data. """
2018-02-19 19:16:50 +01:00
monkeypatch . setattr ( configdata , ' DATA ' , collections . OrderedDict ( [
2017-08-12 21:07:17 +02:00
( ' aliases ' , configdata . Option (
name = ' aliases ' ,
description = ' Aliases for commands. ' ,
typ = configtypes . Dict (
keytype = configtypes . String ( ) ,
valtype = configtypes . Command ( ) ,
) ,
default = { ' q ' : ' quit ' } ,
2018-02-27 15:55:00 +01:00
backends = [ usertypes . Backend . QtWebKit ,
usertypes . Backend . QtWebEngine ] ,
2017-08-12 21:07:17 +02:00
raw_backends = None ) ) ,
( ' bindings.default ' , configdata . Option (
name = ' bindings.default ' ,
description = ' Default keybindings ' ,
typ = configtypes . Dict (
keytype = configtypes . String ( ) ,
valtype = configtypes . Dict (
2018-02-27 06:50:57 +01:00
keytype = configtypes . Key ( ) ,
2017-08-12 21:07:17 +02:00
valtype = configtypes . Command ( ) ,
) ,
) ,
default = {
2017-11-26 13:07:41 +01:00
' normal ' : collections . OrderedDict ( [
2018-02-27 06:58:39 +01:00
( ' <Ctrl+q> ' , ' quit ' ) ,
2017-11-26 13:07:41 +01:00
( ' d ' , ' tab-close ' ) ,
] )
2017-08-12 21:07:17 +02:00
} ,
backends = [ ] ,
2018-03-07 18:30:44 +01:00
raw_backends = None ,
no_autoconfig = True ) ) ,
2017-08-12 21:07:17 +02:00
( ' bindings.commands ' , configdata . Option (
name = ' bindings.commands ' ,
description = ' Default keybindings ' ,
typ = configtypes . Dict (
keytype = configtypes . String ( ) ,
valtype = configtypes . Dict (
2018-02-27 06:50:57 +01:00
keytype = configtypes . Key ( ) ,
2017-08-12 21:07:17 +02:00
valtype = configtypes . Command ( ) ,
) ,
) ,
default = {
2017-09-05 13:52:42 +02:00
' normal ' : collections . OrderedDict ( [
2018-02-27 06:58:39 +01:00
( ' <Ctrl+q> ' , ' quit ' ) ,
2017-09-04 21:22:15 +02:00
( ' ZQ ' , ' quit ' ) ,
2017-09-27 11:10:25 +02:00
( ' I ' , ' invalid ' ) ,
2017-11-26 13:07:41 +01:00
( ' d ' , ' scroll down ' ) ,
2017-09-05 13:52:42 +02:00
] )
2017-08-12 21:07:17 +02:00
} ,
backends = [ ] ,
raw_backends = None ) ) ,
2018-02-27 15:55:00 +01:00
( ' content.javascript.enabled ' , configdata . Option (
name = ' content.javascript.enabled ' ,
description = ' Enable/Disable JavaScript ' ,
typ = configtypes . Bool ( ) ,
default = True ,
backends = [ ] ,
raw_backends = None ) ) ,
2018-09-03 23:27:09 +02:00
( ' completion.open_categories ' , configdata . Option (
name = ' completion.open_categories ' ,
description = ' Which categories to show (in which order) in the :open completion. ' ,
typ = configtypes . FlagList (
) ,
default = [ " searchengines " , " quickmarks " , " bookmarks " , " history " ] ,
backends = [ ] ,
raw_backends = None ) ) ,
( ' url.searchengines ' , configdata . Option (
name = ' url.searchengines ' ,
description = ' searchengines list ' ,
typ = configtypes . Dict (
keytype = configtypes . String ( ) ,
valtype = configtypes . String ( ) ,
) ,
default = { " DEFAULT " : " https://duckduckgo.com/?q= {} " , " google " : " https://google.com/?q= {} " } ,
backends = [ ] ,
raw_backends = None ) ) ,
2017-08-12 21:07:17 +02:00
] ) )
2018-02-19 19:16:50 +01:00
config_stub . _init_values ( )
2016-06-30 13:24:55 +02:00
2016-06-16 05:41:14 +02:00
@pytest.fixture
def quickmarks ( quickmark_manager_stub ) :
""" Pre-populate the quickmark-manager stub with some quickmarks. """
quickmark_manager_stub . marks = collections . OrderedDict ( [
( ' aw ' , ' https://wiki.archlinux.org ' ) ,
( ' wiki ' , ' https://wikipedia.org ' ) ,
2017-08-05 23:03:40 +02:00
( ' ddg ' , ' https://duckduckgo.com ' ) ,
2016-06-16 05:41:14 +02:00
] )
return quickmark_manager_stub
@pytest.fixture
def bookmarks ( bookmark_manager_stub ) :
""" Pre-populate the bookmark-manager stub with some quickmarks. """
bookmark_manager_stub . marks = collections . OrderedDict ( [
( ' https://github.com ' , ' GitHub ' ) ,
( ' https://python.org ' , ' Welcome to Python.org ' ) ,
( ' http://qutebrowser.org ' , ' qutebrowser | qutebrowser ' ) ,
] )
return bookmark_manager_stub
@pytest.fixture
2017-07-14 15:28:06 +02:00
def web_history ( init_sql , stubs , config_stub ) :
2017-07-08 03:16:50 +02:00
""" Fixture which provides a web-history object. """
2017-08-12 21:07:17 +02:00
config_stub . val . completion . timestamp_format = ' % Y- % m- %d '
config_stub . val . completion . web_history_max_items = - 1
2017-07-08 03:16:50 +02:00
stub = history . WebHistory ( )
objreg . register ( ' web-history ' , stub )
yield stub
objreg . delete ( ' web-history ' )
2017-04-18 13:48:11 +02:00
@pytest.fixture
2017-07-08 03:16:50 +02:00
def web_history_populated ( web_history ) :
2017-02-12 14:39:24 +01:00
""" Pre-populate the web-history database. """
2017-07-08 03:16:50 +02:00
web_history . add_url (
url = QUrl ( ' http://qutebrowser.org ' ) ,
2017-06-21 05:04:03 +02:00
title = ' qutebrowser ' ,
atime = datetime ( 2015 , 9 , 5 ) . timestamp ( )
)
2017-07-08 03:16:50 +02:00
web_history . add_url (
url = QUrl ( ' https://python.org ' ) ,
2017-06-21 05:04:03 +02:00
title = ' Welcome to Python.org ' ,
atime = datetime ( 2016 , 3 , 8 ) . timestamp ( )
)
2017-07-08 03:16:50 +02:00
web_history . add_url (
url = QUrl ( ' https://github.com ' ) ,
2017-06-21 05:04:03 +02:00
title = ' https://github.com ' ,
atime = datetime ( 2016 , 5 , 1 ) . timestamp ( )
)
2017-07-08 03:16:50 +02:00
return web_history
2016-06-11 18:43:37 +02:00
2017-09-04 19:55:30 +02:00
@pytest.fixture
def info ( config_stub , key_config_stub ) :
return completer . CompletionInfo ( config = config_stub ,
2017-12-03 13:32:55 +01:00
keyconf = key_config_stub ,
win_id = 0 )
2017-09-04 19:55:30 +02:00
2017-08-12 21:07:17 +02:00
def test_command_completion ( qtmodeltester , cmdutils_stub , configdata_stub ,
2017-09-04 21:00:35 +02:00
key_config_stub , info ) :
2016-06-11 18:43:37 +02:00
""" Test the results of command completion.
Validates that :
- only non - hidden and non - deprecated commands are included
- the command description is shown in the desc column
- the binding ( if any ) is shown in the misc column
- aliases are included
"""
2017-09-04 21:00:35 +02:00
model = miscmodels . command ( info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
" Commands " : [
2017-08-12 21:07:17 +02:00
( ' open ' , ' open a url ' , ' ' ) ,
( ' q ' , " Alias for ' quit ' " , ' ' ) ,
2018-02-27 06:58:39 +01:00
( ' quit ' , ' quit qutebrowser ' , ' ZQ, <Ctrl+q> ' ) ,
2017-11-26 13:07:41 +01:00
( ' tab-close ' , ' Close the current tab. ' , ' ' ) ,
2016-08-10 04:06:03 +02:00
]
} )
2016-06-11 18:43:37 +02:00
2017-08-12 21:07:17 +02:00
def test_help_completion ( qtmodeltester , cmdutils_stub , key_config_stub ,
2017-09-04 21:00:35 +02:00
configdata_stub , config_stub , info ) :
2016-06-14 04:20:25 +02:00
""" Test the results of command completion.
Validates that :
2016-08-01 18:11:26 +02:00
- only non - deprecated commands are included
2016-06-14 04:20:25 +02:00
- the command description is shown in the desc column
- the binding ( if any ) is shown in the misc column
2017-08-12 21:07:17 +02:00
- aliases are not included
2016-06-14 04:20:25 +02:00
- only the first line of a multiline description is shown
"""
2017-09-04 21:00:35 +02:00
model = miscmodels . helptopic ( info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
" Commands " : [
2017-08-12 21:07:17 +02:00
( ' :open ' , ' open a url ' , ' ' ) ,
2018-02-27 06:58:39 +01:00
( ' :quit ' , ' quit qutebrowser ' , ' ZQ, <Ctrl+q> ' ) ,
2017-11-26 13:07:41 +01:00
( ' :scroll ' , ' Scroll the current tab in the given direction. ' , ' ' ) ,
( ' :tab-close ' , ' Close the current tab. ' , ' ' ) ,
2016-08-10 04:06:03 +02:00
] ,
" Settings " : [
2017-08-12 21:07:17 +02:00
( ' aliases ' , ' Aliases for commands. ' , None ) ,
( ' bindings.commands ' , ' Default keybindings ' , None ) ,
( ' bindings.default ' , ' Default keybindings ' , None ) ,
2018-09-03 23:27:09 +02:00
( ' completion.open_categories ' , ' Which categories to show (in which order) in the :open completion. ' , None ) ,
2018-02-27 15:55:00 +01:00
( ' content.javascript.enabled ' , ' Enable/Disable JavaScript ' , None ) ,
2018-09-03 23:27:09 +02:00
( ' url.searchengines ' , ' searchengines list ' , None ) ,
] ,
2016-08-10 04:06:03 +02:00
} )
2016-06-14 04:20:25 +02:00
2018-09-03 23:27:09 +02:00
def test_open_categories ( qtmodeltester , config_stub , web_history_populated ,
quickmarks , bookmarks , info ) :
""" Test that open_categories settings has the desired effect.
Verify that :
- All categories are listed when they are defined in the completion . open_categories list
"""
config_stub . val . url . searchengines = { " DEFAULT " : " https://duckduckgo.com/?q= {} " ,
" google " : " https://google.com/?q= {} " }
config_stub . val . completion . open_categories = [ " searchengines " , " quickmarks " , " bookmarks " , " history " ]
model = urlmodel . url ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Search engines " : [
( ' google ' , ' https://google.com/?q= {} ' , None ) ,
] ,
" Quickmarks " : [
( ' https://wiki.archlinux.org ' , ' aw ' , None ) ,
( ' https://wikipedia.org ' , ' wiki ' , None ) ,
( ' https://duckduckgo.com ' , ' ddg ' , None ) ,
] ,
" Bookmarks " : [
( ' https://github.com ' , ' GitHub ' , None ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , None ) ,
( ' http://qutebrowser.org ' , ' qutebrowser | qutebrowser ' , None ) ,
] ,
" History " : [
( ' https://github.com ' , ' https://github.com ' , ' 2016-05-01 ' ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , ' 2016-03-08 ' ) ,
( ' http://qutebrowser.org ' , ' qutebrowser ' , ' 2015-09-05 ' ) ,
] ,
} )
def test_open_categories_remove_all ( qtmodeltester , config_stub , web_history_populated ,
quickmarks , bookmarks , info ) :
""" Test that removing an item (boookmarks) from the open_categories settings has the desired effect.
Verify that :
- Only categories
"""
config_stub . val . url . searchengines = { " DEFAULT " : " https://duckduckgo.com/?q= {} " ,
" google " : " https://google.com/?q= {} " }
config_stub . val . completion . open_categories = [ ]
model = urlmodel . url ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
} )
def test_open_categories_remove_one ( qtmodeltester , config_stub , web_history_populated ,
quickmarks , bookmarks , info ) :
""" Test that removing an item (boookmarks) from the open_categories settings has the desired effect.
Verify that :
- Only categories
"""
config_stub . val . url . searchengines = { " DEFAULT " : " https://duckduckgo.com/?q= {} " ,
" google " : " https://google.com/?q= {} " }
config_stub . val . completion . open_categories = [ " searchengines " , " quickmarks " , " history " ]
model = urlmodel . url ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Search engines " : [
( ' google ' , ' https://google.com/?q= {} ' , None ) ,
] ,
" Quickmarks " : [
( ' https://wiki.archlinux.org ' , ' aw ' , None ) ,
( ' https://wikipedia.org ' , ' wiki ' , None ) ,
( ' https://duckduckgo.com ' , ' ddg ' , None ) ,
] ,
" History " : [
( ' https://github.com ' , ' https://github.com ' , ' 2016-05-01 ' ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , ' 2016-03-08 ' ) ,
( ' http://qutebrowser.org ' , ' qutebrowser ' , ' 2015-09-05 ' ) ,
] ,
} )
2016-07-29 10:26:55 +02:00
def test_quickmark_completion ( qtmodeltester , quickmarks ) :
2016-06-16 05:41:14 +02:00
""" Test the results of quickmark completion. """
2016-09-16 21:41:54 +02:00
model = miscmodels . quickmark ( )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
" Quickmarks " : [
2017-03-23 17:02:07 +01:00
( ' aw ' , ' https://wiki.archlinux.org ' , None ) ,
( ' wiki ' , ' https://wikipedia.org ' , None ) ,
2017-08-05 23:03:40 +02:00
( ' ddg ' , ' https://duckduckgo.com ' , None ) ,
2016-08-10 04:06:03 +02:00
]
} )
2016-06-16 05:41:14 +02:00
2017-07-28 15:02:15 +02:00
@pytest.mark.parametrize ( ' row, removed ' , [
( 0 , ' aw ' ) ,
2017-08-05 23:03:40 +02:00
( 1 , ' wiki ' ) ,
( 2 , ' ddg ' ) ,
2017-07-28 15:02:15 +02:00
] )
def test_quickmark_completion_delete ( qtmodeltester , quickmarks , row , removed ) :
""" Test deleting a quickmark from the quickmark completion model. """
model = miscmodels . quickmark ( )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
parent = model . index ( 0 , 0 )
idx = model . index ( row , 0 , parent )
before = set ( quickmarks . marks . keys ( ) )
model . delete_cur_item ( idx )
after = set ( quickmarks . marks . keys ( ) )
assert before . difference ( after ) == { removed }
2016-07-29 10:26:55 +02:00
def test_bookmark_completion ( qtmodeltester , bookmarks ) :
2016-06-16 05:41:14 +02:00
""" Test the results of bookmark completion. """
2016-09-16 21:41:54 +02:00
model = miscmodels . bookmark ( )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
" Bookmarks " : [
2017-03-23 17:02:07 +01:00
( ' https://github.com ' , ' GitHub ' , None ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , None ) ,
2017-08-05 23:03:40 +02:00
( ' http://qutebrowser.org ' , ' qutebrowser | qutebrowser ' , None ) ,
2016-08-10 04:06:03 +02:00
]
} )
2016-06-16 05:41:14 +02:00
2017-07-28 15:02:15 +02:00
@pytest.mark.parametrize ( ' row, removed ' , [
2017-08-05 23:03:40 +02:00
( 0 , ' https://github.com ' ) ,
( 1 , ' https://python.org ' ) ,
( 2 , ' http://qutebrowser.org ' ) ,
2017-07-28 15:02:15 +02:00
] )
def test_bookmark_completion_delete ( qtmodeltester , bookmarks , row , removed ) :
""" Test deleting a quickmark from the quickmark completion model. """
model = miscmodels . bookmark ( )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
parent = model . index ( 0 , 0 )
idx = model . index ( row , 0 , parent )
before = set ( bookmarks . marks . keys ( ) )
model . delete_cur_item ( idx )
after = set ( bookmarks . marks . keys ( ) )
assert before . difference ( after ) == { removed }
2017-09-17 11:49:42 +02:00
@pytest.fixture ( autouse = True )
def url_args ( fake_args ) :
""" Prepare arguments needed to test the URL completion. """
fake_args . debug_flags = [ ]
2018-09-03 23:27:09 +02:00
def test_url_completion ( qtmodeltester , config_stub , web_history_populated ,
2017-09-04 19:55:30 +02:00
quickmarks , bookmarks , info ) :
2016-06-16 05:41:14 +02:00
""" Test the results of url completion.
Verify that :
2018-09-03 23:27:09 +02:00
- searchengines , quickmarks , bookmarks , and urls are included
- default search engine is not displayed
2017-02-23 03:12:23 +01:00
- entries are sorted by access time
2017-04-18 13:48:11 +02:00
- only the most recent entry is included for each url
2016-06-16 05:41:14 +02:00
"""
2018-09-03 23:27:09 +02:00
config_stub . val . completion . open_categories = [ " searchengines " , " quickmarks " , " bookmarks " , " history " ]
config_stub . val . url . searchengines = { " DEFAULT " : " https://duckduckgo.com/?q= {} " , " google " : " https://google.com/?q= {} " }
2017-09-04 19:55:30 +02:00
model = urlmodel . url ( info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
2018-09-03 23:27:09 +02:00
" Search engines " : [
( ' google ' , ' https://google.com/?q= {} ' , None ) ,
] ,
2016-08-10 04:06:03 +02:00
" Quickmarks " : [
2017-04-18 13:48:11 +02:00
( ' https://wiki.archlinux.org ' , ' aw ' , None ) ,
2017-02-15 02:32:44 +01:00
( ' https://wikipedia.org ' , ' wiki ' , None ) ,
2017-08-05 23:03:40 +02:00
( ' https://duckduckgo.com ' , ' ddg ' , None ) ,
2016-08-10 04:06:03 +02:00
] ,
" Bookmarks " : [
2017-02-12 14:39:24 +01:00
( ' https://github.com ' , ' GitHub ' , None ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , None ) ,
2017-08-05 23:03:40 +02:00
( ' http://qutebrowser.org ' , ' qutebrowser | qutebrowser ' , None ) ,
2016-08-10 04:06:03 +02:00
] ,
" History " : [
2017-02-23 03:05:03 +01:00
( ' https://github.com ' , ' https://github.com ' , ' 2016-05-01 ' ) ,
2016-06-16 05:41:14 +02:00
( ' https://python.org ' , ' Welcome to Python.org ' , ' 2016-03-08 ' ) ,
2017-02-23 03:12:23 +01:00
( ' http://qutebrowser.org ' , ' qutebrowser ' , ' 2015-09-05 ' ) ,
2016-08-10 04:06:03 +02:00
] ,
} )
2016-06-16 05:41:14 +02:00
2018-09-03 23:27:09 +02:00
def test_search_only_default ( qtmodeltester , config_stub , web_history_populated ,
quickmarks , bookmarks , info ) :
""" Test that Seardh engines is not shown when only default search engine is set in settings.
Verify that :
- No Search engines categories is shown
"""
config_stub . val . completion . open_categories = [ " searchengines " , " quickmarks " , " bookmarks " , " history " ]
config_stub . val . url . searchengines = { " DEFAULT " : " https://duckduckgo.com/?q= {} " , }
model = urlmodel . url ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Quickmarks " : [
( ' https://wiki.archlinux.org ' , ' aw ' , None ) ,
( ' https://wikipedia.org ' , ' wiki ' , None ) ,
( ' https://duckduckgo.com ' , ' ddg ' , None ) ,
] ,
" Bookmarks " : [
( ' https://github.com ' , ' GitHub ' , None ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , None ) ,
( ' http://qutebrowser.org ' , ' qutebrowser | qutebrowser ' , None ) ,
] ,
" History " : [
( ' https://github.com ' , ' https://github.com ' , ' 2016-05-01 ' ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , ' 2016-03-08 ' ) ,
( ' http://qutebrowser.org ' , ' qutebrowser ' , ' 2015-09-05 ' ) ,
] ,
} )
2016-06-16 05:41:14 +02:00
2017-11-28 13:20:49 +01:00
def test_url_completion_no_quickmarks ( qtmodeltester , web_history_populated ,
quickmark_manager_stub , bookmarks , info ) :
""" Test that the quickmark category is gone with no quickmarks. """
model = urlmodel . url ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Bookmarks " : [
( ' https://github.com ' , ' GitHub ' , None ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , None ) ,
( ' http://qutebrowser.org ' , ' qutebrowser | qutebrowser ' , None ) ,
] ,
" History " : [
( ' https://github.com ' , ' https://github.com ' , ' 2016-05-01 ' ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , ' 2016-03-08 ' ) ,
( ' http://qutebrowser.org ' , ' qutebrowser ' , ' 2015-09-05 ' ) ,
] ,
} )
def test_url_completion_no_bookmarks ( qtmodeltester , web_history_populated ,
quickmarks , bookmark_manager_stub , info ) :
""" Test that the bookmarks category is gone with no bookmarks. """
model = urlmodel . url ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Quickmarks " : [
( ' https://wiki.archlinux.org ' , ' aw ' , None ) ,
( ' https://wikipedia.org ' , ' wiki ' , None ) ,
( ' https://duckduckgo.com ' , ' ddg ' , None ) ,
] ,
" History " : [
( ' https://github.com ' , ' https://github.com ' , ' 2016-05-01 ' ) ,
( ' https://python.org ' , ' Welcome to Python.org ' , ' 2016-03-08 ' ) ,
( ' http://qutebrowser.org ' , ' qutebrowser ' , ' 2015-09-05 ' ) ,
] ,
} )
2017-04-18 13:48:11 +02:00
@pytest.mark.parametrize ( ' url, title, pattern, rowcount ' , [
( ' example.com ' , ' Site Title ' , ' ' , 1 ) ,
( ' example.com ' , ' Site Title ' , ' ex ' , 1 ) ,
( ' example.com ' , ' Site Title ' , ' am ' , 1 ) ,
( ' example.com ' , ' Site Title ' , ' com ' , 1 ) ,
( ' example.com ' , ' Site Title ' , ' ex com ' , 1 ) ,
2017-12-10 21:06:45 +01:00
( ' example.com ' , ' Site Title ' , ' com ex ' , 1 ) ,
2017-04-18 13:48:11 +02:00
( ' example.com ' , ' Site Title ' , ' ex foo ' , 0 ) ,
( ' example.com ' , ' Site Title ' , ' foo com ' , 0 ) ,
( ' example.com ' , ' Site Title ' , ' exm ' , 0 ) ,
( ' example.com ' , ' Site Title ' , ' Si Ti ' , 1 ) ,
2017-12-10 21:06:45 +01:00
( ' example.com ' , ' Site Title ' , ' Ti Si ' , 1 ) ,
2017-04-18 13:48:11 +02:00
( ' example.com ' , ' ' , ' foo ' , 0 ) ,
( ' foo_bar ' , ' ' , ' _ ' , 1 ) ,
( ' foobar ' , ' ' , ' _ ' , 0 ) ,
( ' foo % bar ' , ' ' , ' % ' , 1 ) ,
( ' foobar ' , ' ' , ' % ' , 0 ) ,
] )
2017-07-14 15:28:06 +02:00
def test_url_completion_pattern ( web_history , quickmark_manager_stub ,
2017-09-04 19:55:30 +02:00
bookmark_manager_stub , info ,
url , title , pattern , rowcount ) :
2017-04-18 13:48:11 +02:00
""" Test that url completion filters by url and title. """
2017-07-08 03:16:50 +02:00
web_history . add_url ( QUrl ( url ) , title )
2017-09-04 19:55:30 +02:00
model = urlmodel . url ( info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( pattern )
# 2, 0 is History
2017-11-28 13:20:49 +01:00
assert model . rowCount ( model . index ( 0 , 0 ) ) == rowcount
2017-04-18 13:48:11 +02:00
2017-07-14 15:28:06 +02:00
def test_url_completion_delete_bookmark ( qtmodeltester , bookmarks ,
2017-09-04 19:55:30 +02:00
web_history , quickmarks , info ) :
2016-06-22 05:04:03 +02:00
""" Test deleting a bookmark from the url completion model. """
2017-09-04 19:55:30 +02:00
model = urlmodel . url ( info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2017-06-21 05:04:03 +02:00
parent = model . index ( 1 , 0 )
idx = model . index ( 1 , 0 , parent )
# sanity checks
assert model . data ( parent ) == " Bookmarks "
2017-08-05 23:03:40 +02:00
assert model . data ( idx ) == ' https://python.org '
2017-06-21 05:04:03 +02:00
assert ' https://github.com ' in bookmarks . marks
len_before = len ( bookmarks . marks )
model . delete_cur_item ( idx )
2017-08-05 23:03:40 +02:00
assert ' https://python.org ' not in bookmarks . marks
2017-06-21 05:04:03 +02:00
assert len_before == len ( bookmarks . marks ) + 1
2016-06-22 05:04:03 +02:00
2017-09-04 19:55:30 +02:00
def test_url_completion_delete_quickmark ( qtmodeltester , info , qtbot ,
quickmarks , web_history , bookmarks ) :
2016-06-22 05:04:03 +02:00
""" Test deleting a bookmark from the url completion model. """
2017-09-04 19:55:30 +02:00
model = urlmodel . url ( info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2017-06-21 05:04:03 +02:00
parent = model . index ( 0 , 0 )
idx = model . index ( 0 , 0 , parent )
# sanity checks
assert model . data ( parent ) == " Quickmarks "
2017-08-05 23:03:40 +02:00
assert model . data ( idx ) == ' https://wiki.archlinux.org '
2017-06-21 05:04:03 +02:00
assert ' ddg ' in quickmarks . marks
len_before = len ( quickmarks . marks )
model . delete_cur_item ( idx )
2017-08-05 23:03:40 +02:00
assert ' aw ' not in quickmarks . marks
2017-06-21 05:04:03 +02:00
assert len_before == len ( quickmarks . marks ) + 1
2016-06-22 05:04:03 +02:00
2017-09-04 19:55:30 +02:00
def test_url_completion_delete_history ( qtmodeltester , info ,
2017-07-08 03:16:50 +02:00
web_history_populated ,
2017-06-21 05:04:03 +02:00
quickmarks , bookmarks ) :
""" Test deleting a history entry. """
2017-09-04 19:55:30 +02:00
model = urlmodel . url ( info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2017-03-23 17:02:07 +01:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2017-06-21 05:04:03 +02:00
parent = model . index ( 2 , 0 )
idx = model . index ( 1 , 0 , parent )
# sanity checks
assert model . data ( parent ) == " History "
assert model . data ( idx ) == ' https://python.org '
2017-07-08 03:16:50 +02:00
assert ' https://python.org ' in web_history_populated
2017-06-21 05:04:03 +02:00
model . delete_cur_item ( idx )
2017-07-08 03:16:50 +02:00
assert ' https://python.org ' not in web_history_populated
2017-03-23 17:02:07 +01:00
2017-09-04 19:55:30 +02:00
def test_url_completion_zero_limit ( config_stub , web_history , quickmarks , info ,
2017-07-21 17:55:47 +02:00
bookmarks ) :
""" Make sure there ' s no history if the limit was set to zero. """
2017-08-12 21:07:17 +02:00
config_stub . val . completion . web_history_max_items = 0
2018-09-03 23:27:09 +02:00
config_stub . val . completion . open_categories = [ " searchengines " , " quickmarks " , " bookmarks " , " history " ]
config_stub . val . url . searchengines = { " DEFAULT " : " https://duckduckgo.com/?q= {} " , " google " : " https://google.com/?q= {} " }
2017-09-04 19:55:30 +02:00
model = urlmodel . url ( info = info )
2017-07-21 17:55:47 +02:00
model . set_pattern ( ' ' )
2018-09-03 23:27:09 +02:00
category = model . index ( 3 , 0 ) # "History" normally
2017-07-21 17:55:47 +02:00
assert model . data ( category ) is None
2016-06-22 05:04:03 +02:00
2016-07-29 10:26:55 +02:00
def test_session_completion ( qtmodeltester , session_manager_stub ) :
2016-06-17 05:12:04 +02:00
session_manager_stub . sessions = [ ' default ' , ' 1 ' , ' 2 ' ]
2016-09-16 21:41:54 +02:00
model = miscmodels . session ( )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
2017-10-23 15:29:13 +02:00
" Sessions " : [ ( ' 1 ' , None , None ) ,
( ' 2 ' , None , None ) ,
( ' default ' , None , None ) ]
2016-08-10 04:06:03 +02:00
} )
2016-06-17 05:12:04 +02:00
2016-07-29 10:26:55 +02:00
def test_tab_completion ( qtmodeltester , fake_web_tab , app_stub , win_registry ,
2016-06-23 14:21:55 +02:00
tabbed_browser_stubs ) :
2018-02-15 12:02:42 +01:00
tabbed_browser_stubs [ 0 ] . widget . tabs = [
2016-07-08 18:48:24 +02:00
fake_web_tab ( QUrl ( ' https://github.com ' ) , ' GitHub ' , 0 ) ,
fake_web_tab ( QUrl ( ' https://wikipedia.org ' ) , ' Wikipedia ' , 1 ) ,
fake_web_tab ( QUrl ( ' https://duckduckgo.com ' ) , ' DuckDuckGo ' , 2 ) ,
2016-06-17 05:12:21 +02:00
]
2018-02-15 12:02:42 +01:00
tabbed_browser_stubs [ 1 ] . widget . tabs = [
2016-07-08 18:48:24 +02:00
fake_web_tab ( QUrl ( ' https://wiki.archlinux.org ' ) , ' ArchWiki ' , 0 ) ,
2016-06-23 14:21:55 +02:00
]
2016-09-16 21:41:54 +02:00
model = miscmodels . buffer ( )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
' 0 ' : [
2016-06-17 05:12:21 +02:00
( ' 0/1 ' , ' https://github.com ' , ' GitHub ' ) ,
( ' 0/2 ' , ' https://wikipedia.org ' , ' Wikipedia ' ) ,
( ' 0/3 ' , ' https://duckduckgo.com ' , ' DuckDuckGo ' )
2016-08-10 04:06:03 +02:00
] ,
' 1 ' : [
2016-06-23 14:21:55 +02:00
( ' 1/1 ' , ' https://wiki.archlinux.org ' , ' ArchWiki ' ) ,
2016-08-10 04:06:03 +02:00
]
} )
2016-06-17 05:12:21 +02:00
2017-06-21 05:04:03 +02:00
def test_tab_completion_delete ( qtmodeltester , fake_web_tab , app_stub ,
2016-07-29 10:26:55 +02:00
win_registry , tabbed_browser_stubs ) :
2016-06-21 03:58:12 +02:00
""" Verify closing a tab by deleting it from the completion widget. """
2018-02-15 12:02:42 +01:00
tabbed_browser_stubs [ 0 ] . widget . tabs = [
2016-07-08 18:48:24 +02:00
fake_web_tab ( QUrl ( ' https://github.com ' ) , ' GitHub ' , 0 ) ,
fake_web_tab ( QUrl ( ' https://wikipedia.org ' ) , ' Wikipedia ' , 1 ) ,
fake_web_tab ( QUrl ( ' https://duckduckgo.com ' ) , ' DuckDuckGo ' , 2 )
2016-06-21 03:58:12 +02:00
]
2018-02-15 12:02:42 +01:00
tabbed_browser_stubs [ 1 ] . widget . tabs = [
2016-07-08 18:48:24 +02:00
fake_web_tab ( QUrl ( ' https://wiki.archlinux.org ' ) , ' ArchWiki ' , 0 ) ,
2016-06-23 14:21:55 +02:00
]
2016-09-16 21:41:54 +02:00
model = miscmodels . buffer ( )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2017-06-21 05:04:03 +02:00
parent = model . index ( 0 , 0 )
idx = model . index ( 1 , 0 , parent )
# sanity checks
assert model . data ( parent ) == " 0 "
assert model . data ( idx ) == ' 0/2 '
model . delete_cur_item ( idx )
2018-02-15 12:02:42 +01:00
actual = [ tab . url ( ) for tab in tabbed_browser_stubs [ 0 ] . widget . tabs ]
2016-06-21 03:58:12 +02:00
assert actual == [ QUrl ( ' https://github.com ' ) ,
QUrl ( ' https://duckduckgo.com ' ) ]
2018-09-03 23:27:09 +02:00
def test_tab_completion_not_sorted ( qtmodeltester , fake_web_tab , app_stub ,
win_registry , tabbed_browser_stubs ) :
""" Ensure that the completion row order is the same as tab index order.
Would be violated for more than 9 tabs if the completion was being
alphabetically sorted on the first column , or the others .
"""
expected = [ ]
for idx in range ( 1 , 11 ) :
url = " " . join ( random . sample ( string . ascii_letters , 12 ) )
title = " " . join ( random . sample ( string . ascii_letters , 12 ) )
expected . append ( ( " 0/ {} " . format ( idx ) , url , title ) )
tabbed_browser_stubs [ 0 ] . widget . tabs = [
fake_web_tab ( QUrl ( tab [ 1 ] ) , tab [ 2 ] , idx )
for idx , tab in enumerate ( expected )
]
model = miscmodels . buffer ( )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
' 0 ' : expected ,
' 1 ' : [ ] ,
} )
2017-12-03 13:32:55 +01:00
def test_other_buffer_completion ( qtmodeltester , fake_web_tab , app_stub ,
win_registry , tabbed_browser_stubs , info ) :
2018-02-15 12:02:42 +01:00
tabbed_browser_stubs [ 0 ] . widget . tabs = [
2017-12-03 13:32:55 +01:00
fake_web_tab ( QUrl ( ' https://github.com ' ) , ' GitHub ' , 0 ) ,
fake_web_tab ( QUrl ( ' https://wikipedia.org ' ) , ' Wikipedia ' , 1 ) ,
fake_web_tab ( QUrl ( ' https://duckduckgo.com ' ) , ' DuckDuckGo ' , 2 ) ,
]
2018-02-15 12:02:42 +01:00
tabbed_browser_stubs [ 1 ] . widget . tabs = [
2017-12-03 13:32:55 +01:00
fake_web_tab ( QUrl ( ' https://wiki.archlinux.org ' ) , ' ArchWiki ' , 0 ) ,
]
info . win_id = 1
model = miscmodels . other_buffer ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
' 0 ' : [
( ' 0/1 ' , ' https://github.com ' , ' GitHub ' ) ,
( ' 0/2 ' , ' https://wikipedia.org ' , ' Wikipedia ' ) ,
( ' 0/3 ' , ' https://duckduckgo.com ' , ' DuckDuckGo ' )
] ,
} )
2018-04-10 08:43:35 +02:00
def test_other_buffer_completion_id0 ( qtmodeltester , fake_web_tab , app_stub ,
win_registry , tabbed_browser_stubs , info ) :
tabbed_browser_stubs [ 0 ] . widget . tabs = [
fake_web_tab ( QUrl ( ' https://github.com ' ) , ' GitHub ' , 0 ) ,
fake_web_tab ( QUrl ( ' https://wikipedia.org ' ) , ' Wikipedia ' , 1 ) ,
fake_web_tab ( QUrl ( ' https://duckduckgo.com ' ) , ' DuckDuckGo ' , 2 ) ,
]
tabbed_browser_stubs [ 1 ] . widget . tabs = [
fake_web_tab ( QUrl ( ' https://wiki.archlinux.org ' ) , ' ArchWiki ' , 0 ) ,
]
info . win_id = 0
model = miscmodels . other_buffer ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
' 1 ' : [
( ' 1/1 ' , ' https://wiki.archlinux.org ' , ' ArchWiki ' ) ,
] ,
} )
2017-12-03 13:32:55 +01:00
def test_window_completion ( qtmodeltester , fake_web_tab , tabbed_browser_stubs ,
info ) :
2018-02-15 12:02:42 +01:00
tabbed_browser_stubs [ 0 ] . widget . tabs = [
2017-10-11 08:14:18 +02:00
fake_web_tab ( QUrl ( ' https://github.com ' ) , ' GitHub ' , 0 ) ,
fake_web_tab ( QUrl ( ' https://wikipedia.org ' ) , ' Wikipedia ' , 1 ) ,
fake_web_tab ( QUrl ( ' https://duckduckgo.com ' ) , ' DuckDuckGo ' , 2 )
]
2018-02-15 12:02:42 +01:00
tabbed_browser_stubs [ 1 ] . widget . tabs = [
2017-10-11 08:14:18 +02:00
fake_web_tab ( QUrl ( ' https://wiki.archlinux.org ' ) , ' ArchWiki ' , 0 )
]
2017-12-03 13:32:55 +01:00
info . win_id = 1
model = miscmodels . window ( info = info )
2017-10-11 08:14:18 +02:00
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
' Windows ' : [
( ' 0 ' , ' window title - qutebrowser ' ,
2017-12-15 19:08:15 +01:00
' GitHub, Wikipedia, DuckDuckGo ' ) ,
2017-10-11 08:14:18 +02:00
]
} )
2017-08-12 21:07:17 +02:00
def test_setting_option_completion ( qtmodeltester , config_stub ,
2017-09-04 19:55:30 +02:00
configdata_stub , info ) :
model = configmodel . option ( info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-07-29 10:26:55 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
2017-08-12 21:07:17 +02:00
" Options " : [
( ' aliases ' , ' Aliases for commands. ' , ' { " q " : " quit " } ' ) ,
2017-12-15 19:08:15 +01:00
( ' bindings.commands ' , ' Default keybindings ' , (
2018-02-27 06:58:39 +01:00
' { " normal " : { " <Ctrl+q> " : " quit " , " ZQ " : " quit " , '
2017-12-15 19:08:15 +01:00
' " I " : " invalid " , " d " : " scroll down " }} ' ) ) ,
2018-09-03 23:27:09 +02:00
( ' completion.open_categories ' , ' Which categories to show (in which order) in the :open completion. ' , ' [ " searchengines " , " quickmarks " , " bookmarks " , " history " ] ' ) ,
2018-02-27 15:55:00 +01:00
( ' content.javascript.enabled ' , ' Enable/Disable JavaScript ' ,
' true ' ) ,
2018-09-03 23:27:09 +02:00
( ' url.searchengines ' , ' searchengines list ' ,
' { " DEFAULT " : " https://duckduckgo.com/?q= {} " , " google " : " https://google.com/?q= {} " } ' ) ,
2016-08-10 04:06:03 +02:00
]
} )
2016-06-18 12:55:17 +02:00
2018-02-27 15:55:00 +01:00
def test_setting_customized_option_completion ( qtmodeltester , config_stub ,
configdata_stub , info ) :
info . config . set_obj ( ' aliases ' , { ' foo ' : ' nop ' } )
model = configmodel . customized_option ( info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Customized options " : [
( ' aliases ' , ' Aliases for commands. ' , ' { " foo " : " nop " } ' ) ,
]
} )
def test_setting_value_completion ( qtmodeltester , config_stub , configdata_stub ,
info ) :
model = configmodel . value ( optname = ' content.javascript.enabled ' , info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Current/Default " : [
( ' true ' , ' Current value ' , None ) ,
( ' true ' , ' Default value ' , None ) ,
] ,
" Completions " : [
( ' false ' , ' ' , None ) ,
( ' true ' , ' ' , None ) ,
] ,
} )
def test_setting_value_no_completions ( qtmodeltester , config_stub ,
configdata_stub , info ) :
model = configmodel . value ( optname = ' aliases ' , info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Current/Default " : [
( ' { " q " : " quit " } ' , ' Current value ' , None ) ,
( ' { " q " : " quit " } ' , ' Default value ' , None ) ,
] ,
} )
def test_setting_value_completion_invalid ( info ) :
assert configmodel . value ( optname = ' foobarbaz ' , info = info ) is None
2018-03-31 21:57:08 +02:00
@pytest.mark.parametrize ( ' args, expected ' , [
( [ ] , {
" Current/Default " : [
( ' true ' , ' Current value ' , None ) ,
( ' true ' , ' Default value ' , None ) ,
] ,
" Completions " : [
( ' false ' , ' ' , None ) ,
( ' true ' , ' ' , None ) ,
] ,
} ) ,
( [ ' false ' ] , {
" Current/Default " : [
( ' true ' , ' Current value ' , None ) ,
( ' true ' , ' Default value ' , None ) ,
] ,
" Completions " : [
( ' true ' , ' ' , None ) ,
] ,
} ) ,
( [ ' true ' ] , {
" Completions " : [
( ' false ' , ' ' , None ) ,
] ,
} ) ,
( [ ' false ' , ' true ' ] , { } ) ,
] )
def test_setting_value_cycle ( qtmodeltester , config_stub , configdata_stub ,
info , args , expected ) :
opt = ' content.javascript.enabled '
model = configmodel . value ( opt , * args , info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , expected )
2017-08-12 21:07:17 +02:00
def test_bind_completion ( qtmodeltester , cmdutils_stub , config_stub ,
2017-09-04 19:55:30 +02:00
key_config_stub , configdata_stub , info ) :
2016-08-04 12:30:24 +02:00
""" Test the results of keybinding command completion.
2016-08-01 18:30:12 +02:00
Validates that :
2017-08-12 21:07:17 +02:00
- only non - deprecated commands are included
2016-08-01 18:30:12 +02:00
- the command description is shown in the desc column
- the binding ( if any ) is shown in the misc column
- aliases are included
"""
2017-09-04 19:55:30 +02:00
model = configmodel . bind ( ' ZQ ' , info = info )
2017-04-18 13:48:11 +02:00
model . set_pattern ( ' ' )
2016-08-01 18:30:12 +02:00
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
2016-08-10 04:06:03 +02:00
_check_completions ( model , {
2017-11-26 13:07:41 +01:00
" Current/Default " : [
( ' quit ' , ' (Current) quit qutebrowser ' , ' ZQ ' ) ,
2017-06-30 03:44:44 +02:00
] ,
2016-08-10 04:06:03 +02:00
" Commands " : [
2017-08-12 21:07:17 +02:00
( ' open ' , ' open a url ' , ' ' ) ,
( ' q ' , " Alias for ' quit ' " , ' ' ) ,
2018-02-27 06:58:39 +01:00
( ' quit ' , ' quit qutebrowser ' , ' ZQ, <Ctrl+q> ' ) ,
2017-11-26 13:07:41 +01:00
( ' scroll ' , ' Scroll the current tab in the given direction. ' , ' ' ) ,
( ' tab-close ' , ' Close the current tab. ' , ' ' ) ,
2017-08-12 21:07:17 +02:00
] ,
2016-08-10 04:06:03 +02:00
} )
2017-02-23 02:43:48 +01:00
2017-09-27 11:10:25 +02:00
def test_bind_completion_invalid ( cmdutils_stub , config_stub , key_config_stub ,
configdata_stub , info ) :
""" Test command completion with an invalid command bound. """
model = configmodel . bind ( ' I ' , info = info )
model . set_pattern ( ' ' )
_check_completions ( model , {
2017-11-26 13:07:41 +01:00
" Current/Default " : [
( ' invalid ' , ' (Current) Invalid command! ' , ' I ' ) ,
2017-09-27 11:10:25 +02:00
] ,
" Commands " : [
( ' open ' , ' open a url ' , ' ' ) ,
( ' q ' , " Alias for ' quit ' " , ' ' ) ,
2018-02-27 06:58:39 +01:00
( ' quit ' , ' quit qutebrowser ' , ' ZQ, <Ctrl+q> ' ) ,
2017-11-26 13:07:41 +01:00
( ' scroll ' , ' Scroll the current tab in the given direction. ' , ' ' ) ,
( ' tab-close ' , ' Close the current tab. ' , ' ' ) ,
2017-09-27 11:10:25 +02:00
] ,
} )
2018-03-05 22:21:57 +01:00
def test_bind_completion_invalid_binding ( cmdutils_stub , config_stub ,
key_config_stub , configdata_stub ,
info ) :
""" Test command completion with an invalid key binding. """
model = configmodel . bind ( ' <blub> ' , info = info )
model . set_pattern ( ' ' )
_check_completions ( model , {
" Current/Default " : [
2018-03-06 07:39:41 +01:00
( ' ' , " Could not parse ' <blub> ' : Got invalid key! " , ' <blub> ' ) ,
2018-03-05 22:21:57 +01:00
] ,
" Commands " : [
( ' open ' , ' open a url ' , ' ' ) ,
( ' q ' , " Alias for ' quit ' " , ' ' ) ,
( ' quit ' , ' quit qutebrowser ' , ' ZQ, <Ctrl+q> ' ) ,
( ' scroll ' , ' Scroll the current tab in the given direction. ' , ' ' ) ,
( ' tab-close ' , ' Close the current tab. ' , ' ' ) ,
] ,
} )
2017-11-26 13:07:41 +01:00
def test_bind_completion_no_binding ( qtmodeltester , cmdutils_stub , config_stub ,
2017-09-09 18:39:04 +02:00
key_config_stub , configdata_stub , info ) :
2017-11-26 13:07:41 +01:00
""" Test keybinding completion with no current or default binding. """
2017-09-09 18:39:04 +02:00
model = configmodel . bind ( ' x ' , info = info )
model . set_pattern ( ' ' )
qtmodeltester . data_display_may_return_none = True
qtmodeltester . check ( model )
_check_completions ( model , {
" Commands " : [
( ' open ' , ' open a url ' , ' ' ) ,
( ' q ' , " Alias for ' quit ' " , ' ' ) ,
2018-02-27 06:58:39 +01:00
( ' quit ' , ' quit qutebrowser ' , ' ZQ, <Ctrl+q> ' ) ,
2017-11-26 13:07:41 +01:00
( ' scroll ' , ' Scroll the current tab in the given direction. ' , ' ' ) ,
( ' tab-close ' , ' Close the current tab. ' , ' ' ) ,
] ,
} )
def test_bind_completion_changed ( cmdutils_stub , config_stub , key_config_stub ,
configdata_stub , info ) :
""" Test command completion with a non-default command bound. """
model = configmodel . bind ( ' d ' , info = info )
model . set_pattern ( ' ' )
_check_completions ( model , {
" Current/Default " : [
( ' scroll down ' ,
' (Current) Scroll the current tab in the given direction. ' , ' d ' ) ,
( ' tab-close ' , ' (Default) Close the current tab. ' , ' d ' ) ,
] ,
" Commands " : [
( ' open ' , ' open a url ' , ' ' ) ,
( ' q ' , " Alias for ' quit ' " , ' ' ) ,
2018-02-27 06:58:39 +01:00
( ' quit ' , ' quit qutebrowser ' , ' ZQ, <Ctrl+q> ' ) ,
2017-11-26 13:07:41 +01:00
( ' scroll ' , ' Scroll the current tab in the given direction. ' , ' ' ) ,
( ' tab-close ' , ' Close the current tab. ' , ' ' ) ,
2017-09-09 18:39:04 +02:00
] ,
} )
2017-09-04 19:55:30 +02:00
def test_url_completion_benchmark ( benchmark , info ,
2017-02-23 02:43:48 +01:00
quickmark_manager_stub ,
bookmark_manager_stub ,
2017-07-08 03:16:50 +02:00
web_history ) :
2017-02-23 02:43:48 +01:00
""" Benchmark url completion. """
2017-06-11 19:57:38 +02:00
r = range ( 100000 )
entries = {
' last_atime ' : list ( r ) ,
' url ' : [ ' http://example.com/ {} ' . format ( i ) for i in r ] ,
' title ' : [ ' title {} ' . format ( i ) for i in r ]
}
2017-02-23 02:43:48 +01:00
2017-07-08 03:16:50 +02:00
web_history . completion . insert_batch ( entries )
2017-02-23 02:43:48 +01:00
2017-06-11 19:57:38 +02:00
quickmark_manager_stub . marks = collections . OrderedDict ( [
( ' title {} ' . format ( i ) , ' example.com/ {} ' . format ( i ) )
for i in range ( 1000 ) ] )
2017-02-23 02:43:48 +01:00
2017-06-11 19:57:38 +02:00
bookmark_manager_stub . marks = collections . OrderedDict ( [
( ' example.com/ {} ' . format ( i ) , ' title {} ' . format ( i ) )
for i in range ( 1000 ) ] )
2017-02-23 02:43:48 +01:00
def bench ( ) :
2017-09-04 19:55:30 +02:00
model = urlmodel . url ( info = info )
2017-02-13 00:14:46 +01:00
model . set_pattern ( ' ' )
model . set_pattern ( ' e ' )
model . set_pattern ( ' ex ' )
model . set_pattern ( ' ex ' )
model . set_pattern ( ' ex 1 ' )
model . set_pattern ( ' ex 12 ' )
model . set_pattern ( ' ex 123 ' )
2017-02-23 02:43:48 +01:00
benchmark ( bench )