Exemplo n.º 1
0
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': [],
    })
def test_tab_completion_delete(qtmodeltester, fake_web_tab, app_stub,
                               win_registry, tabbed_browser_stubs):
    """Verify closing a tab by deleting it from the completion widget."""
    tabbed_browser_stubs[0].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].tabs = [
        fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
    ]
    model = miscmodels.buffer()
    model.set_pattern('')
    qtmodeltester.data_display_may_return_none = True
    qtmodeltester.check(model)

    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)
    actual = [tab.url() for tab in tabbed_browser_stubs[0].tabs]
    assert actual == [
        QUrl('https://github.com'),
        QUrl('https://duckduckgo.com')
    ]
Exemplo n.º 3
0
def test_tab_completion_delete(qtmodeltester, fake_web_tab, app_stub,
                               win_registry, tabbed_browser_stubs):
    """Verify closing a tab by deleting it from the completion widget."""
    tabbed_browser_stubs[0].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].tabs = [
        fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
    ]
    model = miscmodels.buffer()
    model.set_pattern('')
    qtmodeltester.data_display_may_return_none = True
    qtmodeltester.check(model)

    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)
    actual = [tab.url() for tab in tabbed_browser_stubs[0].tabs]
    assert actual == [QUrl('https://github.com'),
                      QUrl('https://duckduckgo.com')]
Exemplo n.º 4
0
def test_tab_completion(qtmodeltester, fake_web_tab, app_stub, win_registry,
                        tabbed_browser_stubs):
    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),
    ]
    model = miscmodels.buffer()
    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')
        ],
        '1': [
            ('1/1', 'https://wiki.archlinux.org', 'ArchWiki'),
        ]
    })
Exemplo n.º 5
0
def test_tab_completion(qtmodeltester, fake_web_tab, app_stub, win_registry,
                        tabbed_browser_stubs):
    tabbed_browser_stubs[0].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].tabs = [
        fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
    ]
    model = miscmodels.buffer()
    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')
        ],
        '1': [
            ('1/1', 'https://wiki.archlinux.org', 'ArchWiki'),
        ]
    })
Exemplo n.º 6
0
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.check(model)

    _check_completions(model, {
        '0': expected,
        '1': [],
    })
Exemplo n.º 7
0
def test_tab_completion_tabs_are_windows(qtmodeltester, fake_web_tab,
                                         win_registry, tabbed_browser_stubs,
                                         config_stub):
    """Verify tabs across all windows are listed under a single category."""
    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),
    ]

    config_stub.val.tabs.tabs_are_windows = True
    model = miscmodels.buffer()
    model.set_pattern('')
    qtmodeltester.check(model)

    _check_completions(
        model, {
            'Windows': [
                ('0/1', 'https://github.com', 'GitHub'),
                ('0/2', 'https://wikipedia.org', 'Wikipedia'),
                ('0/3', 'https://duckduckgo.com', 'DuckDuckGo'),
                ('1/1', 'https://wiki.archlinux.org', 'ArchWiki'),
            ]
        })
Exemplo n.º 8
0
def resolve_tab_index(index: str) -> 'browsertab.AbstractTab':
    """Resolve a tab index string to the win_id and tab index.

    Args:
        index: The [win_id/]index of the tab to be selected. Or a substring
                in which case the closest match will be focused.
    """
    index_parts = index.split('/', 1)

    try:
        for part in index_parts:
            int(part)
    except ValueError:
        model = miscmodels.buffer()
        model.set_pattern(index)

        if model.count() > 0:
            index = model.data(model.first_item())
            index_parts = index.split('/', 1)
        else:
            raise cmdutils.CommandError(
                "No matching tab for: {}".format(index))

    if len(index_parts) == 2:
        win_id = int(index_parts[0])
        idx = int(index_parts[1])
    elif len(index_parts) == 1:
        idx = int(index_parts[0])
        active_window = QApplication.instance().activeWindow()

        if active_window is None:
            # Not sure how you enter a command without an active window...
            raise cmdutils.CommandError(
                "No window specified and couldn't find active window!")
        win_id = active_window.win_id

    if win_id not in objreg.window_registry:
        raise cmdutils.CommandError(
            "There's no window with id {}!".format(win_id))

    tabbed_browser = objreg.get('tabbed-browser',
                                scope='window',
                                window=win_id)

    if not 0 < idx <= tabbed_browser.widget.count():
        raise cmdutils.CommandError(
            "There's no tab with index {}!".format(idx))

    return tabbed_browser.widget.widget(idx - 1)
Exemplo n.º 9
0
def test_tab_completion(qtmodeltester, fake_web_tab, win_registry,
                        tabbed_browser_stubs):
    tabbed_browser_stubs[0].widget.tabs = [
        fake_web_tab(QUrl('https://github.com'), 'GitHub'),
        fake_web_tab(QUrl('https://wikipedia.org'), 'Wikipedia'),
        fake_web_tab(QUrl('https://duckduckgo.com'), 'DuckDuckGo'),
    ]
    tab_1_1 = fake_web_tab(QUrl('https://wiki.archlinux.org'), 'ArchWiki')
    tab_1_1.win_id = 1
    tabbed_browser_stubs[1].widget.tabs = [tab_1_1]
    model = miscmodels.buffer()
    model.set_pattern('')
    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')
        ],
        '1': [
            ('1/1', 'https://wiki.archlinux.org', 'ArchWiki'),
        ]
    })