示例#1
0
 def on_tab_changed(self, tab):
     """Update URL if the tab changed."""
     self._hover_url = None
     if tab.url().isValid():
         self._normal_url = urlutils.safe_display_string(tab.url())
     else:
         self._normal_url = ''
     self.on_load_status_changed(tab.load_status().name)
     self._update_url()
示例#2
0
 def on_tab_changed(self, tab):
     """Update URL if the tab changed."""
     self._hover_url = None
     if tab.url().isValid():
         self._normal_url = urlutils.safe_display_string(tab.url())
     else:
         self._normal_url = ''
     self.on_load_status_changed(tab.load_status().name)
     self._update_url()
示例#3
0
def test_on_tab_changed(url_widget, fake_web_tab, load_status, qurl):
    tab_widget = fake_web_tab(load_status=load_status, url=qurl)
    url_widget.on_tab_changed(tab_widget)

    assert url_widget._urltype.name == load_status.name
    if not qurl.isValid():
        expected = ''
    else:
        expected = urlutils.safe_display_string(qurl)
    assert url_widget.text() == expected
示例#4
0
def test_on_tab_changed(url_widget, fake_web_tab, load_status, qurl):
    tab_widget = fake_web_tab(load_status=load_status, url=qurl)
    url_widget.on_tab_changed(tab_widget)

    assert url_widget._urltype.name == load_status.name
    if not qurl.isValid():
        expected = ''
    else:
        expected = urlutils.safe_display_string(qurl)
    assert url_widget.text() == expected
示例#5
0
    def set_url(self, url):
        """Setter to be used as a Qt slot.

        Args:
            url: The URL to set as QUrl, or None.
        """
        if url is None:
            self._normal_url = None
        elif not url.isValid():
            self._normal_url = "Invalid URL!"
        else:
            self._normal_url = urlutils.safe_display_string(url)
        self._normal_url_type = UrlType.normal
        self._update_url()
示例#6
0
    def set_url(self, url):
        """Setter to be used as a Qt slot.

        Args:
            url: The URL to set as QUrl, or None.
        """
        if url is None:
            self._normal_url = None
        elif not url.isValid():
            self._normal_url = "Invalid URL!"
        else:
            self._normal_url = urlutils.safe_display_string(url)
        self._normal_url_type = UrlType.normal
        self._update_url()
示例#7
0
    def set_hover_url(self, link):
        """Setter to be used as a Qt slot.

        Saves old shown URL in self._old_url and restores it later if a link is
        "un-hovered" when it gets called with empty parameters.

        Args:
            link: The link which was hovered (string)
        """
        if link:
            qurl = QUrl(link)
            if qurl.isValid():
                self._hover_url = urlutils.safe_display_string(qurl)
            else:
                self._hover_url = '(invalid URL!) {}'.format(link)
        else:
            self._hover_url = None
        self._update_url()
示例#8
0
    def set_hover_url(self, link):
        """Setter to be used as a Qt slot.

        Saves old shown URL in self._old_url and restores it later if a link is
        "un-hovered" when it gets called with empty parameters.

        Args:
            link: The link which was hovered (string)
        """
        if link:
            qurl = QUrl(link)
            if qurl.isValid():
                self._hover_url = urlutils.safe_display_string(qurl)
            else:
                self._hover_url = '(invalid URL!) {}'.format(link)
        else:
            self._hover_url = None
        self._update_url()
示例#9
0
def test_safe_display_string_invalid():
    with pytest.raises(urlutils.InvalidUrlError):
        urlutils.safe_display_string(QUrl())
示例#10
0
def test_safe_display_string(url, expected):
    assert urlutils.safe_display_string(url) == expected
示例#11
0
def test_safe_display_string_invalid():
    with pytest.raises(urlutils.InvalidUrlError):
        urlutils.safe_display_string(QUrl())
示例#12
0
def test_safe_display_string(url, expected):
    assert urlutils.safe_display_string(url) == expected