Skip to content

Commit

Permalink
Issue #2437 - Adds tests for rendering wrt addons
Browse files Browse the repository at this point in the history
This does two things:
- Adds unittest tests to check that the right partial template for addons is sent depending on the user agent string.
- Adds a test for an unknown browser
- Fixes the template for addon where some white spaces where left over here and there.
- Removes the previous weaker functional tests which was very dependent on the testing browser.

It was triggered by the upgrade of ua-parser in python which took into account the headlesschrome user agent string, then not detected by our template. It was making the functional test fail.
See #2444 for the background.
  • Loading branch information
karlcow committed May 10, 2018
1 parent fd8c65e commit c9c4f76
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
10 changes: 0 additions & 10 deletions tests/functional/index-non-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ registerSuite("Index", {
.end();
},

"reporter addon link is shown"() {
return FunctionalHelpers.openPage(this, url("/"), ".js-hero-title")
.findByCssSelector(".js-addon-link")
.getVisibleText()
.then(function(text) {
assert.include(text, "Download");
})
.end();
},

"form toggles open then closed"() {
return (
FunctionalHelpers.openPage(this, url("/"), ".js-hero-title")
Expand Down
49 changes: 47 additions & 2 deletions tests/unit/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

# Any request that depends on parsing HTTP Headers (basically anything
# on the index route, will need to include the following: environ_base=headers
headers = {'HTTP_USER_AGENT': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; '
'rv:31.0) Gecko/20100101 Firefox/31.0')}
CHROME_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3425.0 Safari/537.36' # noqa
FIREFOX_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0' # noqa
FIREFOX_AND_UA = 'Mozilla/5.0 (Android; Mobile; rv:61.0) Gecko/61.0 Firefox/61.0' # noqa
SAFARI_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.2 Safari/605.1.15' # noqa
OPERA_UA = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.100' # noqa
headers = {'HTTP_USER_AGENT': FIREFOX_UA}


class TestURIContent(unittest.TestCase):
Expand Down Expand Up @@ -69,5 +73,46 @@ def test_user_title_pages(self):
rv = self.app.get('/activity/testuser')
self.assertTrue(title in rv.data)

def test_addon_link(self):
"""An addon link should be in the top navigation bar.
This depends on the user agent string.
"""

# testing Firefox addon
headers = {'HTTP_USER_AGENT': FIREFOX_UA}
rv = self.app.get('/', environ_base=headers)
expected = '<span class="link-text">Download Firefox Add-on</span>'
expected2 = '<use xlink:href="#svg-download2">Firefox addons</use>'
self.assertTrue(expected in rv.data)
self.assertTrue(expected2 in rv.data)
# testing for Firefox Androidpe
headers = {'HTTP_USER_AGENT': FIREFOX_AND_UA}
rv = self.app.get('/', environ_base=headers)
expected = '<span class="link-text">Download Firefox Add-on</span>'
expected2 = '<use xlink:href="#svg-download2">Firefox for Android addons</use>' # noqa
self.assertTrue(expected in rv.data)
self.assertTrue(expected2 in rv.data)
# testing for Chrome
headers = {'HTTP_USER_AGENT': CHROME_UA}
rv = self.app.get('/', environ_base=headers)
expected = '<span class="link-text">Download Chrome Add-on</span>'
expected2 = '<use xlink:href="#svg-download2">Chrome webstore</use>'
self.assertTrue(expected in rv.data)
self.assertTrue(expected2 in rv.data)
# testing for Opera
headers = {'HTTP_USER_AGENT': OPERA_UA}
rv = self.app.get('/', environ_base=headers)
expected = '<span class="link-text">Download Opera Add-on</span>'
expected2 = '<use xlink:href="#svg-download2">Opera Extension</use>'
self.assertTrue(expected in rv.data)
self.assertTrue(expected2 in rv.data)
# testing for unknown browser
headers = {'HTTP_USER_AGENT': 'Punk Cat Space'}
rv = self.app.get('/', environ_base=headers)
expected = '<span class="link-text">Give Feedback</span>'
self.assertTrue(expected in rv.data)


if __name__ == '__main__':
unittest.main()
6 changes: 3 additions & 3 deletions webcompat/templates/nav/addon-links.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<a class="nav-link js-addon-link" href="https://addons.mozilla.org/en-US/android/addon/webcompatcom-mobile-reporter/"
title="Navigate to firefox addon store">
<svg class="icon nav-icon" viewBox="0 0 30 30" role="presentation">
<title> Firefox for Android addons</title>
<use xlink:href="#svg-download2"> Firefox for Android addons</use>
<title>Firefox for Android addons</title>
<use xlink:href="#svg-download2">Firefox for Android addons</use>
</svg>
<span class="link-text">Download Firefox Add-on</span>
</a>
Expand All @@ -38,7 +38,7 @@
title="Navigate to opera addons">
<svg class="icon nav-icon" viewBox="0 0 30 30" role="presentation">
<title>Opera Extension</title>
<use xlink:href="#svg-download2"> Opera Extension</use>
<use xlink:href="#svg-download2">Opera Extension</use>
</svg>
<span class="link-text">Download Opera Add-on</span>
</a>
Expand Down

0 comments on commit c9c4f76

Please sign in to comment.