def test_two_active_items():
    """Check tabhistory.serialize with two active items."""
    items = [Item(QUrl(), '', active=True),
             Item(QUrl(), ''),
             Item(QUrl(), '', active=True)]
    with pytest.raises(ValueError):
        tabhistory.serialize(items)
예제 #2
0
def test_two_active_items():
    """Check tabhistory.serialize with two active items."""
    items = [Item(QUrl(), '', active=True),
             Item(QUrl(), ''),
             Item(QUrl(), '', active=True)]
    with pytest.raises(ValueError):
        tabhistory.serialize(items)
예제 #3
0
    def setup(self, webpage):
        self.page = webpage
        self.history = self.page.history()
        assert self.history.count() == 0

        stream, _data, self.user_data = tabhistory.serialize(self.ITEMS)
        qtutils.deserialize_stream(stream, self.history)
예제 #4
0
    def setup(self, webpage):
        self.page = webpage
        self.history = self.page.history()
        assert self.history.count() == 0

        stream, _data, self.user_data = tabhistory.serialize(self.ITEMS)
        qtutils.deserialize_stream(stream, self.history)
예제 #5
0
 def _set_data(self, browser, tab_id, items):
     """Helper function for test_long_output."""
     history = browser.widgets()[tab_id].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)
예제 #6
0
    def setUp(self):
        self.page = helpers.get_webpage()
        self.history = self.page.history()
        self.assertEqual(self.history.count(), 0)

        self.items = [
            Item(QUrl('https://www.heise.de/'), QUrl('http://www.heise.de/'),
                 'heise'),
            Item(QUrl('http://example.com/%E2%80%A6'),
                 QUrl('http://example.com/%E2%80%A6'), 'percent', active=True),
            Item(QUrl('http://example.com/?foo=bar'),
                 QUrl('http://original.url.example.com/'), 'arg',
                 user_data={'foo': 23, 'bar': 42}),
            # From https://github.com/OtterBrowser/otter-browser/issues/709#issuecomment-74749471
            Item(QUrl('http://github.com/OtterBrowser/24/134/2344/otter-browser/issues/709/'),
                 QUrl('http://github.com/OtterBrowser/24/134/2344/otter-browser/issues/709/'),
                 'Page not found | github',
                 user_data={'zoom': 149, 'scroll-pos': QPoint(0, 0)}),
            Item(QUrl('https://mail.google.com/mail/u/0/#label/some+label/234lkjsd0932lkjf884jqwerdf4'),
                 QUrl('https://mail.google.com/mail/u/0/#label/some+label/234lkjsd0932lkjf884jqwerdf4'),
                 '"some label" - [email protected] - Gmail"',
                 user_data={'zoom': 120, 'scroll-pos': QPoint(0, 0)}),
        ]
        stream, _data, self.user_data = tabhistory.serialize(self.items)
        qtutils.deserialize_stream(stream, self.history)
예제 #7
0
 def _set_data(self, browser, tab_id, items):
     """Helper function for test_long_output."""
     history = browser.widgets()[tab_id].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)
예제 #8
0
 def test_empty(self):
     """Check tabhistory.serialize with no items."""
     items = []
     stream, _data, user_data = tabhistory.serialize(items)
     qtutils.deserialize_stream(stream, self.history)
     self.assertEqual(self.history.count(), 0)
     self.assertEqual(self.history.currentItemIndex(), 0)
     self.assertFalse(user_data)
def test_empty(empty_history):
    """Check tabhistory.serialize with no items."""
    items = []
    stream, _data, user_data = tabhistory.serialize(items)
    qtutils.deserialize_stream(stream, empty_history)
    assert empty_history.count() == 0
    assert empty_history.currentItemIndex() == 0
    assert not user_data
예제 #10
0
def test_empty(empty_history):
    """Check tabhistory.serialize with no items."""
    items = []
    stream, _data, user_data = tabhistory.serialize(items)
    qtutils.deserialize_stream(stream, empty_history)
    assert empty_history.count() == 0
    assert empty_history.currentItemIndex() == 0
    assert not user_data
예제 #11
0
 def load_history(self, entries):
     """Load the history from a list of TabHistoryItem objects."""
     stream, _data, user_data = tabhistory.serialize(entries)
     history = self.history()
     qtutils.deserialize_stream(stream, history)
     for i, data in enumerate(user_data):
         history.itemAt(i).setUserData(data)
     cur_data = history.currentItem().userData()
     if cur_data is not None:
         frame = self.mainFrame()
         if 'zoom' in cur_data:
             frame.page().view().zoom_perc(cur_data['zoom'] * 100)
         if ('scroll-pos' in cur_data and
                 frame.scrollPosition() == QPoint(0, 0)):
             QTimer.singleShot(0, functools.partial(
                 frame.setScrollPosition, cur_data['scroll-pos']))
예제 #12
0
 def load_history(self, entries):
     """Load the history from a list of TabHistoryItem objects."""
     stream, _data, user_data = tabhistory.serialize(entries)
     history = self.history()
     qtutils.deserialize_stream(stream, history)
     for i, data in enumerate(user_data):
         history.itemAt(i).setUserData(data)
     cur_data = history.currentItem().userData()
     if cur_data is not None:
         frame = self.mainFrame()
         if 'zoom' in cur_data:
             frame.page().view().zoom_perc(cur_data['zoom'] * 100)
         if ('scroll-pos' in cur_data and
                 frame.scrollPosition() == QPoint(0, 0)):
             QTimer.singleShot(0, functools.partial(
                 frame.setScrollPosition, cur_data['scroll-pos']))
예제 #13
0
    def get(self, items):
        """Get the serialized history for the given items.

        Args:
            items: A list of TabHistoryItems.

        Return:
            A list of serialized items, as dicts.
        """
        history = self.webview.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)

        d = self.sess_man._save_tab(self.webview, active=True)
        new_history = d['history']
        assert len(new_history) == len(items)
        return new_history
예제 #14
0
    def get(self, items):
        """Get the serialized history for the given items.

        Args:
            items: A list of TabHistoryItems.

        Return:
            A list of serialized items, as dicts.
        """
        history = self.webview.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)

        d = self.sess_man._save_tab(self.webview, active=True)
        new_history = d['history']
        assert len(new_history) == len(items)
        return new_history
예제 #15
0
def test_no_active_item():
    """Check tabhistory.serialize with no active item."""
    items = [Item(QUrl(), '')]
    with pytest.raises(ValueError):
        tabhistory.serialize(items)
예제 #16
0
 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)
예제 #17
0
def objects(empty_history):
    """Fixture providing a history (and userdata) filled with example data."""
    stream, _data, user_data = tabhistory.serialize(ITEMS)
    qtutils.deserialize_stream(stream, empty_history)
    return Objects(history=empty_history, user_data=user_data)
예제 #18
0
 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)
예제 #19
0
def objects(empty_history):
    """Fixture providing a history (and userdata) filled with example data."""
    stream, _data, user_data = tabhistory.serialize(ITEMS)
    qtutils.deserialize_stream(stream, empty_history)
    return Objects(history=empty_history, user_data=user_data)
예제 #20
0
 def test_no_active_item(self):
     """Check tabhistory.serialize with no active item."""
     items = [Item(QUrl(), QUrl(), '')]
     with self.assertRaises(ValueError):
         tabhistory.serialize(items)
예제 #21
0
def test_no_active_item():
    """Check tabhistory.serialize with no active item."""
    items = [Item(QUrl(), '')]
    with pytest.raises(ValueError):
        tabhistory.serialize(items)