diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/firefox-ui/tests/functional | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/firefox-ui/tests/functional')
28 files changed, 1754 insertions, 0 deletions
diff --git a/testing/firefox-ui/tests/functional/keyboard_shortcuts/manifest.ini b/testing/firefox-ui/tests/functional/keyboard_shortcuts/manifest.ini new file mode 100644 index 000000000..97ec827f1 --- /dev/null +++ b/testing/firefox-ui/tests/functional/keyboard_shortcuts/manifest.ini @@ -0,0 +1,4 @@ +[DEFAULT] +tags = local + +[test_browser_window.py] diff --git a/testing/firefox-ui/tests/functional/keyboard_shortcuts/test_browser_window.py b/testing/firefox-ui/tests/functional/keyboard_shortcuts/test_browser_window.py new file mode 100644 index 000000000..5b656d0e5 --- /dev/null +++ b/testing/firefox-ui/tests/functional/keyboard_shortcuts/test_browser_window.py @@ -0,0 +1,56 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase + + +class TestBrowserWindowShortcuts(PuppeteerMixin, MarionetteTestCase): + + def test_addons_manager(self): + # If an about:xyz page is visible, no new tab will be opened + with self.marionette.using_context('content'): + self.marionette.navigate('about:') + + # TODO: To be moved to the upcoming add-ons library + def opener(tab): + tab.window.send_shortcut(tab.window.localize_entity('addons.commandkey'), + accel=True, shift=True) + self.browser.tabbar.open_tab(opener) + + # TODO: Marionette currently fails to detect the correct tab + # with self.marionette.using_content('content'): + # self.wait_for_condition(lambda mn: mn.get_url() == "about:addons") + + # TODO: remove extra switch once it is done automatically + self.browser.tabbar.tabs[1].switch_to() + self.browser.tabbar.close_tab() + + def test_search_field(self): + current_name = self.marionette.execute_script(""" + return window.document.activeElement.localName; + """) + + # This doesn't test anything if we're already at input. + self.assertNotEqual(current_name, "input") + + # TODO: To be moved to the upcoming search library + if self.puppeteer.platform == 'linux': + key = 'searchFocusUnix.commandkey' + else: + key = 'searchFocus.commandkey' + self.browser.send_shortcut(self.browser.localize_entity(key), + accel=True) + + # TODO: Check that the right input box is focused + # Located below searchbar as class="autocomplete-textbox textbox-input" + # Anon locator has not been released yet (bug 1080764) + def has_input_selected(mn): + selection_name = mn.execute_script(""" + return window.document.activeElement.localName; + """) + return selection_name == "input" + + Wait(self.marionette).until(has_input_selected) diff --git a/testing/firefox-ui/tests/functional/locationbar/manifest.ini b/testing/firefox-ui/tests/functional/locationbar/manifest.ini new file mode 100644 index 000000000..72adfd767 --- /dev/null +++ b/testing/firefox-ui/tests/functional/locationbar/manifest.ini @@ -0,0 +1,9 @@ +[DEFAULT] +tags = local + +[test_access_locationbar.py] +disabled = Bug 1168727 - Timeout when opening auto-complete popup +[test_escape_autocomplete.py] +[test_favicon_in_autocomplete.py] +[test_suggest_bookmarks.py] + diff --git a/testing/firefox-ui/tests/functional/locationbar/test_access_locationbar.py b/testing/firefox-ui/tests/functional/locationbar/test_access_locationbar.py new file mode 100644 index 000000000..160a402c2 --- /dev/null +++ b/testing/firefox-ui/tests/functional/locationbar/test_access_locationbar.py @@ -0,0 +1,60 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase + + +class TestAccessLocationBar(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestAccessLocationBar, self).setUp() + + # Clear complete history so there's no interference from previous entries. + self.puppeteer.places.remove_all_history() + + self.test_urls = [ + 'layout/mozilla_projects.html', + 'layout/mozilla.html', + 'layout/mozilla_mission.html' + ] + self.test_urls = [self.marionette.absolute_url(t) + for t in self.test_urls] + + self.locationbar = self.browser.navbar.locationbar + self.autocomplete_results = self.locationbar.autocomplete_results + self.urlbar = self.locationbar.urlbar + + def test_access_locationbar_history(self): + + # Open some local pages, then about:blank + def load_urls(): + with self.marionette.using_context('content'): + for url in self.test_urls: + self.marionette.navigate(url) + self.puppeteer.places.wait_for_visited(self.test_urls, load_urls) + with self.marionette.using_context('content'): + self.marionette.navigate('about:blank') + + # Need to blur url bar or autocomplete won't load - bug 1038614 + self.marionette.execute_script("""arguments[0].blur();""", script_args=[self.urlbar]) + + # Clear contents of url bar to focus, then arrow down for list of visited sites + # Verify that autocomplete is open and results are displayed + self.locationbar.clear() + self.urlbar.send_keys(self.puppeteer.keys.ARROW_DOWN) + Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open) + Wait(self.marionette).until(lambda _: len(self.autocomplete_results.visible_results) > 1) + + # Arrow down again to select first item in list, appearing in reversed order, as loaded. + # Verify first item. + self.urlbar.send_keys(self.puppeteer.keys.ARROW_DOWN) + Wait(self.marionette).until(lambda _: self.autocomplete_results.selected_index == '0') + self.assertIn('mission', self.locationbar.value) + + # Navigate to the currently selected url + # Verify it loads by comparing the page url to the test url + self.urlbar.send_keys(self.puppeteer.keys.ENTER) + self.assertEqual(self.locationbar.value, self.test_urls[-1]) diff --git a/testing/firefox-ui/tests/functional/locationbar/test_escape_autocomplete.py b/testing/firefox-ui/tests/functional/locationbar/test_escape_autocomplete.py new file mode 100644 index 000000000..209d9b0f5 --- /dev/null +++ b/testing/firefox-ui/tests/functional/locationbar/test_escape_autocomplete.py @@ -0,0 +1,56 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase + + +class TestEscapeAutocomplete(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestEscapeAutocomplete, self).setUp() + + # Clear complete history so there's no interference from previous entries. + self.puppeteer.places.remove_all_history() + + self.test_urls = [ + 'layout/mozilla.html', + 'layout/mozilla_community.html', + ] + self.test_urls = [self.marionette.absolute_url(t) + for t in self.test_urls] + + self.test_string = 'mozilla' + + self.locationbar = self.browser.navbar.locationbar + self.autocomplete_results = self.locationbar.autocomplete_results + + def tearDown(self): + self.autocomplete_results.close(force=True) + + super(TestEscapeAutocomplete, self).tearDown() + + def test_escape_autocomplete(self): + # Open some local pages + def load_urls(): + with self.marionette.using_context('content'): + for url in self.test_urls: + self.marionette.navigate(url) + self.puppeteer.places.wait_for_visited(self.test_urls, load_urls) + + # Clear the location bar, type the test string, check that autocomplete list opens + self.locationbar.clear() + self.locationbar.urlbar.send_keys(self.test_string) + self.assertEqual(self.locationbar.value, self.test_string) + Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open) + + # Press escape, check location bar value, check autocomplete list closed + self.locationbar.urlbar.send_keys(self.puppeteer.keys.ESCAPE) + self.assertEqual(self.locationbar.value, self.test_string) + Wait(self.marionette).until(lambda _: not self.autocomplete_results.is_open) + + # Press escape again and check that locationbar returns to the page url + self.locationbar.urlbar.send_keys(self.puppeteer.keys.ESCAPE) + self.assertEqual(self.locationbar.value, self.test_urls[-1]) diff --git a/testing/firefox-ui/tests/functional/locationbar/test_favicon_in_autocomplete.py b/testing/firefox-ui/tests/functional/locationbar/test_favicon_in_autocomplete.py new file mode 100644 index 000000000..6e8a5f6b1 --- /dev/null +++ b/testing/firefox-ui/tests/functional/locationbar/test_favicon_in_autocomplete.py @@ -0,0 +1,62 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase + + +class TestFaviconInAutocomplete(PuppeteerMixin, MarionetteTestCase): + + PREF_SUGGEST_SEARCHES = 'browser.urlbar.suggest.searches' + PREF_SUGGEST_BOOKMARK = 'browser.urlbar.suggest.bookmark' + + def setUp(self): + super(TestFaviconInAutocomplete, self).setUp() + + # Disable suggestions for searches and bookmarks to get results only for history + self.marionette.set_pref(self.PREF_SUGGEST_SEARCHES, False) + self.marionette.set_pref(self.PREF_SUGGEST_BOOKMARK, False) + + self.puppeteer.places.remove_all_history() + + self.test_urls = [self.marionette.absolute_url('layout/mozilla.html')] + + self.test_string = 'mozilla' + self.test_favicon = 'mozilla_favicon.ico' + + self.autocomplete_results = self.browser.navbar.locationbar.autocomplete_results + + def tearDown(self): + try: + self.autocomplete_results.close(force=True) + self.marionette.clear_pref(self.PREF_SUGGEST_SEARCHES) + self.marionette.clear_pref(self.PREF_SUGGEST_BOOKMARK) + finally: + super(TestFaviconInAutocomplete, self).tearDown() + + def test_favicon_in_autocomplete(self): + # Open the test page + def load_urls(): + with self.marionette.using_context('content'): + self.marionette.navigate(self.test_urls[0]) + self.puppeteer.places.wait_for_visited(self.test_urls, load_urls) + + locationbar = self.browser.navbar.locationbar + + # Clear the location bar, type the test string, check that autocomplete list opens + locationbar.clear() + locationbar.urlbar.send_keys(self.test_string) + self.assertEqual(locationbar.value, self.test_string) + Wait(self.marionette).until(lambda _: self.autocomplete_results.is_complete) + + result = self.autocomplete_results.visible_results[1] + + result_icon = self.marionette.execute_script(""" + return arguments[0].image; + """, script_args=[result]) + + self.assertIn(self.test_favicon, result_icon) + + self.autocomplete_results.close() diff --git a/testing/firefox-ui/tests/functional/locationbar/test_suggest_bookmarks.py b/testing/firefox-ui/tests/functional/locationbar/test_suggest_bookmarks.py new file mode 100644 index 000000000..9abc2d6cb --- /dev/null +++ b/testing/firefox-ui/tests/functional/locationbar/test_suggest_bookmarks.py @@ -0,0 +1,96 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import By, Wait +from marionette_harness import MarionetteTestCase + + +class TestStarInAutocomplete(PuppeteerMixin, MarionetteTestCase): + """ This replaces + http://hg.mozilla.org/qa/mozmill-tests/file/default/firefox/tests/functional/testAwesomeBar/testSuggestBookmarks.js + Check a star appears in autocomplete list for a bookmarked page. + """ + + PREF_SUGGEST_SEARCHES = 'browser.urlbar.suggest.searches' + + def setUp(self): + super(TestStarInAutocomplete, self).setUp() + + self.bookmark_panel = None + self.test_urls = [self.marionette.absolute_url('layout/mozilla_grants.html')] + + # Disable search suggestions to only get results for history and bookmarks + self.marionette.set_pref(self.PREF_SUGGEST_SEARCHES, False) + + with self.marionette.using_context('content'): + self.marionette.navigate('about:blank') + + self.puppeteer.places.remove_all_history() + + def tearDown(self): + # Close the autocomplete results + try: + if self.bookmark_panel: + self.marionette.execute_script(""" + arguments[0].hidePopup(); + """, script_args=[self.bookmark_panel]) + + self.browser.navbar.locationbar.autocomplete_results.close() + self.puppeteer.places.restore_default_bookmarks() + self.marionette.clear_pref(self.PREF_SUGGEST_SEARCHES) + finally: + super(TestStarInAutocomplete, self).tearDown() + + def test_star_in_autocomplete(self): + search_string = 'grants' + + def visit_urls(): + with self.marionette.using_context('content'): + for url in self.test_urls: + self.marionette.navigate(url) + + # Navigate to all the urls specified in self.test_urls and wait for them to + # be registered as visited + self.puppeteer.places.wait_for_visited(self.test_urls, visit_urls) + + # Bookmark the current page using the bookmark menu + self.browser.menubar.select_by_id('bookmarksMenu', + 'menu_bookmarkThisPage') + + # TODO: Replace hard-coded selector with library method when one is available + self.bookmark_panel = self.marionette.find_element(By.ID, 'editBookmarkPanel') + done_button = self.marionette.find_element(By.ID, 'editBookmarkPanelDoneButton') + + Wait(self.marionette).until( + lambda mn: self.bookmark_panel.get_attribute('panelopen') == 'true') + done_button.click() + + # We must open the blank page so the autocomplete result isn't "Switch to tab" + with self.marionette.using_context('content'): + self.marionette.navigate('about:blank') + + self.puppeteer.places.remove_all_history() + + # Focus the locationbar, delete any contents there, and type the search string + locationbar = self.browser.navbar.locationbar + locationbar.clear() + locationbar.urlbar.send_keys(search_string) + autocomplete_results = locationbar.autocomplete_results + + # Wait for the search string to be present, for the autocomplete results to appear + # and for there to be exactly one autocomplete result + Wait(self.marionette).until(lambda mn: locationbar.value == search_string) + Wait(self.marionette).until(lambda mn: autocomplete_results.is_complete) + Wait(self.marionette).until(lambda mn: len(autocomplete_results.visible_results) == 2) + + # Compare the highlighted text in the autocomplete result to the search string + first_result = autocomplete_results.visible_results[1] + matching_titles = autocomplete_results.get_matching_text(first_result, 'title') + for title in matching_titles: + Wait(self.marionette).until(lambda mn: title.lower() == search_string) + + self.assertIn('bookmark', + first_result.get_attribute('type'), + 'The auto-complete result is a bookmark') diff --git a/testing/firefox-ui/tests/functional/manifest.ini b/testing/firefox-ui/tests/functional/manifest.ini new file mode 100644 index 000000000..bc254e962 --- /dev/null +++ b/testing/firefox-ui/tests/functional/manifest.ini @@ -0,0 +1,5 @@ +[include:keyboard_shortcuts/manifest.ini] +[include:locationbar/manifest.ini] +[include:private_browsing/manifest.ini] +[include:security/manifest.ini] +[include:sessionstore/manifest.ini] diff --git a/testing/firefox-ui/tests/functional/private_browsing/manifest.ini b/testing/firefox-ui/tests/functional/private_browsing/manifest.ini new file mode 100644 index 000000000..405753082 --- /dev/null +++ b/testing/firefox-ui/tests/functional/private_browsing/manifest.ini @@ -0,0 +1,4 @@ +[DEFAULT] +tags = local + +[test_about_private_browsing.py]
\ No newline at end of file diff --git a/testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py b/testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py new file mode 100644 index 000000000..4b22d03ea --- /dev/null +++ b/testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py @@ -0,0 +1,60 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from firefox_puppeteer.ui.browser.window import BrowserWindow +from marionette_driver import By, Wait +from marionette_harness import MarionetteTestCase + + +class TestAboutPrivateBrowsing(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestAboutPrivateBrowsing, self).setUp() + + # Use a fake local support URL + support_url = 'about:blank?' + self.marionette.set_pref('app.support.baseURL', support_url) + + self.pb_url = support_url + 'private-browsing' + + def tearDown(self): + try: + self.marionette.clear_pref('app.support.baseURL') + finally: + super(TestAboutPrivateBrowsing, self).tearDown() + + def testCheckAboutPrivateBrowsing(self): + self.assertFalse(self.browser.is_private) + + with self.marionette.using_context('content'): + self.marionette.navigate('about:privatebrowsing') + + status_node = self.marionette.find_element(By.CSS_SELECTOR, 'p.showNormal') + self.assertEqual(status_node.text, + self.browser.localize_entity('aboutPrivateBrowsing.notPrivate'), + 'Status text indicates we are not in private browsing mode') + + def window_opener(win): + with win.marionette.using_context('content'): + button = self.marionette.find_element(By.ID, 'startPrivateBrowsing') + button.click() + + pb_window = self.browser.open_window(callback=window_opener, + expected_window_class=BrowserWindow) + + try: + self.assertTrue(pb_window.is_private) + + def tab_opener(tab): + with tab.marionette.using_context('content'): + link = tab.marionette.find_element(By.ID, 'learnMore') + link.click() + + tab = pb_window.tabbar.open_tab(trigger=tab_opener) + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + lambda _: tab.location == self.pb_url) + + finally: + pb_window.close() diff --git a/testing/firefox-ui/tests/functional/security/manifest.ini b/testing/firefox-ui/tests/functional/security/manifest.ini new file mode 100644 index 000000000..46aeaf5c3 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/manifest.ini @@ -0,0 +1,22 @@ +[DEFAULT] +tags = remote + +[test_dv_certificate.py] +[test_enable_privilege.py] +tags = local +[test_ev_certificate.py] +skip-if = true # Bug 1407663 +[test_mixed_content_page.py] +[test_mixed_script_content_blocking.py] +[test_no_certificate.py] +tags = local +[test_safe_browsing_initial_download.py] +[test_safe_browsing_notification.py] +[test_safe_browsing_warning_pages.py] +[test_security_notification.py] +[test_ssl_disabled_error_page.py] +[test_ssl_status_after_restart.py] +skip-if = (os == "win" && os_version == "5.1") # Bug 1167179: Fails to open popups after restart +[test_submit_unencrypted_info_warning.py] +[test_unknown_issuer.py] +[test_untrusted_connection_error_page.py] diff --git a/testing/firefox-ui/tests/functional/security/test_dv_certificate.py b/testing/firefox-ui/tests/functional/security/test_dv_certificate.py new file mode 100644 index 000000000..565f64996 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_dv_certificate.py @@ -0,0 +1,85 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase + + +class TestDVCertificate(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestDVCertificate, self).setUp() + + self.locationbar = self.browser.navbar.locationbar + self.identity_popup = self.browser.navbar.locationbar.identity_popup + + self.url = 'https://ssl-dv.mozqa.com' + + def tearDown(self): + try: + self.browser.switch_to() + self.identity_popup.close(force=True) + self.puppeteer.windows.close_all([self.browser]) + finally: + super(TestDVCertificate, self).tearDown() + + def test_dv_cert(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + self.assertEqual(self.locationbar.identity_box.get_property('className'), + 'verifiedDomain') + + # Open the identity popup + self.locationbar.open_identity_popup() + + # Check the identity popup doorhanger + self.assertEqual(self.identity_popup.element.get_attribute('connection'), 'secure') + + cert = self.browser.tabbar.selected_tab.certificate + + # The shown host equals to the certificate + self.assertEqual(self.identity_popup.view.main.host.get_property('textContent'), + cert['commonName']) + + # Only the secure label is visible in the main view + secure_label = self.identity_popup.view.main.secure_connection_label + self.assertNotEqual(secure_label.value_of_css_property('display'), 'none') + + insecure_label = self.identity_popup.view.main.insecure_connection_label + self.assertEqual(insecure_label.value_of_css_property('display'), 'none') + + self.identity_popup.view.main.expander.click() + Wait(self.marionette).until( + lambda _: self.identity_popup.view.security.selected, + message='Security view of identity popup has not been selected.') + + # Only the secure label is visible in the security view + secure_label = self.identity_popup.view.security.secure_connection_label + self.assertNotEqual(secure_label.value_of_css_property('display'), 'none') + + insecure_label = self.identity_popup.view.security.insecure_connection_label + self.assertEqual(insecure_label.value_of_css_property('display'), 'none') + + verifier_label = self.browser.localize_property('identity.identified.verifier') + self.assertEqual(self.identity_popup.view.security.verifier.get_property('textContent'), + verifier_label.replace("%S", cert['issuerOrganization'])) + + def opener(mn): + self.identity_popup.view.security.more_info_button.click() + + page_info_window = self.browser.open_page_info_window(opener) + deck = page_info_window.deck + + self.assertEqual(deck.selected_panel, deck.security) + + self.assertEqual(deck.security.domain.get_property('value'), + cert['commonName']) + + self.assertEqual(deck.security.owner.get_property('value'), + page_info_window.localize_property('securityNoOwner')) + + self.assertEqual(deck.security.verifier.get_property('value'), + cert['issuerOrganization']) diff --git a/testing/firefox-ui/tests/functional/security/test_enable_privilege.py b/testing/firefox-ui/tests/functional/security/test_enable_privilege.py new file mode 100644 index 000000000..17e883cc5 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_enable_privilege.py @@ -0,0 +1,17 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from marionette_driver import By +from marionette_harness import MarionetteTestCase + + +class TestEnablePrivilege(MarionetteTestCase): + + def test_enable_privilege(self): + with self.marionette.using_context('content'): + url = self.marionette.absolute_url('security/enable_privilege.html') + self.marionette.navigate(url) + + result = self.marionette.find_element(By.ID, 'result') + self.assertEqual(result.get_property('textContent'), 'PASS') diff --git a/testing/firefox-ui/tests/functional/security/test_ev_certificate.py b/testing/firefox-ui/tests/functional/security/test_ev_certificate.py new file mode 100644 index 000000000..f5acf5795 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_ev_certificate.py @@ -0,0 +1,112 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase + + +class TestEVCertificate(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestEVCertificate, self).setUp() + + self.locationbar = self.browser.navbar.locationbar + self.identity_popup = self.locationbar.identity_popup + + self.url = 'https://ssl-ev.mozqa.com/' + + def tearDown(self): + try: + self.browser.switch_to() + self.identity_popup.close(force=True) + self.puppeteer.windows.close_all([self.browser]) + finally: + super(TestEVCertificate, self).tearDown() + + def test_ev_certificate(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + # Check the identity box + self.assertEqual(self.locationbar.identity_box.get_property('className'), + 'verifiedIdentity') + + # Get the information from the certificate + cert = self.browser.tabbar.selected_tab.certificate + address = self.puppeteer.security.get_address_from_certificate(cert) + + # Check the identity popup label displays + self.assertEqual(self.locationbar.identity_organization_label.get_property('value'), + cert['organization']) + self.assertEqual(self.locationbar.identity_country_label.get_property('value'), + '(' + address['country'] + ')') + + # Open the identity popup + self.locationbar.open_identity_popup() + + # Check the idenity popup doorhanger + self.assertEqual(self.identity_popup.element.get_attribute('connection'), 'secure-ev') + + # For EV certificates no hostname but the organization name is shown + self.assertEqual(self.identity_popup.view.main.host.get_property('textContent'), + cert['organization']) + + # Only the secure label is visible in the main view + secure_label = self.identity_popup.view.main.secure_connection_label + self.assertNotEqual(secure_label.value_of_css_property('display'), 'none') + + insecure_label = self.identity_popup.view.main.insecure_connection_label + self.assertEqual(insecure_label.value_of_css_property('display'), 'none') + + self.identity_popup.view.main.expander.click() + Wait(self.marionette).until(lambda _: self.identity_popup.view.security.selected) + + security_view = self.identity_popup.view.security + + # Only the secure label is visible in the security view + secure_label = security_view.secure_connection_label + self.assertNotEqual(secure_label.value_of_css_property('display'), 'none') + + insecure_label = security_view.insecure_connection_label + self.assertEqual(insecure_label.value_of_css_property('display'), 'none') + + # Check the organization name + self.assertEqual(security_view.owner.get_property('textContent'), cert['organization']) + + # Check the owner location string + # More information: + # hg.mozilla.org/mozilla-central/file/eab4a81e4457/browser/base/content/browser.js#l7012 + location = self.browser.localize_property('identity.identified.state_and_country') + location = location.replace('%S', address['state'], 1).replace('%S', address['country']) + location = address['city'] + '\n' + location + self.assertEqual(security_view.owner_location.get_property('textContent'), location) + + # Check the verifier + l10n_verifier = self.browser.localize_property('identity.identified.verifier') + l10n_verifier = l10n_verifier.replace('%S', cert['issuerOrganization']) + self.assertEqual(security_view.verifier.get_property('textContent'), l10n_verifier) + + # Open the Page Info window by clicking the More Information button + page_info = self.browser.open_page_info_window( + lambda _: self.identity_popup.view.security.more_info_button.click()) + + try: + # Verify that the current panel is the security panel + self.assertEqual(page_info.deck.selected_panel, page_info.deck.security) + + # Verify the domain listed on the security panel + self.assertIn(cert['commonName'], + page_info.deck.security.domain.get_property('value')) + + # Verify the owner listed on the security panel + self.assertEqual(page_info.deck.security.owner.get_property('value'), + cert['organization']) + + # Verify the verifier listed on the security panel + self.assertEqual(page_info.deck.security.verifier.get_property('value'), + cert['issuerOrganization']) + finally: + page_info.close() + self.browser.focus() diff --git a/testing/firefox-ui/tests/functional/security/test_mixed_content_page.py b/testing/firefox-ui/tests/functional/security/test_mixed_content_page.py new file mode 100644 index 000000000..c146b46f4 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_mixed_content_page.py @@ -0,0 +1,55 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_harness import MarionetteTestCase + + +class TestMixedContentPage(PuppeteerMixin, MarionetteTestCase): + def setUp(self): + super(TestMixedContentPage, self).setUp() + + self.locationbar = self.browser.navbar.locationbar + self.identity_popup = self.locationbar.identity_popup + + self.url = 'https://mozqa.com/data/firefox/security/mixedcontent.html' + + def tearDown(self): + try: + self.identity_popup.close(force=True) + finally: + super(TestMixedContentPage, self).tearDown() + + def test_mixed_content(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + self.assertEqual(self.locationbar.identity_box.get_property('className'), + 'unknownIdentity mixedDisplayContent') + + # Open the identity popup + self.locationbar.open_identity_popup() + + # Only the insecure label is visible in the main view + secure_label = self.identity_popup.view.main.secure_connection_label + self.assertEqual(secure_label.value_of_css_property('display'), 'none') + + insecure_label = self.identity_popup.view.main.insecure_connection_label + self.assertNotEqual(insecure_label.value_of_css_property('display'), 'none') + + # TODO: Bug 1177417 - Needs to open and close the security view, but a second + # click on the expander doesn't hide the security view + # self.identity_popup.view.main.expander.click() + # Wait(self.marionette).until(lambda _: self.identity_popup.view.security.selected) + + # Only the insecure label is visible in the security view + secure_label = self.identity_popup.view.security.secure_connection_label + self.assertEqual(secure_label.value_of_css_property('display'), 'none') + + insecure_label = self.identity_popup.view.security.insecure_connection_label + self.assertNotEqual(insecure_label.value_of_css_property('display'), 'none') + + # owner is not visible + owner = self.identity_popup.view.security.owner + self.assertEqual(owner.value_of_css_property('display'), 'none') diff --git a/testing/firefox-ui/tests/functional/security/test_mixed_script_content_blocking.py b/testing/firefox-ui/tests/functional/security/test_mixed_script_content_blocking.py new file mode 100644 index 000000000..796b1dc29 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_mixed_script_content_blocking.py @@ -0,0 +1,87 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import By, Wait +from marionette_harness import MarionetteTestCase + + +class TestMixedScriptContentBlocking(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestMixedScriptContentBlocking, self).setUp() + + self.url = 'https://mozqa.com/data/firefox/security/mixed_content_blocked/index.html' + + self.test_elements = [ + ('result1', 'Insecure script one'), + ('result2', 'Insecure script from iFrame'), + ('result3', 'Insecure plugin'), + ('result4', 'Insecure stylesheet'), + ] + + self.locationbar = self.browser.navbar.locationbar + self.identity_popup = self.locationbar.identity_popup + + def tearDown(self): + try: + self.identity_popup.close(force=True) + finally: + super(TestMixedScriptContentBlocking, self).tearDown() + + def _expect_protection_status(self, enabled): + if enabled: + color, identity, state = ( + 'rgb(0, 136, 0)', + 'verifiedDomain mixedActiveBlocked', + 'blocked' + ) + else: + color, identity, state = ( + 'rgb(255, 0, 0)', + 'unknownIdentity mixedActiveContent', + 'unblocked' + ) + + # First call to Wait() needs a longer timeout due to the reload of the web page. + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + lambda _: self.locationbar.identity_box.get_property('className') == identity, + message='Expected identity "{}" not found'.format(identity) + ) + + with self.marionette.using_context('content'): + for identifier, description in self.test_elements: + el = self.marionette.find_element(By.ID, identifier) + Wait(self.marionette).until( + lambda mn: el.value_of_css_property('color') == color, + message=("%s has been %s" % (description, state)) + ) + + def expect_protection_enabled(self): + self._expect_protection_status(True) + + def expect_protection_disabled(self): + self._expect_protection_status(False) + + def test_mixed_content_page(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + self.expect_protection_enabled() + + # Disable mixed content blocking via identity popup + self.locationbar.open_identity_popup() + self.identity_popup.view.main.expander.click() + Wait(self.marionette).until(lambda _: self.identity_popup.view.security.selected) + + disable_button = self.identity_popup.view.security.disable_mixed_content_blocking_button + disable_button.click() + + self.expect_protection_disabled() + + # A reload keeps blocking disabled + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + self.expect_protection_disabled() diff --git a/testing/firefox-ui/tests/functional/security/test_no_certificate.py b/testing/firefox-ui/tests/functional/security/test_no_certificate.py new file mode 100644 index 000000000..a3b7bf98a --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_no_certificate.py @@ -0,0 +1,81 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from urlparse import urlparse + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import expected, Wait +from marionette_harness import MarionetteTestCase + + +class TestNoCertificate(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestNoCertificate, self).setUp() + + self.locationbar = self.browser.navbar.locationbar + self.identity_popup = self.locationbar.identity_popup + + self.url = self.marionette.absolute_url('layout/mozilla.html') + + def tearDown(self): + try: + self.browser.switch_to() + self.identity_popup.close(force=True) + self.puppeteer.windows.close_all([self.browser]) + finally: + super(TestNoCertificate, self).tearDown() + + def test_no_certificate(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + # Check the favicon + # TODO: find a better way to check, e.g., mozmill's isDisplayed + favicon_hidden = self.marionette.execute_script(""" + return arguments[0].hasAttribute("hidden"); + """, script_args=[self.browser.navbar.locationbar.identity_icon]) + self.assertFalse(favicon_hidden, 'The identity icon is visible') + + # Check that the identity box organization label is blank + self.assertEqual(self.locationbar.identity_organization_label.get_property('value'), '', + 'The organization has no label') + + # Open the identity popup + self.locationbar.open_identity_popup() + + # Check the idenity popup doorhanger + self.assertEqual(self.identity_popup.element.get_attribute('connection'), 'not-secure') + + # The expander for the security view does not exist + expected.element_not_present(lambda m: self.identity_popup.main.expander) + + # Only the insecure label is visible + secure_label = self.identity_popup.view.main.secure_connection_label + self.assertEqual(secure_label.value_of_css_property('display'), 'none') + + insecure_label = self.identity_popup.view.main.insecure_connection_label + self.assertNotEqual(insecure_label.value_of_css_property('display'), 'none') + + self.identity_popup.view.main.expander.click() + Wait(self.marionette).until(lambda _: self.identity_popup.view.security.selected) + + # Open the Page Info window by clicking the "More Information" button + page_info = self.browser.open_page_info_window( + lambda _: self.identity_popup.view.security.more_info_button.click()) + + # Verify that the current panel is the security panel + self.assertEqual(page_info.deck.selected_panel, page_info.deck.security) + + # Check the domain listed on the security panel contains the url's host name + self.assertIn(urlparse(self.url).hostname, + page_info.deck.security.domain.get_property('value')) + + # Check the owner label equals localized 'securityNoOwner' + self.assertEqual(page_info.deck.security.owner.get_property('value'), + page_info.localize_property('securityNoOwner')) + + # Check the verifier label equals localized 'notset' + self.assertEqual(page_info.deck.security.verifier.get_property('value'), + page_info.localize_property('notset')) diff --git a/testing/firefox-ui/tests/functional/security/test_safe_browsing_initial_download.py b/testing/firefox-ui/tests/functional/security/test_safe_browsing_initial_download.py new file mode 100644 index 000000000..6f9c50ffb --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_safe_browsing_initial_download.py @@ -0,0 +1,84 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import os + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase + + +class TestSafeBrowsingInitialDownload(PuppeteerMixin, MarionetteTestCase): + + file_extensions = [ + 'pset', + 'sbstore', + ] + + prefs_download_lists = [ + 'urlclassifier.blockedTable', + 'urlclassifier.downloadAllowTable', + 'urlclassifier.downloadBlockTable', + 'urlclassifier.malwareTable', + 'urlclassifier.phishTable', + 'urlclassifier.trackingTable', + 'urlclassifier.trackingWhitelistTable', + ] + + prefs_provider_update_time = { + # Force an immediate download of the safebrowsing files + 'browser.safebrowsing.provider.google.nextupdatetime': 1, + 'browser.safebrowsing.provider.mozilla.nextupdatetime': 1, + } + + prefs_safebrowsing = { + 'browser.safebrowsing.debug': True, + 'browser.safebrowsing.blockedURIs.enabled': True, + 'browser.safebrowsing.downloads.enabled': True, + 'browser.safebrowsing.phishing.enabled': True, + 'browser.safebrowsing.malware.enabled': True, + 'privacy.trackingprotection.enabled': True, + 'privacy.trackingprotection.pbmode.enabled': True, + } + + def get_safebrowsing_files(self): + files = [] + for pref_name in self.prefs_download_lists: + base_names = self.marionette.get_pref(pref_name).split(',') + for ext in self.file_extensions: + files.extend(['{file}.{ext}'.format(file=f, ext=ext) for f in base_names if f]) + + return set(sorted(files)) + + def setUp(self): + super(TestSafeBrowsingInitialDownload, self).setUp() + + # Force the preferences for the new profile + enforce_prefs = self.prefs_safebrowsing + enforce_prefs.update(self.prefs_provider_update_time) + self.marionette.enforce_gecko_prefs(enforce_prefs) + + self.safebrowsing_path = os.path.join(self.marionette.instance.profile.profile, + 'safebrowsing') + self.safebrowsing_files = self.get_safebrowsing_files() + + def tearDown(self): + try: + # Restart with a fresh profile + self.restart(clean=True) + finally: + super(TestSafeBrowsingInitialDownload, self).tearDown() + + def test_safe_browsing_initial_download(self): + def check_downloaded(_): + return reduce(lambda state, pref: state and int(self.marionette.get_pref(pref)) != 1, + self.prefs_provider_update_time.keys(), True) + + try: + Wait(self.marionette, timeout=60).until( + check_downloaded, message='Not all safebrowsing files have been downloaded') + finally: + files_on_disk_toplevel = os.listdir(self.safebrowsing_path) + for f in self.safebrowsing_files: + self.assertIn(f, files_on_disk_toplevel) diff --git a/testing/firefox-ui/tests/functional/security/test_safe_browsing_notification.py b/testing/firefox-ui/tests/functional/security/test_safe_browsing_notification.py new file mode 100644 index 000000000..5fb3d0389 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_safe_browsing_notification.py @@ -0,0 +1,149 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import time + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import By, expected, Wait +from marionette_harness import MarionetteTestCase + + +class TestSafeBrowsingNotificationBar(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestSafeBrowsingNotificationBar, self).setUp() + + self.test_data = [ + # Unwanted software URL + { + # First two properties are not needed, + # since these errors are not reported + 'button_property': None, + 'report_page': None, + 'unsafe_page': 'https://www.itisatrap.org/firefox/unwanted.html' + }, + # Phishing URL info + { + 'button_property': 'safebrowsing.notADeceptiveSiteButton.label', + 'report_page': 'google.com/safebrowsing/report_error', + 'unsafe_page': 'https://www.itisatrap.org/firefox/its-a-trap.html' + }, + # Malware URL object + { + 'button_property': 'safebrowsing.notAnAttackButton.label', + 'report_page': 'stopbadware.org', + 'unsafe_page': 'https://www.itisatrap.org/firefox/its-an-attack.html' + } + ] + + self.marionette.set_pref('browser.safebrowsing.phishing.enabled', True) + self.marionette.set_pref('browser.safebrowsing.malware.enabled', True) + + # Give the browser a little time, because SafeBrowsing.jsm takes a while + # between start up and adding the example urls to the db. + # hg.mozilla.org/mozilla-central/file/46aebcd9481e/browser/base/content/browser.js#l1194 + time.sleep(3) + + # TODO: Bug 1139544: While we don't have a reliable way to close the safe browsing + # notification bar when a test fails, run this test in a new tab. + self.browser.tabbar.open_tab() + + def tearDown(self): + try: + self.puppeteer.utils.permissions.remove('https://www.itisatrap.org', 'safe-browsing') + self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]]) + self.marionette.clear_pref('browser.safebrowsing.phishing.enabled') + self.marionette.clear_pref('browser.safebrowsing.malware.enabled') + finally: + super(TestSafeBrowsingNotificationBar, self).tearDown() + + def test_notification_bar(self): + with self.marionette.using_context('content'): + for item in self.test_data: + button_property = item['button_property'] + report_page, unsafe_page = item['report_page'], item['unsafe_page'] + + # Navigate to the unsafe page + # Check "ignore warning" link then notification bar's "not badware" button + # Only do this if feature supports it + if button_property is not None: + self.marionette.navigate(unsafe_page) + # Wait for the DOM to receive events for about:blocked + time.sleep(1) + self.check_ignore_warning_button(unsafe_page) + self.check_not_badware_button(button_property, report_page) + + # Return to the unsafe page + # Check "ignore warning" link then notification bar's "get me out" button + self.marionette.navigate(unsafe_page) + # Wait for the DOM to receive events for about:blocked + time.sleep(1) + self.check_ignore_warning_button(unsafe_page) + self.check_get_me_out_of_here_button() + + # Return to the unsafe page + # Check "ignore warning" link then notification bar's "X" button + self.marionette.navigate(unsafe_page) + # Wait for the DOM to receive events for about:blocked + time.sleep(1) + self.check_ignore_warning_button(unsafe_page) + self.check_x_button() + + def check_ignore_warning_button(self, unsafe_page): + button = self.marionette.find_element(By.ID, 'ignoreWarningButton') + button.click() + + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + expected.element_present(By.ID, 'main-feature'), + message='Expected target element "#main-feature" has not been found', + ) + self.assertEquals(self.marionette.get_url(), self.browser.get_final_url(unsafe_page)) + + # Clean up here since the permission gets set in this function + self.puppeteer.utils.permissions.remove('https://www.itisatrap.org', 'safe-browsing') + + # Check the not a forgery or attack button in the notification bar + def check_not_badware_button(self, button_property, report_page): + with self.marionette.using_context('chrome'): + # TODO: update to use safe browsing notification bar class when bug 1139544 lands + label = self.browser.localize_property(button_property) + button = (self.marionette.find_element(By.ID, 'content') + .find_element('anon attribute', {'label': label})) + + self.browser.tabbar.open_tab(lambda _: button.click()) + + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + lambda mn: report_page in mn.get_url(), + message='The expected safe-browsing report page has not been opened', + ) + + with self.marionette.using_context('chrome'): + self.browser.tabbar.close_tab() + + def check_get_me_out_of_here_button(self): + with self.marionette.using_context('chrome'): + # TODO: update to use safe browsing notification bar class when bug 1139544 lands + label = self.browser.localize_property('safebrowsing.getMeOutOfHereButton.label') + button = (self.marionette.find_element(By.ID, 'content') + .find_element('anon attribute', {'label': label})) + button.click() + + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + lambda mn: self.browser.default_homepage in mn.get_url(), + message='The default home page has not been loaded', + ) + + def check_x_button(self): + with self.marionette.using_context('chrome'): + # TODO: update to use safe browsing notification bar class when bug 1139544 lands + button = (self.marionette.find_element(By.ID, 'content') + .find_element('anon attribute', {'value': 'blocked-badware-page'}) + .find_element('anon attribute', + {'class': 'messageCloseButton close-icon tabbable'})) + button.click() + + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + expected.element_stale(button), + message='The notification bar has not been closed', + ) diff --git a/testing/firefox-ui/tests/functional/security/test_safe_browsing_warning_pages.py b/testing/firefox-ui/tests/functional/security/test_safe_browsing_warning_pages.py new file mode 100644 index 000000000..968a9464b --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_safe_browsing_warning_pages.py @@ -0,0 +1,115 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import time + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import By, expected, Wait +from marionette_harness import MarionetteTestCase + + +class TestSafeBrowsingWarningPages(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestSafeBrowsingWarningPages, self).setUp() + + self.urls = [ + # Unwanted software URL + 'https://www.itisatrap.org/firefox/unwanted.html', + # Phishing URL + 'https://www.itisatrap.org/firefox/its-a-trap.html', + # Malware URL + 'https://www.itisatrap.org/firefox/its-an-attack.html' + ] + + self.marionette.set_pref('app.support.baseURL', + self.marionette.absolute_url("support.html?topic=")) + self.marionette.set_pref('browser.safebrowsing.phishing.enabled', True) + self.marionette.set_pref('browser.safebrowsing.malware.enabled', True) + + # Give the browser a little time, because SafeBrowsing.jsm takes a + # while between start up and adding the example urls to the db. + # hg.mozilla.org/mozilla-central/file/46aebcd9481e/browser/base/content/browser.js#l1194 + time.sleep(3) + + # TODO: Bug 1139544: While we don't have a reliable way to close the safe browsing + # notification bar when a test fails, run this test in a new tab. + self.browser.tabbar.open_tab() + + def tearDown(self): + try: + self.puppeteer.utils.permissions.remove('https://www.itisatrap.org', 'safe-browsing') + self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]]) + self.marionette.clear_pref('app.support.baseURL') + self.marionette.clear_pref('browser.safebrowsing.malware.enabled') + self.marionette.clear_pref('browser.safebrowsing.phishing.enabled') + finally: + super(TestSafeBrowsingWarningPages, self).tearDown() + + def test_warning_pages(self): + with self.marionette.using_context("content"): + for unsafe_page in self.urls: + # Load a test page, then test the get me out button + self.marionette.navigate(unsafe_page) + # Wait for the DOM to receive events for about:blocked + time.sleep(1) + self.check_get_me_out_of_here_button(unsafe_page) + + # Load the test page again, then test the report button + self.marionette.navigate(unsafe_page) + # Wait for the DOM to receive events for about:blocked + time.sleep(1) + self.check_report_button(unsafe_page) + + # Load the test page again, then test the ignore warning button + self.marionette.navigate(unsafe_page) + # Wait for the DOM to receive events for about:blocked + time.sleep(1) + self.check_ignore_warning_button(unsafe_page) + + def check_get_me_out_of_here_button(self, unsafe_page): + button = self.marionette.find_element(By.ID, "getMeOutButton") + button.click() + + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + lambda mn: self.browser.default_homepage in mn.get_url()) + + def check_report_button(self, unsafe_page): + # Get the URL of the support site for phishing and malware. This may result in a redirect. + with self.marionette.using_context('chrome'): + url = self.marionette.execute_script(""" + Components.utils.import("resource://gre/modules/Services.jsm"); + return Services.urlFormatter.formatURLPref("app.support.baseURL") + + "phishing-malware"; + """) + + button = self.marionette.find_element(By.ID, "reportButton") + button.click() + + # Wait for the button to become stale, whereby a longer timeout is needed + # here to not fail in case of slow connections. + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + expected.element_stale(button)) + + # Wait for page load to be completed, so we can verify the URL even if a redirect happens. + # TODO: Bug 1140470: use replacement for mozmill's waitforPageLoad + expected_url = self.browser.get_final_url(url) + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + lambda mn: expected_url == mn.get_url(), + message="The expected URL '{}' has not been loaded".format(expected_url) + ) + + topic = self.marionette.find_element(By.ID, "topic") + self.assertEquals(topic.text, "phishing-malware") + + def check_ignore_warning_button(self, unsafe_page): + button = self.marionette.find_element(By.ID, 'ignoreWarningButton') + button.click() + + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + expected.element_present(By.ID, 'main-feature')) + self.assertEquals(self.marionette.get_url(), self.browser.get_final_url(unsafe_page)) + + # Clean up by removing safe browsing permission for unsafe page + self.puppeteer.utils.permissions.remove('https://www.itisatrap.org', 'safe-browsing') diff --git a/testing/firefox-ui/tests/functional/security/test_security_notification.py b/testing/firefox-ui/tests/functional/security/test_security_notification.py new file mode 100644 index 000000000..5825d0364 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_security_notification.py @@ -0,0 +1,62 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import time + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import By, Wait +from marionette_driver.errors import MarionetteException +from marionette_harness import MarionetteTestCase + + +class TestSecurityNotification(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestSecurityNotification, self).setUp() + + self.urls = [ + # Invalid cert page + 'https://ssl-expired.mozqa.com', + # Secure page + 'https://ssl-ev.mozqa.com/', + # Insecure page + 'http://no-ssl.mozqa.com' + ] + + self.identity_box = self.browser.navbar.locationbar.identity_box + + def test_invalid_cert(self): + with self.marionette.using_context('content'): + # Go to a site that has an invalid (expired) cert + self.assertRaises(MarionetteException, self.marionette.navigate, self.urls[0]) + + # Wait for the DOM to receive events + time.sleep(1) + + # Verify the text in Technical Content contains the page with invalid cert + text = self.marionette.find_element(By.ID, 'badCertTechnicalInfo') + self.assertIn(self.urls[0][8:], text.get_property('textContent')) + + # Verify the "Go Back" and "Advanced" buttons appear + self.assertIsNotNone(self.marionette.find_element(By.ID, 'returnButton')) + self.assertIsNotNone(self.marionette.find_element(By.ID, 'advancedButton')) + + # Verify the error code is correct + self.assertIn('SEC_ERROR_EXPIRED_CERTIFICATE', text.get_property('textContent')) + + def test_secure_website(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.urls[1]) + + Wait(self.marionette).until(lambda _: ( + self.identity_box.get_property('className') == 'verifiedIdentity') + ) + + def test_insecure_website(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.urls[2]) + + Wait(self.marionette).until(lambda _: ( + self.identity_box.get_property('className') == 'unknownIdentity') + ) diff --git a/testing/firefox-ui/tests/functional/security/test_ssl_disabled_error_page.py b/testing/firefox-ui/tests/functional/security/test_ssl_disabled_error_page.py new file mode 100644 index 000000000..d1d9c531f --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_ssl_disabled_error_page.py @@ -0,0 +1,60 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import time + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import By, expected, Wait +from marionette_driver.errors import MarionetteException +from marionette_harness import MarionetteTestCase + + +class TestSSLDisabledErrorPage(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestSSLDisabledErrorPage, self).setUp() + + self.url = 'https://tlsv1-0.mozqa.com' + + self.puppeteer.utils.sanitize({"sessions": True}) + + # Disable SSL 3.0, TLS 1.0 and TLS 1.1 for secure connections + # by forcing the use of TLS 1.2 + # see: http://kb.mozillazine.org/Security.tls.version.*#Possible_values_and_their_effects + self.marionette.set_pref('security.tls.version.min', 3) + self.marionette.set_pref('security.tls.version.max', 3) + + def tearDown(self): + try: + self.marionette.clear_pref('security.tls.version.min') + self.marionette.clear_pref('security.tls.version.max') + finally: + super(TestSSLDisabledErrorPage, self).tearDown() + + def test_ssl_disabled_error_page(self): + with self.marionette.using_context('content'): + # Open the test page + self.assertRaises(MarionetteException, self.marionette.navigate, self.url) + + # Wait for the DOM to receive events + time.sleep(1) + + # Verify "Secure Connection Failed" error page title + title = self.marionette.find_element(By.CLASS_NAME, 'title-text') + nss_failure2title = self.browser.localize_entity('nssFailure2.title') + self.assertEquals(title.get_property('textContent'), nss_failure2title) + + # Verify the error message is correct + short_description = self.marionette.find_element(By.ID, 'errorShortDescText') + self.assertIn('SSL_ERROR_UNSUPPORTED_VERSION', + short_description.get_property('textContent')) + self.assertIn('mozqa.com', short_description.get_property('textContent')) + + # Verify that the "Restore" button appears and works + reset_button = self.marionette.find_element(By.ID, 'prefResetButton') + reset_button.click() + + # With the preferences reset, the page has to load correctly + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + expected.element_present(By.LINK_TEXT, 'http://quality.mozilla.org')) diff --git a/testing/firefox-ui/tests/functional/security/test_ssl_status_after_restart.py b/testing/firefox-ui/tests/functional/security/test_ssl_status_after_restart.py new file mode 100644 index 000000000..f274d8f2f --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_ssl_status_after_restart.py @@ -0,0 +1,124 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import Wait +from marionette_harness import MarionetteTestCase, skip_if_e10s + + +class TestSSLStatusAfterRestart(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestSSLStatusAfterRestart, self).setUp() + + self.test_data = ( + { + 'url': 'https://ssl-dv.mozqa.com', + 'identity': '', + 'type': 'secure' + }, + { + 'url': 'https://ssl-ev.mozqa.com/', + 'identity': 'Mozilla Corporation', + 'type': 'secure-ev' + }, + { + 'url': 'https://ssl-ov.mozqa.com/', + 'identity': '', + 'type': 'secure' + } + ) + + # Set browser to restore previous session + self.marionette.set_pref('browser.startup.page', 3) + + self.locationbar = self.browser.navbar.locationbar + self.identity_popup = self.locationbar.identity_popup + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]]) + self.browser.switch_to() + self.identity_popup.close(force=True) + self.marionette.clear_pref('browser.startup.page') + finally: + super(TestSSLStatusAfterRestart, self).tearDown() + + @skip_if_e10s("Bug 1325047") + def test_ssl_status_after_restart(self): + for item in self.test_data: + with self.marionette.using_context('content'): + self.marionette.navigate(item['url']) + self.verify_certificate_status(item) + self.browser.tabbar.open_tab() + + self.restart() + + # Refresh references to elements + self.locationbar = self.browser.navbar.locationbar + self.identity_popup = self.locationbar.identity_popup + + for index, item in enumerate(self.test_data): + self.browser.tabbar.tabs[index].select() + self.verify_certificate_status(item) + + def verify_certificate_status(self, item): + url, identity, cert_type = item['url'], item['identity'], item['type'] + + # Check the favicon + # TODO: find a better way to check, e.g., mozmill's isDisplayed + favicon_hidden = self.marionette.execute_script(""" + return arguments[0].hasAttribute("hidden"); + """, script_args=[self.browser.navbar.locationbar.identity_icon]) + self.assertFalse(favicon_hidden) + + self.locationbar.open_identity_popup() + + # Check the type shown on the identity popup doorhanger + self.assertEqual(self.identity_popup.element.get_attribute('connection'), + cert_type) + + self.identity_popup.view.main.expander.click() + Wait(self.marionette).until(lambda _: self.identity_popup.view.security.selected) + + # Check the identity label + self.assertEqual(self.locationbar.identity_organization_label.get_property('value'), + identity) + + # Get the information from the certificate + cert = self.browser.tabbar.selected_tab.certificate + + # Open the Page Info window by clicking the More Information button + page_info = self.browser.open_page_info_window( + lambda _: self.identity_popup.view.security.more_info_button.click()) + + # Verify that the current panel is the security panel + self.assertEqual(page_info.deck.selected_panel, page_info.deck.security) + + # Verify the domain listed on the security panel + # If this is a wildcard cert, check only the domain + if cert['commonName'].startswith('*'): + self.assertIn(self.puppeteer.security.get_domain_from_common_name(cert['commonName']), + page_info.deck.security.domain.get_property('value'), + 'Expected domain found in certificate for ' + url) + else: + self.assertEqual(page_info.deck.security.domain.get_property('value'), + cert['commonName'], + 'Domain value matches certificate common name.') + + # Verify the owner listed on the security panel + if identity != '': + owner = cert['organization'] + else: + owner = page_info.localize_property('securityNoOwner') + + self.assertEqual(page_info.deck.security.owner.get_property('value'), owner, + 'Expected owner label found for ' + url) + + # Verify the verifier listed on the security panel + self.assertEqual(page_info.deck.security.verifier.get_property('value'), + cert['issuerOrganization'], + 'Verifier matches issuer of certificate for ' + url) + page_info.close() diff --git a/testing/firefox-ui/tests/functional/security/test_submit_unencrypted_info_warning.py b/testing/firefox-ui/tests/functional/security/test_submit_unencrypted_info_warning.py new file mode 100644 index 000000000..a2f431fb5 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_submit_unencrypted_info_warning.py @@ -0,0 +1,65 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import By, expected, Wait +from marionette_driver.errors import NoAlertPresentException +from marionette_driver.marionette import Alert +from marionette_harness import MarionetteTestCase + + +class TestSubmitUnencryptedInfoWarning(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestSubmitUnencryptedInfoWarning, self).setUp() + + self.url = 'https://ssl-dv.mozqa.com/data/firefox/security/unencryptedsearch.html' + self.test_string = 'mozilla' + + self.marionette.set_pref('security.warn_submit_insecure', True) + + def tearDown(self): + try: + self.marionette.clear_pref('security.warn_submit_insecure') + finally: + super(TestSubmitUnencryptedInfoWarning, self).tearDown() + + def test_submit_unencrypted_info_warning(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + # Get the page's search box and submit button. + searchbox = self.marionette.find_element(By.ID, 'q') + button = self.marionette.find_element(By.ID, 'submit') + + # Use the page's search box to submit information. + searchbox.send_keys(self.test_string) + button.click() + + # Get the expected warning text and replace its two instances of "##" with "\n\n". + message = self.browser.localize_property('formPostSecureToInsecureWarning.message') + message = message.replace('##', '\n\n') + + # Wait for the warning, verify the expected text matches warning, accept the warning + warning = Alert(self.marionette) + try: + Wait(self.marionette, + ignored_exceptions=NoAlertPresentException, + timeout=self.marionette.timeout.page_load).until( + lambda _: warning.text == message) + finally: + warning.accept() + + # Wait for the search box to become stale, then wait for the page to be reloaded. + Wait(self.marionette).until(expected.element_stale(searchbox)) + + # TODO: Bug 1140470: use replacement for mozmill's waitforPageLoad + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + lambda mn: mn.execute_script('return document.readyState == "DOMContentLoaded" ||' + ' document.readyState == "complete";') + ) + + # Check that search_term contains the test string. + search_term = self.marionette.find_element(By.ID, 'search-term') + self.assertEqual(search_term.get_property('textContent'), self.test_string) diff --git a/testing/firefox-ui/tests/functional/security/test_unknown_issuer.py b/testing/firefox-ui/tests/functional/security/test_unknown_issuer.py new file mode 100644 index 000000000..b329f2500 --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_unknown_issuer.py @@ -0,0 +1,34 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import time + +from marionette_driver import By +from marionette_driver.errors import MarionetteException +from marionette_harness import MarionetteTestCase + + +class TestUnknownIssuer(MarionetteTestCase): + + def setUp(self): + super(TestUnknownIssuer, self).setUp() + + self.url = 'https://ssl-unknownissuer.mozqa.com' + + def test_unknown_issuer(self): + with self.marionette.using_context('content'): + # Go to a site that has a cert with an unknown issuer + self.assertRaises(MarionetteException, self.marionette.navigate, self.url) + + # Wait for the DOM to receive events + time.sleep(1) + + # Check for the correct error code + error = self.marionette.find_element(By.ID, 'errorCode') + self.assertEquals(error.get_property('textContent'), + 'SEC_ERROR_UNKNOWN_ISSUER') + + # Verify the "Go Back" and "Advanced" buttons appear + self.assertIsNotNone(self.marionette.find_element(By.ID, 'returnButton')) + self.assertIsNotNone(self.marionette.find_element(By.ID, 'advancedButton')) diff --git a/testing/firefox-ui/tests/functional/security/test_untrusted_connection_error_page.py b/testing/firefox-ui/tests/functional/security/test_untrusted_connection_error_page.py new file mode 100644 index 000000000..0dbce1c8f --- /dev/null +++ b/testing/firefox-ui/tests/functional/security/test_untrusted_connection_error_page.py @@ -0,0 +1,35 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import time + +from firefox_puppeteer import PuppeteerMixin +from marionette_driver import By, Wait +from marionette_driver.errors import MarionetteException +from marionette_harness import MarionetteTestCase + + +class TestUntrustedConnectionErrorPage(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestUntrustedConnectionErrorPage, self).setUp() + + self.url = 'https://ssl-selfsigned.mozqa.com' + + def test_untrusted_connection_error_page(self): + self.marionette.set_context('content') + + # In some localized builds, the default page redirects + target_url = self.browser.get_final_url(self.browser.default_homepage) + + self.assertRaises(MarionetteException, self.marionette.navigate, self.url) + + # Wait for the DOM to receive events + time.sleep(1) + + button = self.marionette.find_element(By.ID, "returnButton") + button.click() + + Wait(self.marionette, timeout=self.marionette.timeout.page_load).until( + lambda mn: target_url == self.marionette.get_url()) diff --git a/testing/firefox-ui/tests/functional/sessionstore/manifest.ini b/testing/firefox-ui/tests/functional/sessionstore/manifest.ini new file mode 100644 index 000000000..c2d0a02b8 --- /dev/null +++ b/testing/firefox-ui/tests/functional/sessionstore/manifest.ini @@ -0,0 +1,5 @@ +[DEFAULT] +tags = local + +[test_restore_windows_after_restart.py] +skip-if = (os == "win" || e10s) # Bug 1291844 and Bug 1228446 diff --git a/testing/firefox-ui/tests/functional/sessionstore/test_restore_windows_after_restart.py b/testing/firefox-ui/tests/functional/sessionstore/test_restore_windows_after_restart.py new file mode 100644 index 000000000..cc7de728b --- /dev/null +++ b/testing/firefox-ui/tests/functional/sessionstore/test_restore_windows_after_restart.py @@ -0,0 +1,150 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from firefox_puppeteer import PuppeteerMixin +from marionette_harness import MarionetteTestCase + + +class TestRestoreWindowsAfterRestart(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestRestoreWindowsAfterRestart, self).setUp() + + # Each list element represents a window of tabs loaded at + # some testing URL + self.test_windows = set([ + # Window 1. Note the comma after the absolute_url call - + # this is Python's way of declaring a 1 item tuple. + (self.marionette.absolute_url('layout/mozilla.html'), ), + + # Window 2 + (self.marionette.absolute_url('layout/mozilla_organizations.html'), + self.marionette.absolute_url('layout/mozilla_community.html')), + + # Window 3 + (self.marionette.absolute_url('layout/mozilla_governance.html'), + self.marionette.absolute_url('layout/mozilla_grants.html')), + ]) + + self.private_windows = set([ + (self.marionette.absolute_url('layout/mozilla_mission.html'), + self.marionette.absolute_url('layout/mozilla_organizations.html')), + + (self.marionette.absolute_url('layout/mozilla_projects.html'), + self.marionette.absolute_url('layout/mozilla_mission.html')), + ]) + + self.marionette.enforce_gecko_prefs({ + # Set browser to restore previous session + 'browser.startup.page': 3, + # Make the content load right away instead of waiting for + # the user to click on the background tabs + 'browser.sessionstore.restore_on_demand': False, + # Avoid race conditions by having the content process never + # send us session updates unless the parent has explicitly asked + # for them via the TabStateFlusher. + 'browser.sessionstore.debug.no_auto_updates': True, + }) + + def tearDown(self): + try: + # Create a fresh profile for subsequent tests. + self.restart(clean=True) + finally: + super(TestRestoreWindowsAfterRestart, self).tearDown() + + def test_with_variety(self): + """ Opens a set of windows, both standard and private, with + some number of tabs in them. Once the tabs have loaded, restarts + the browser, and then ensures that the standard tabs have been + restored, and that the private ones have not. + """ + self.open_windows(self.test_windows) + self.open_windows(self.private_windows, is_private=True) + + self.restart() + + windows = self.puppeteer.windows.all + + # There's no guarantee that Marionette will return us an + # iterator for the opened windows that will match the + # order within our window list. Instead, we'll convert + # the list of URLs within each open window to a set of + # tuples that will allow us to do a direct comparison + # while allowing the windows to be in any order. + opened_windows = set() + for win in windows: + urls = tuple() + for tab in win.tabbar.tabs: + urls = urls + tuple([tab.location]) + opened_windows.add(urls) + + self.assertEqual(opened_windows, self.test_windows) + + def open_windows(self, window_sets, is_private=False): + """ Opens a set of windows with tabs pointing at some + URLs. + + @param window_sets (list) + A set of URL tuples. Each tuple within window_sets + represents a window, and each URL in the URL + tuples represents what will be loaded in a tab. + + Note that if is_private is False, then the first + URL tuple will be opened in the current window, and + subequent tuples will be opened in new windows. + + Example: + + set( + (self.marionette.absolute_url('layout/mozilla_1.html'), + self.marionette.absolute_url('layout/mozilla_2.html')), + + (self.marionette.absolute_url('layout/mozilla_3.html'), + self.marionette.absolute_url('layout/mozilla_4.html')), + ) + + This would take the currently open window, and load + mozilla_1.html and mozilla_2.html in new tabs. It would + then open a new, second window, and load tabs at + mozilla_3.html and mozilla_4.html. + @param is_private (boolean, optional) + Whether or not any new windows should be a private browsing + windows. + """ + + if (is_private): + win = self.browser.open_browser(is_private=True) + win.switch_to() + else: + win = self.browser + + for index, urls in enumerate(window_sets): + if index > 0: + win = self.browser.open_browser(is_private=is_private) + win.switch_to() + self.open_tabs(win, urls) + + def open_tabs(self, win, urls): + """ Opens a set of URLs inside a window in new tabs. + + @param win (browser window) + The browser window to load the tabs in. + @param urls (tuple) + A tuple of URLs to load in this window. The + first URL will be loaded in the currently selected + browser tab. Subsequent URLs will be loaded in + new tabs. + """ + # If there are any remaining URLs for this window, + # open some new tabs and navigate to them. + with self.marionette.using_context('content'): + if isinstance(urls, str): + self.marionette.navigate(urls) + else: + for index, url in enumerate(urls): + if index > 0: + with self.marionette.using_context('chrome'): + win.tabbar.open_tab() + self.marionette.navigate(url) |