Exemplo n.º 1
0
def download_stub(win_registry):
    """Register a FakeDownloadManager."""
    stub = FakeDownloadManager()
    objreg.register('download-manager', stub,
                    scope='window', window='last-focused')
    yield
    objreg.delete('download-manager', scope='window', window='last-focused')
Exemplo n.º 2
0
    def _remove_tab(self, tab):
        """Remove a tab from the tab list and delete it properly.

        Args:
            tab: The QWebView to be closed.
        """
        idx = self.indexOf(tab)
        if idx == -1:
            raise ValueError("tab {} is not contained in TabbedWidget!".format(
                tab))
        if tab is self._now_focused:
            self._now_focused = None
        if tab is objreg.get('last-focused-tab', None, scope='window',
                             window=self._win_id):
            objreg.delete('last-focused-tab', scope='window',
                          window=self._win_id)
        if tab.cur_url.isValid():
            history_data = qtutils.serialize(tab.history())
            entry = UndoEntry(tab.cur_url, history_data)
            self._undo_stack.append(entry)
        elif tab.cur_url.isEmpty():
            # There are some good reasons why an URL could be empty
            # (target="_blank" with a download, see [1]), so we silently ignore
            # this.
            # [1] https://github.com/The-Compiler/qutebrowser/issues/163
            pass
        else:
            # We display a warnings for URLs which are not empty but invalid -
            # but we don't return here because we want the tab to close either
            # way.
            urlutils.invalid_url_error(self._win_id, tab.cur_url, "saving tab")
        tab.shutdown()
        self.removeTab(idx)
        tab.deleteLater()
Exemplo n.º 3
0
    def _remove_tab(self, tab):
        """Remove a tab from the tab list and delete it properly.

        Args:
            tab: The QWebView to be closed.

        Raise:
            ValueError if the tab is not in the QTabWidget.
        """
        idx = self.indexOf(tab)
        if idx == -1:
            raise ValueError("tab {} is not contained in TabbedWidget!".format(
                tab))
        if tab is self._now_focused:
            self._now_focused = None
        if tab is objreg.get('last-focused-tab', None):
            objreg.delete('last-focused-tab')
        if not tab.cur_url.isEmpty():
            qtutils.ensure_valid(tab.cur_url)
            history_data = qtutils.serialize(tab.history())
            entry = UndoEntry(tab.cur_url, history_data)
            self._undo_stack.append(entry)
        tab.shutdown()
        self._tabs.remove(tab)
        self.removeTab(idx)
        tab.deleteLater()
Exemplo n.º 4
0
def fake_args(request):
    ns = types.SimpleNamespace()
    ns.backend = 'webengine' if request.config.webengine else 'webkit'
    ns.debug_flags = []
    objreg.register('args', ns)
    yield ns
    objreg.delete('args')
Exemplo n.º 5
0
def status_command_stub(stubs, qtbot, win_registry):
    """Fixture which provides a fake status-command object."""
    cmd = stubs.StatusBarCommandStub()
    objreg.register('status-command', cmd, scope='window', window=0)
    qtbot.addWidget(cmd)
    yield cmd
    objreg.delete('status-command', scope='window', window=0)
Exemplo n.º 6
0
def test_init(backend, qapp, tmpdir, monkeypatch, fake_save_manager,
              fake_args):
    if backend == 'webkit':
        pytest.importorskip('PyQt5.QtWebKitWidgets')

    fake_args.backend = backend
    monkeypatch.setattr(history.standarddir, 'data', lambda: str(tmpdir))
    history.init(qapp)
    hist = objreg.get('web-history')
    assert hist.parent() is qapp

    try:
        from PyQt5.QtWebKit import QWebHistoryInterface
    except ImportError:
        QWebHistoryInterface = None

    if backend == 'webkit':
        default_interface = QWebHistoryInterface.defaultInterface()
        assert default_interface._history is hist
    else:
        assert backend == 'webengine'
        if QWebHistoryInterface is None:
            default_interface = None
        else:
            default_interface = QWebHistoryInterface.defaultInterface()
        # For this to work, nothing can ever have called setDefaultInterface
        # before (so we need to test webengine before webkit)
        assert default_interface is None

    assert fake_save_manager.add_saveable.called
    objreg.delete('web-history')
Exemplo n.º 7
0
def fake_keyconfig():
    """Create a mock of a KeyConfiguration and register it into objreg."""
    fake_keyconfig = mock.Mock(spec=['get_bindings_for'])
    fake_keyconfig.get_bindings_for.side_effect = lambda s: BINDINGS[s]
    objreg.register('key-config', fake_keyconfig)
    yield
    objreg.delete('key-config')
Exemplo n.º 8
0
def default_config():
    """Fixture that provides and registers an empty default config object."""
    config_obj = config.ConfigManager()
    config_obj.read(configdir=None, fname=None, relaxed=True)
    objreg.register('config', config_obj)
    yield config_obj
    objreg.delete('config')
Exemplo n.º 9
0
def fake_keyconfig():
    """Create a mock of a KeyConfiguration and register it into objreg."""
    bindings = dict(BINDINGS)  # so the bindings can be changed later
    fake_keyconfig = mock.Mock(spec=['get_bindings_for'])
    fake_keyconfig.get_bindings_for.side_effect = lambda s: bindings[s]
    objreg.register('key-config', fake_keyconfig)
    yield bindings
    objreg.delete('key-config')
Exemplo n.º 10
0
def test_init(qapp, tmpdir, monkeypatch, fake_save_manager):
    monkeypatch.setattr(history.standarddir, 'data', lambda: str(tmpdir))
    history.init(qapp)
    hist = objreg.get('web-history')
    assert hist.parent() is qapp
    assert QWebHistoryInterface.defaultInterface()._history is hist
    assert fake_save_manager.add_saveable.called
    objreg.delete('web-history')
Exemplo n.º 11
0
def web_history(fake_save_manager, tmpdir, init_sql, config_stub, stubs):
    """Create a web history and register it into objreg."""
    config_stub.val.completion.timestamp_format = '%Y-%m-%d'
    config_stub.val.completion.web_history.max_items = -1
    web_history = history.WebHistory(stubs.FakeHistoryProgress())
    objreg.register('web-history', web_history)
    yield web_history
    objreg.delete('web-history')
Exemplo n.º 12
0
def web_history(init_sql, stubs, config_stub):
    """Fixture which provides a web-history object."""
    config_stub.val.completion.timestamp_format = '%Y-%m-%d'
    config_stub.val.completion.web_history_max_items = -1
    stub = history.WebHistory()
    objreg.register('web-history', stub)
    yield stub
    objreg.delete('web-history')
Exemplo n.º 13
0
def cookiejar_and_cache(stubs):
    """Fixture providing a fake cookie jar and cache."""
    jar = QNetworkCookieJar()
    cache = stubs.FakeNetworkCache()
    objreg.register('cookie-jar', jar)
    objreg.register('cache', cache)
    yield
    objreg.delete('cookie-jar')
    objreg.delete('cache')
Exemplo n.º 14
0
def tabbed_browser_stubs(stubs, win_registry):
    """Fixture providing a fake tabbed-browser object on win_id 0 and 1."""
    win_registry.add_window(1)
    stubs = [stubs.TabbedBrowserStub(), stubs.TabbedBrowserStub()]
    objreg.register('tabbed-browser', stubs[0], scope='window', window=0)
    objreg.register('tabbed-browser', stubs[1], scope='window', window=1)
    yield stubs
    objreg.delete('tabbed-browser', scope='window', window=0)
    objreg.delete('tabbed-browser', scope='window', window=1)
Exemplo n.º 15
0
    def setup(self, mocker, stubs):
        """Set up mocks and read the test config."""
        mocker.patch('qutebrowser.keyinput.basekeyparser.usertypes.Timer',
                     new=stubs.FakeTimer)
        mocker.patch('qutebrowser.keyinput.modeparsers.config',
                     new=stubs.ConfigStub(CONFIG))

        objreg.register('key-config', fake_keyconfig)
        self.kp = modeparsers.NormalKeyParser(0)
        self.kp.execute = mock.Mock()
        yield
        objreg.delete('key-config')
Exemplo n.º 16
0
 def _do_close(self):
     """Helper function for closeEvent."""
     try:
         last_visible = objreg.get('last-visible-main-window')
         if self is last_visible:
             objreg.delete('last-visible-main-window')
     except KeyError:
         pass
     objreg.get('session-manager').save_last_window_session()
     self._save_geometry()
     log.destroy.debug("Closing window {}".format(self.win_id))
     self.tabbed_browser.shutdown()
Exemplo n.º 17
0
def cleanup_init():
    # prevent test_init from leaking state
    yield
    hist = objreg.get('web-history', None)
    if hist is not None:
        hist.setParent(None)
        objreg.delete('web-history')
    try:
        from PyQt5.QtWebKit import QWebHistoryInterface
        QWebHistoryInterface.setDefaultInterface(None)
    except ImportError:
        pass
Exemplo n.º 18
0
    def _remove_tab(self, tab, *, add_undo=True, new_undo=True, crashed=False):
        """Remove a tab from the tab list and delete it properly.

        Args:
            tab: The QWebView to be closed.
            add_undo: Whether the tab close can be undone.
            new_undo: Whether the undo entry should be a new item in the stack.
            crashed: Whether we're closing a tab with crashed renderer process.
        """
        idx = self.widget.indexOf(tab)
        if idx == -1:
            if crashed:
                return
            raise TabDeletedError("tab {} is not contained in "
                                  "TabbedWidget!".format(tab))
        if tab is self._now_focused:
            self._now_focused = None
        if tab is objreg.get('last-focused-tab', None, scope='window',
                             window=self._win_id):
            objreg.delete('last-focused-tab', scope='window',
                          window=self._win_id)

        if tab.url().isEmpty():
            # There are some good reasons why a URL could be empty
            # (target="_blank" with a download, see [1]), so we silently ignore
            # this.
            # [1] https://github.com/qutebrowser/qutebrowser/issues/163
            pass
        elif not tab.url().isValid():
            # We display a warning for URLs which are not empty but invalid -
            # but we don't return here because we want the tab to close either
            # way.
            urlutils.invalid_url_error(tab.url(), "saving tab")
        elif add_undo:
            try:
                history_data = tab.history.serialize()
            except browsertab.WebTabError:
                pass  # special URL
            else:
                entry = UndoEntry(tab.url(), history_data, idx,
                                  tab.data.pinned)
                if new_undo or not self._undo_stack:
                    self._undo_stack.append([entry])
                else:
                    self._undo_stack[-1].append(entry)

        tab.shutdown()
        self.widget.removeTab(idx)
        if not crashed:
            # WORKAROUND for a segfault when we delete the crashed tab.
            # see https://bugreports.qt.io/browse/QTBUG-58698
            tab.layout().unwrap()
            tab.deleteLater()
Exemplo n.º 19
0
 def on_focus_changed(self, _old, new):
     """Register currently focused main window in the object registry."""
     if new is None:
         window = None
     else:
         window = new.window()
     if window is None or not isinstance(window, mainwindow.MainWindow):
         try:
             objreg.delete('last-focused-main-window')
         except KeyError:
             pass
     else:
         objreg.register('last-focused-main-window', window, update=True)
Exemplo n.º 20
0
def init_patch(qapp, fake_save_manager, monkeypatch, config_tmpdir,
               data_tmpdir):
    monkeypatch.setattr(configfiles, 'state', None)
    monkeypatch.setattr(config, 'instance', None)
    monkeypatch.setattr(config, 'key_instance', None)
    monkeypatch.setattr(config, 'change_filters', [])
    monkeypatch.setattr(configinit, '_init_errors', None)
    monkeypatch.setattr(configtypes.Font, 'monospace_fonts', None)
    yield
    try:
        objreg.delete('config-commands')
    except KeyError:
        pass
Exemplo n.º 21
0
 def patch(self, fake_args):
     objreg.register('app', QObject())
     objreg.register('save-manager', mock.MagicMock())
     fake_args.relaxed_config = False
     old_standarddir_args = standarddir._args
     yield
     objreg.delete('app')
     objreg.delete('save-manager')
     # registered by config.init()
     objreg.delete('config')
     objreg.delete('key-config')
     objreg.delete('state-config')
     standarddir._args = old_standarddir_args
Exemplo n.º 22
0
def fake_window(win_registry, stubs, monkeypatch, qtbot):
    """Fixture which provides a fake main windows with a tabbedbrowser."""
    win0 = FakeMainWindow(b'fake-geometry-0', win_id=0)
    objreg.register('main-window', win0, scope='window', window=0)

    webview = QWebView()
    qtbot.add_widget(webview)
    browser = stubs.TabbedBrowserStub([webview])
    objreg.register('tabbed-browser', browser, scope='window', window=0)

    yield

    objreg.delete('main-window', scope='window', window=0)
    objreg.delete('tabbed-browser', scope='window', window=0)
Exemplo n.º 23
0
def fake_windows(win_registry, stubs, monkeypatch, qtbot):
    """Fixture which provides two fake main windows and tabbedbrowsers."""
    win_registry.add_window(1)
    win0 = FakeMainWindow(b'fake-geometry-0', win_id=0)
    win1 = FakeMainWindow(b'fake-geometry-1', win_id=1)
    objreg.register('main-window', win0, scope='window', window=0)
    objreg.register('main-window', win1, scope='window', window=1)

    webview0 = QWebView()
    qtbot.add_widget(webview0)
    webview1 = QWebView()
    qtbot.add_widget(webview1)
    webview2 = QWebView()
    qtbot.add_widget(webview2)
    webview3 = QWebView()
    qtbot.add_widget(webview3)

    browser0 = FakeTabbedBrowser([webview0, webview1])
    browser1 = FakeTabbedBrowser([webview2, webview3])
    objreg.register('tabbed-browser', browser0, scope='window', window=0)
    objreg.register('tabbed-browser', browser1, scope='window', window=1)

    qapp = stubs.FakeQApplication(active_window=win0)
    monkeypatch.setattr('qutebrowser.misc.sessions.QApplication', qapp)

    yield browser0, browser1

    objreg.delete('main-window', scope='window', window=0)
    objreg.delete('main-window', scope='window', window=1)
    objreg.delete('tabbed-browser', scope='window', window=0)
    objreg.delete('tabbed-browser', scope='window', window=1)
Exemplo n.º 24
0
def on_focus_changed(_old, new):
    """Register currently focused main window in the object registry."""
    if new is None:
        window = None
    else:
        window = new.window()
    if window is None or not isinstance(window, mainwindow.MainWindow):
        try:
            objreg.delete('last-focused-main-window')
        except KeyError:
            pass
        qApp.restoreOverrideCursor()
    else:
        objreg.register('last-focused-main-window', window, update=True)
        _maybe_hide_mouse_cursor()
Exemplo n.º 25
0
def on_focus_changed(_old, new):
    """Register currently focused main window in the object registry."""
    if not isinstance(new, QWidget):
        log.misc.debug("on_focus_changed called with non-QWidget {!r}".format(
            new))

    if new is None or not isinstance(new, mainwindow.MainWindow):
        try:
            objreg.delete('last-focused-main-window')
        except KeyError:
            pass
        qApp.restoreOverrideCursor()
    else:
        objreg.register('last-focused-main-window', new.window(), update=True)
        _maybe_hide_mouse_cursor()
Exemplo n.º 26
0
def test_init(backend, qapp, tmpdir, monkeypatch, fake_save_manager,
              fake_args):
    fake_args.backend = backend
    monkeypatch.setattr(history.standarddir, 'data', lambda: str(tmpdir))
    history.init(qapp)
    hist = objreg.get('web-history')
    assert hist.parent() is qapp
    default_interface = QWebHistoryInterface.defaultInterface()

    if backend == 'webkit':
        assert default_interface._history is hist
    else:
        assert backend == 'webengine'
        # For this to work, nothing can ever have called setDefaultInterface
        # before (so we need to test webengine before webkit)
        assert default_interface is None

    assert fake_save_manager.add_saveable.called
    objreg.delete('web-history')
Exemplo n.º 27
0
def default_config():
    """
    Fixture that registers an empty config object into the objreg module.

    Should be used by tests which create widgets that obtain their initial
    state from the global config object.

    Note:

        If we declare this fixture like this:

            @pytest.yield_fixture(autouse=True)

        Then all tests below this file will have a default config registered
        and ready for use. Is that desirable?
    """
    config_obj = ConfigManager(configdir=None, fname=None, relaxed=True)
    objreg.register('config', config_obj)
    yield config_obj
    objreg.delete('config')
Exemplo n.º 28
0
    def fake_history(self, stubs, tabbed_browser_stubs, monkeypatch, webview):
        """Fixture which provides a window with a fake history."""
        win = FakeMainWindow(b'fake-geometry-0', win_id=0)
        objreg.register('main-window', win, scope='window', window=0)

        browser = tabbed_browser_stubs[0]
        qapp = stubs.FakeQApplication(active_window=win)
        monkeypatch.setattr(sessions, 'QApplication', qapp)

        def set_data(items):
            history = browser.widgets()[0].page().history()
            stream, _data, user_data = tabhistory.serialize(items)
            qtutils.deserialize_stream(stream, history)
            for i, data in enumerate(user_data):
                history.itemAt(i).setUserData(data)

        yield set_data

        objreg.delete('main-window', scope='window', window=0)
        objreg.delete('tabbed-browser', scope='window', window=0)
Exemplo n.º 29
0
    def fake_history(self, win_registry, stubs, monkeypatch, webview):
        """Fixture which provides a window with a fake history."""
        win = FakeMainWindow(b"fake-geometry-0", win_id=0)
        objreg.register("main-window", win, scope="window", window=0)
        browser = FakeTabbedBrowser([webview])

        objreg.register("tabbed-browser", browser, scope="window", window=0)
        qapp = stubs.FakeQApplication(active_window=win)
        monkeypatch.setattr("qutebrowser.misc.sessions.QApplication", qapp)

        def set_data(items):
            history = browser.widgets()[0].page().history()
            stream, _data, user_data = tabhistory.serialize(items)
            qtutils.deserialize_stream(stream, history)
            for i, data in enumerate(user_data):
                history.itemAt(i).setUserData(data)

        yield set_data

        objreg.delete("main-window", scope="window", window=0)
        objreg.delete("tabbed-browser", scope="window", window=0)
Exemplo n.º 30
0
def tab(request, default_config, qtbot, tab_registry, cookiejar_and_cache):
    if PYQT_VERSION < 0x050600:
        pytest.skip("Causes segfaults, see #1638")

    if request.param == "webkit":
        webkittab = pytest.importorskip("qutebrowser.browser.webkit.webkittab")
        tab_class = webkittab.WebKitTab
    elif request.param == "webengine":
        webenginetab = pytest.importorskip("qutebrowser.browser.webengine.webenginetab")
        tab_class = webenginetab.WebEngineTab
    else:
        assert False

    # Can't use the mode_manager fixture as that uses config_stub, which
    # conflicts with default_config
    mm = modeman.ModeManager(0)
    objreg.register("mode-manager", mm, scope="window", window=0)

    t = tab_class(win_id=0, mode_manager=mm)
    qtbot.add_widget(t)
    yield t

    objreg.delete("mode-manager", scope="window", window=0)
Exemplo n.º 31
0
def basedir():
    """Register a Fake basedir."""
    args = BaseDirStub()
    objreg.register('args', args)
    yield
    objreg.delete('args')
Exemplo n.º 32
0
def message_bridge(win_registry):
    """Fixture to get a MessageBridge."""
    bridge = message.MessageBridge()
    objreg.register('message-bridge', bridge, scope='window', window=0)
    yield bridge
    objreg.delete('message-bridge', scope='window', window=0)
Exemplo n.º 33
0
def host_blocker_stub(stubs):
    """Fixture which provides a fake host blocker object."""
    stub = stubs.HostBlockerStub()
    objreg.register('host-blocker', stub)
    yield stub
    objreg.delete('host-blocker')
Exemplo n.º 34
0
def download_stub(win_registry, tmpdir, stubs):
    """Register a FakeDownloadManager."""
    stub = stubs.FakeDownloadManager(tmpdir)
    objreg.register('qtnetwork-download-manager', stub)
    yield stub
    objreg.delete('qtnetwork-download-manager')
Exemplo n.º 35
0
def mode_manager(win_registry, config_stub, qapp):
    mm = modeman.ModeManager(0)
    objreg.register('mode-manager', mm, scope='window', window=0)
    yield mm
    objreg.delete('mode-manager', scope='window', window=0)
Exemplo n.º 36
0
def fake_args():
    ns = types.SimpleNamespace()
    objreg.register('args', ns)
    yield ns
    objreg.delete('args')
Exemplo n.º 37
0
 def tabbed_browser(self, win_registry):
     tb = FakeTabbedBrowser()
     objreg.register('tabbed-browser', tb, scope='window', window=0)
     yield tb
     objreg.delete('tabbed-browser', scope='window', window=0)
Exemplo n.º 38
0
def mode_manager(win_registry, config_stub, key_config_stub, qapp):
    mm = modeman.init(win_id=0, parent=qapp)
    yield mm
    objreg.delete('mode-manager', scope='window', window=0)
Exemplo n.º 39
0
def config_stub(stubs):
    """Fixture which provides a fake config object."""
    stub = stubs.ConfigStub()
    objreg.register('config', stub)
    yield stub
    objreg.delete('config')
Exemplo n.º 40
0
def greasemonkey_manager(data_tmpdir):
    gm_manager = greasemonkey.GreasemonkeyManager()
    objreg.register('greasemonkey', gm_manager)
    yield
    objreg.delete('greasemonkey')
Exemplo n.º 41
0
 def cleanup(self):
     yield
     objreg.delete('session-manager')
Exemplo n.º 42
0
def quickmark_manager_stub(stubs):
    """Fixture which provides a fake quickmark manager object."""
    stub = stubs.QuickmarkManagerStub()
    objreg.register('quickmark-manager', stub)
    yield stub
    objreg.delete('quickmark-manager')
Exemplo n.º 43
0
 def cleanup(self):
     try:
         objreg.delete('ipc-server')
     except KeyError:
         pass
Exemplo n.º 44
0
def tabbed_browser(stubs, win_registry):
    tb = stubs.TabbedBrowserStub()
    objreg.register('tabbed-browser', tb, scope='window', window=0)
    yield tb
    objreg.delete('tabbed-browser', scope='window', window=0)
Exemplo n.º 45
0
def fake_window(tabbed_browser_stubs):
    """Fixture which provides a fake main windows with a tabbedbrowser."""
    win0 = FakeMainWindow(b'fake-geometry-0', win_id=0)
    objreg.register('main-window', win0, scope='window', window=0)
    yield
    objreg.delete('main-window', scope='window', window=0)
Exemplo n.º 46
0
def default_config():
    """Fixture that provides and registers an empty default config object."""
    config_obj = config.ConfigManager(configdir=None, fname=None, relaxed=True)
    objreg.register('config', config_obj)
    yield config_obj
    objreg.delete('config')
Exemplo n.º 47
0
def mode_manager(win_registry, config_stub, qapp):
    config_stub.data.update({'input': {'forward-unbound-keys': 'auto'}})
    mm = modeman.ModeManager(0)
    objreg.register('mode-manager', mm, scope='window', window=0)
    yield mm
    objreg.delete('mode-manager', scope='window', window=0)
Exemplo n.º 48
0
    def _remove_tab(self, tab, *, add_undo=True, new_undo=True, crashed=False):
        """Remove a tab from the tab list and delete it properly.

        Args:
            tab: The QWebView to be closed.
            add_undo: Whether the tab close can be undone.
            new_undo: Whether the undo entry should be a new item in the stack.
            crashed: Whether we're closing a tab with crashed renderer process.
        """
        idx = self.indexOf(tab)
        if idx == -1:
            if crashed:
                return
            raise TabDeletedError("tab {} is not contained in "
                                  "TabbedWidget!".format(tab))
        if tab is self._now_focused:
            self._now_focused = None
        if tab is objreg.get(
                'last-focused-tab', None, scope='window', window=self._win_id):
            objreg.delete('last-focused-tab',
                          scope='window',
                          window=self._win_id)

        if tab.url().isEmpty():
            # There are some good reasons why a URL could be empty
            # (target="_blank" with a download, see [1]), so we silently ignore
            # this.
            # [1] https://github.com/qutebrowser/qutebrowser/issues/163
            pass
        elif not tab.url().isValid():
            # We display a warning for URLs which are not empty but invalid -
            # but we don't return here because we want the tab to close either
            # way.
            urlutils.invalid_url_error(tab.url(), "saving tab")
        elif add_undo:
            try:
                history_data = tab.history.serialize()
            except browsertab.WebTabError:
                pass  # special URL
            else:
                entry = UndoEntry(tab.url(), history_data, idx,
                                  tab.data.pinned)
                if new_undo or not self._undo_stack:
                    self._undo_stack.append([entry])
                else:
                    self._undo_stack[-1].append(entry)

        cur_node = tab.node

        node_parent = cur_node.parent

        if node_parent:

            node_siblings = list(node_parent.children)
            node_children = cur_node.children

            if node_children:
                next_node = node_children[0]

                # prvni node se stane parentem pro ostatní děti
                for n in node_children[1:]:
                    n.parent = next_node

                # swap nodes
                node_idx = node_siblings.index(cur_node)
                node_siblings[node_idx] = next_node

                node_parent.children = tuple(node_siblings)
                cur_node.children = tuple()

            cur_node.parent = None
        else:
            self.print_tree_tab_structure("!!! ERROR !!! Tab ID %s\n" %
                                          tab.tab_id)

        tab.shutdown()
        self.removeTab(idx)
        if not crashed:
            # WORKAROUND for a segfault when we delete the crashed tab.
            # see https://bugreports.qt.io/browse/QTBUG-58698
            tab.layout().unwrap()
            tab.deleteLater()
Exemplo n.º 49
0
def key_config_stub(stubs):
    """Fixture which provides a fake key config object."""
    stub = stubs.KeyConfigStub()
    objreg.register('key-config', stub)
    yield stub
    objreg.delete('key-config')
Exemplo n.º 50
0
 def fake_web_history(self, fake_save_manager, tmpdir, init_sql):
     """Create a fake web-history and register it into objreg."""
     web_history = history.WebHistory()
     objreg.register('web-history', web_history)
     yield web_history
     objreg.delete('web-history')
Exemplo n.º 51
0
def web_history_stub(stubs):
    """Fixture which provides a fake web-history object."""
    stub = stubs.WebHistoryStub()
    objreg.register('web-history', stub)
    yield stub
    objreg.delete('web-history')
Exemplo n.º 52
0
def session_manager_stub(stubs):
    """Fixture which provides a fake web-history object."""
    stub = stubs.SessionManagerStub()
    objreg.register('session-manager', stub)
    yield stub
    objreg.delete('session-manager')
Exemplo n.º 53
0
def app_stub(stubs):
    """Fixture which provides a fake app object."""
    stub = stubs.ApplicationStub()
    objreg.register('app', stub)
    yield stub
    objreg.delete('app')
def init_patch():
    yield
    objreg.delete('command-history')
Exemplo n.º 55
0
def fake_save_manager():
    """Create a mock of save-manager and register it into objreg."""
    fake_save_manager = unittest.mock.Mock(spec=savemanager.SaveManager)
    objreg.register('save-manager', fake_save_manager)
    yield fake_save_manager
    objreg.delete('save-manager')
Exemplo n.º 56
0
 def tearDown(self):
     objreg.delete('key-config')
Exemplo n.º 57
0
def tab_registry(win_registry):
    """Fixture providing a tab registry for win_id 0."""
    registry = objreg.ObjectRegistry()
    objreg.register('tab-registry', registry, scope='window', window=0)
    yield registry
    objreg.delete('tab-registry', scope='window', window=0)
Exemplo n.º 58
0
def fake_args(request):
    ns = types.SimpleNamespace()
    ns.backend = 'webengine' if request.config.webengine else 'webkit'
    objreg.register('args', ns)
    yield ns
    objreg.delete('args')
Exemplo n.º 59
0
 def state_config(self):
     state = {'general': {}}
     objreg.register('state-config', state)
     yield state
     objreg.delete('state-config')