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 | |
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')
48 files changed, 3311 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) diff --git a/testing/firefox-ui/tests/puppeteer/manifest.ini b/testing/firefox-ui/tests/puppeteer/manifest.ini new file mode 100644 index 000000000..2eb24b6dc --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/manifest.ini @@ -0,0 +1,24 @@ +[DEFAULT] +tags = local + +# API tests +[test_appinfo.py] +[test_l10n.py] +[test_places.py] +[test_security.py] +tags = remote +[test_software_update.py] +tags = remote +[test_utils.py] + +# UI tests +[test_about_window.py] +[test_menubar.py] +[test_notifications.py] +[test_page_info_window.py] +[test_tabbar.py] +[test_toolbars.py] +tags = remote +[test_update_wizard.py] +tags = remote +[test_windows.py] diff --git a/testing/firefox-ui/tests/puppeteer/test_about_window.py b/testing/firefox-ui/tests/puppeteer/test_about_window.py new file mode 100644 index 000000000..c957211bb --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_about_window.py @@ -0,0 +1,74 @@ +# 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.deck import Panel +from marionette_harness import MarionetteTestCase + + +class TestAboutWindow(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestAboutWindow, self).setUp() + + self.about_window = self.browser.open_about_window() + self.deck = self.about_window.deck + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + finally: + super(TestAboutWindow, self).tearDown() + + def test_basic(self): + self.assertEqual(self.about_window.window_type, 'Browser:About') + + def test_elements(self): + """Test correct retrieval of elements.""" + self.assertNotEqual(self.about_window.dtds, []) + + self.assertEqual(self.deck.element.get_property('localName'), 'deck') + + # apply panel + panel = self.deck.apply + self.assertEqual(panel.element.get_property('localName'), 'hbox') + self.assertEqual(panel.button.get_property('localName'), 'button') + + # check_for_updates panel + panel = self.deck.check_for_updates + self.assertEqual(panel.element.get_property('localName'), 'hbox') + self.assertEqual(panel.button.get_property('localName'), 'button') + + # checking_for_updates panel + self.assertEqual(self.deck.checking_for_updates.element.get_property('localName'), 'hbox') + + # download_and_install panel + panel = self.deck.download_and_install + self.assertEqual(panel.element.get_property('localName'), 'hbox') + self.assertEqual(panel.button.get_property('localName'), 'button') + + # download_failed panel + self.assertEqual(self.deck.download_failed.element.get_property('localName'), 'hbox') + + # downloading panel + self.assertEqual(self.deck.downloading.element.get_property('localName'), 'hbox') + + # check deck attributes + self.assertIsInstance(self.deck.selected_index, int) + self.assertIsInstance(self.deck.selected_panel, Panel) + + def test_open_window(self): + """Test various opening strategies.""" + def opener(win): + self.browser.menubar.select_by_id('helpMenu', 'aboutName') + + open_strategies = ('menu', + opener, + ) + + self.about_window.close() + for trigger in open_strategies: + about_window = self.browser.open_about_window(trigger=trigger) + self.assertEquals(about_window, self.puppeteer.windows.current) + about_window.close() diff --git a/testing/firefox-ui/tests/puppeteer/test_appinfo.py b/testing/firefox-ui/tests/puppeteer/test_appinfo.py new file mode 100644 index 000000000..f0be0f616 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_appinfo.py @@ -0,0 +1,31 @@ +# 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 mozversion + +from firefox_puppeteer import PuppeteerMixin +from marionette_harness import MarionetteTestCase + + +class TestAppInfo(PuppeteerMixin, MarionetteTestCase): + + def test_valid_properties(self): + binary = self.marionette.bin + version_info = mozversion.get_version(binary=binary) + + self.assertEqual(self.puppeteer.appinfo.ID, version_info['application_id']) + self.assertEqual(self.puppeteer.appinfo.name, version_info['application_name']) + self.assertEqual(self.puppeteer.appinfo.vendor, version_info['application_vendor']) + self.assertEqual(self.puppeteer.appinfo.version, version_info['application_version']) + # Bug 1298328 - Platform buildid mismatch due to incremental builds + # self.assertEqual(self.puppeteer.appinfo.platformBuildID, + # version_info['platform_buildid']) + self.assertEqual(self.puppeteer.appinfo.platformVersion, version_info['platform_version']) + self.assertIsNotNone(self.puppeteer.appinfo.locale) + self.assertIsNotNone(self.puppeteer.appinfo.user_agent) + self.assertIsNotNone(self.puppeteer.appinfo.XPCOMABI) + + def test_invalid_properties(self): + with self.assertRaises(AttributeError): + self.puppeteer.appinfo.unknown diff --git a/testing/firefox-ui/tests/puppeteer/test_l10n.py b/testing/firefox-ui/tests/puppeteer/test_l10n.py new file mode 100644 index 000000000..08f41f9d7 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_l10n.py @@ -0,0 +1,51 @@ +# 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.api.l10n import L10n +from marionette_driver import By +from marionette_driver.errors import NoSuchElementException +from marionette_harness import MarionetteTestCase + + +class TestL10n(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestL10n, self).setUp() + + self.l10n = L10n(self.marionette) + + def test_dtd_entity_chrome(self): + dtds = ['chrome://global/locale/about.dtd', + 'chrome://browser/locale/baseMenuOverlay.dtd'] + + value = self.l10n.localize_entity(dtds, 'helpSafeMode.label') + elm = self.marionette.find_element(By.ID, 'helpSafeMode') + self.assertEqual(value, elm.get_attribute('label')) + + self.assertRaises(NoSuchElementException, + self.l10n.localize_entity, dtds, 'notExistent') + + def test_dtd_entity_content(self): + dtds = ['chrome://global/locale/about.dtd', + 'chrome://global/locale/aboutSupport.dtd'] + + value = self.l10n.localize_entity(dtds, 'aboutSupport.pageTitle') + + self.marionette.set_context(self.marionette.CONTEXT_CONTENT) + self.marionette.navigate('about:support') + + elm = self.marionette.find_element(By.TAG_NAME, 'title') + self.assertEqual(value, elm.text) + + def test_properties(self): + properties = ['chrome://global/locale/filepicker.properties', + 'chrome://global/locale/findbar.properties'] + + # TODO: Find a way to verify the retrieved translated string + value = self.l10n.localize_property(properties, 'NotFound') + self.assertNotEqual(value, '') + + self.assertRaises(NoSuchElementException, + self.l10n.localize_property, properties, 'notExistent') diff --git a/testing/firefox-ui/tests/puppeteer/test_menubar.py b/testing/firefox-ui/tests/puppeteer/test_menubar.py new file mode 100644 index 000000000..ddc6117bf --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_menubar.py @@ -0,0 +1,30 @@ +# 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.errors import NoSuchElementException +from marionette_harness import MarionetteTestCase + + +class TestMenuBar(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestMenuBar, self).setUp() + + def test_click_item_in_menubar(self): + def opener(_): + self.browser.menubar.select_by_id('file-menu', + 'menu_newNavigatorTab') + + self.browser.tabbar.open_tab(trigger=opener) + + self.browser.tabbar.tabs[-1].close() + + def test_click_non_existent_menu_and_item(self): + with self.assertRaises(NoSuchElementException): + self.browser.menubar.select_by_id('foobar-menu', + 'menu_newNavigatorTab') + + with self.assertRaises(NoSuchElementException): + self.browser.menubar.select_by_id('file-menu', 'menu_foobar') diff --git a/testing/firefox-ui/tests/puppeteer/test_notifications.py b/testing/firefox-ui/tests/puppeteer/test_notifications.py new file mode 100644 index 000000000..de44c7434 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_notifications.py @@ -0,0 +1,82 @@ +# 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.notifications import ( + AddOnInstallFailedNotification, + AddOnInstallConfirmationNotification, +) +from marionette_driver import By +from marionette_driver.errors import TimeoutException +from marionette_harness import MarionetteTestCase + + +class TestNotifications(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestNotifications, self).setUp() + + self.marionette.set_pref('extensions.install.requireSecureOrigin', False) + + self.addons_url = self.marionette.absolute_url('addons/extensions/') + self.puppeteer.utils.permissions.add(self.marionette.baseurl, 'install') + + def tearDown(self): + try: + self.marionette.clear_pref('extensions.install.requireSecureOrigin') + self.marionette.clear_pref('xpinstall.signatures.required') + + self.puppeteer.utils.permissions.remove(self.addons_url, 'install') + + if self.browser.notification: + self.browser.notification.close(force=True) + finally: + super(TestNotifications, self).tearDown() + + def test_open_close_notification(self): + """Trigger and dismiss a notification""" + self.assertIsNone(self.browser.notification) + self.trigger_addon_notification('restartless_addon_signed.xpi') + self.browser.notification.close() + self.assertIsNone(self.browser.notification) + + def test_wait_for_notification_timeout(self): + """Wait for a notification when one is not shown""" + message = 'No notification was shown' + with self.assertRaisesRegexp(TimeoutException, message): + self.browser.wait_for_notification() + + def test_wait_for_specific_notification_timeout(self): + """Wait for a notification when one is not shown""" + message = 'AddOnInstallFailedNotification was not shown' + with self.assertRaisesRegexp(TimeoutException, message): + self.browser.wait_for_notification(AddOnInstallFailedNotification) + + def test_wait_for_no_notification_timeout(self): + """Wait for no notification when one is shown""" + message = 'Unexpected notification shown' + self.trigger_addon_notification('restartless_addon_signed.xpi') + with self.assertRaisesRegexp(TimeoutException, message): + self.browser.wait_for_notification(None) + + def test_notification_with_origin(self): + """Trigger a notification with an origin""" + self.trigger_addon_notification('restartless_addon_signed.xpi') + self.assertIn(self.browser.notification.origin, self.marionette.baseurl) + self.assertIsNotNone(self.browser.notification.label) + + def test_addon_install_failed_notification(self): + """Trigger add-on blocked notification using an unsigned add-on""" + # Ensure that installing unsigned extensions will fail + self.marionette.set_pref('xpinstall.signatures.required', True) + + self.trigger_addon_notification( + 'restartless_addon_unsigned.xpi', + notification=AddOnInstallFailedNotification) + + def trigger_addon_notification(self, addon, notification=AddOnInstallConfirmationNotification): + with self.marionette.using_context('content'): + self.marionette.navigate(self.addons_url) + self.marionette.find_element(By.LINK_TEXT, addon).click() + self.browser.wait_for_notification(notification) diff --git a/testing/firefox-ui/tests/puppeteer/test_page_info_window.py b/testing/firefox-ui/tests/puppeteer/test_page_info_window.py new file mode 100644 index 000000000..d86cbee3c --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_page_info_window.py @@ -0,0 +1,100 @@ +# 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 TestPageInfoWindow(PuppeteerMixin, MarionetteTestCase): + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + finally: + super(TestPageInfoWindow, self).tearDown() + + def test_elements(self): + """Test correct retrieval of elements.""" + page_info = self.browser.open_page_info_window() + + self.assertNotEqual(page_info.dtds, []) + self.assertNotEqual(page_info.properties, []) + + self.assertEqual(page_info.deck.element.get_property('localName'), 'deck') + + # feed panel + self.assertEqual(page_info.deck.feed.element.get_property('localName'), 'vbox') + + # general panel + self.assertEqual(page_info.deck.general.element.get_property('localName'), 'vbox') + + # media panel + self.assertEqual(page_info.deck.media.element.get_property('localName'), 'vbox') + + # permissions panel + self.assertEqual(page_info.deck.permissions.element.get_property('localName'), 'vbox') + + # security panel + panel = page_info.deck.select(page_info.deck.security) + + self.assertEqual(panel.element.get_property('localName'), 'vbox') + + self.assertEqual(panel.domain.get_property('localName'), 'textbox') + self.assertEqual(panel.owner.get_property('localName'), 'textbox') + self.assertEqual(panel.verifier.get_property('localName'), 'textbox') + + self.assertEqual(panel.view_certificate.get_property('localName'), 'button') + self.assertEqual(panel.view_cookies.get_property('localName'), 'button') + self.assertEqual(panel.view_passwords.get_property('localName'), 'button') + + def test_select(self): + """Test properties and methods for switching between panels.""" + page_info = self.browser.open_page_info_window() + deck = page_info.deck + + self.assertEqual(deck.selected_panel, deck.general) + + self.assertEqual(deck.select(deck.security), deck.security) + self.assertEqual(deck.selected_panel, deck.security) + + def test_open_window(self): + """Test various opening strategies.""" + def opener(win): + self.browser.menubar.select_by_id('tools-menu', 'menu_pageInfo') + + open_strategies = ('menu', + 'shortcut', + opener, + ) + + for trigger in open_strategies: + if trigger == 'shortcut' and self.puppeteer.platform == 'windows_nt': + # The shortcut for page info window does not exist on windows. + self.assertRaises(ValueError, self.browser.open_page_info_window, + trigger=trigger) + continue + + page_info = self.browser.open_page_info_window(trigger=trigger) + self.assertEquals(page_info, self.puppeteer.windows.current) + page_info.close() + + def test_close_window(self): + """Test various closing strategies.""" + def closer(win): + win.send_shortcut(win.localize_entity('closeWindow.key'), + accel=True) + + # Close a tab by each trigger method + close_strategies = ('menu', + 'shortcut', + closer, + ) + for trigger in close_strategies: + # menu only works on OS X + if trigger == 'menu' and self.puppeteer.platform != 'darwin': + continue + + page_info = self.browser.open_page_info_window() + page_info.close(trigger=trigger) + self.assertTrue(page_info.closed) diff --git a/testing/firefox-ui/tests/puppeteer/test_places.py b/testing/firefox-ui/tests/puppeteer/test_places.py new file mode 100644 index 000000000..95d0f23a4 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_places.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 By, Wait +from marionette_harness import MarionetteTestCase + + +class TestPlaces(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestPlaces, self).setUp() + + self.urls = [self.marionette.absolute_url('layout/mozilla_governance.html'), + self.marionette.absolute_url('layout/mozilla_grants.html'), + ] + + def tearDown(self): + try: + self.puppeteer.places.restore_default_bookmarks() + self.puppeteer.places.remove_all_history() + finally: + super(TestPlaces, self).tearDown() + + def get_all_urls_in_history(self): + return self.marionette.execute_script(""" + let hs = Components.classes["@mozilla.org/browser/nav-history-service;1"] + .getService(Components.interfaces.nsINavHistoryService); + let urls = []; + + let options = hs.getNewQueryOptions(); + options.resultType = options.RESULTS_AS_URI; + + let root = hs.executeQuery(hs.getNewQuery(), options).root + root.containerOpen = true; + for (let i = 0; i < root.childCount; i++) { + urls.push(root.getChild(i).uri) + } + root.containerOpen = false; + + return urls; + """) + + def test_plugins(self): + # TODO: Once we use a plugin, add a test case to verify that the data will be removed + self.puppeteer.places.clear_plugin_data() + + def test_bookmarks(self): + star_button = self.marionette.find_element(By.ID, 'bookmarks-menu-button') + + # Visit URLs and bookmark them all + for url in self.urls: + with self.marionette.using_context('content'): + self.marionette.navigate(url) + + Wait(self.marionette).until( + lambda _: self.puppeteer.places.is_bookmark_star_button_ready()) + star_button.click() + Wait(self.marionette).until(lambda _: self.puppeteer.places.is_bookmarked(url)) + + ids = self.puppeteer.places.get_folder_ids_for_url(url) + self.assertEqual(len(ids), 1) + self.assertEqual(ids[0], self.puppeteer.places.bookmark_folders.unfiled) + + # Restore default bookmarks, so the added URLs are gone + self.puppeteer.places.restore_default_bookmarks() + for url in self.urls: + self.assertFalse(self.puppeteer.places.is_bookmarked(url)) + + def test_history(self): + self.assertEqual(len(self.get_all_urls_in_history()), 0) + + # Visit pages and check that they are all present + def load_urls(): + with self.marionette.using_context('content'): + for url in self.urls: + self.marionette.navigate(url) + self.puppeteer.places.wait_for_visited(self.urls, load_urls) + + self.assertEqual(self.get_all_urls_in_history(), self.urls) + + # Check that both pages are no longer in the remove_all_history + self.puppeteer.places.remove_all_history() + self.assertEqual(len(self.get_all_urls_in_history()), 0) diff --git a/testing/firefox-ui/tests/puppeteer/test_security.py b/testing/firefox-ui/tests/puppeteer/test_security.py new file mode 100644 index 000000000..879053e5a --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_security.py @@ -0,0 +1,45 @@ +# 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.errors import NoCertificateError +from marionette_harness import MarionetteTestCase + + +class TestSecurity(PuppeteerMixin, MarionetteTestCase): + + def test_get_address_from_certificate(self): + url = 'https://ssl-ev.mozqa.com' + + with self.marionette.using_context(self.marionette.CONTEXT_CONTENT): + self.marionette.navigate(url) + + cert = self.browser.tabbar.tabs[0].certificate + self.assertIn(cert['commonName'], url) + self.assertEqual(cert['organization'], 'Mozilla Corporation') + self.assertEqual(cert['issuerOrganization'], 'DigiCert Inc') + + address = self.puppeteer.security.get_address_from_certificate(cert) + self.assertIsNotNone(address) + self.assertIsNotNone(address['city']) + self.assertIsNotNone(address['country']) + self.assertIsNotNone(address['postal_code']) + self.assertIsNotNone(address['state']) + self.assertIsNotNone(address['street']) + + def test_get_certificate(self): + url_http = self.marionette.absolute_url('layout/mozilla.html') + url_https = 'https://ssl-ev.mozqa.com' + + # Test EV certificate + with self.marionette.using_context(self.marionette.CONTEXT_CONTENT): + self.marionette.navigate(url_https) + cert = self.browser.tabbar.tabs[0].certificate + self.assertIn(cert['commonName'], url_https) + + # HTTP connections do not have a SSL certificate + with self.marionette.using_context(self.marionette.CONTEXT_CONTENT): + self.marionette.navigate(url_http) + with self.assertRaises(NoCertificateError): + self.browser.tabbar.tabs[0].certificate diff --git a/testing/firefox-ui/tests/puppeteer/test_software_update.py b/testing/firefox-ui/tests/puppeteer/test_software_update.py new file mode 100644 index 000000000..4bad47d94 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_software_update.py @@ -0,0 +1,134 @@ +# 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 firefox_puppeteer.api.software_update import SoftwareUpdate +from marionette_harness import MarionetteTestCase + + +class TestSoftwareUpdate(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestSoftwareUpdate, self).setUp() + + self.software_update = SoftwareUpdate(self.marionette) + + self.saved_mar_channels = self.software_update.mar_channels.channels + self.software_update.mar_channels.channels = set(['expected', 'channels']) + + def tearDown(self): + try: + self.software_update.mar_channels.channels = self.saved_mar_channels + finally: + super(TestSoftwareUpdate, self).tearDown() + + def test_abi(self): + self.assertTrue(self.software_update.ABI) + + def test_allowed(self): + self.assertTrue(self.software_update.allowed) + + def test_build_info(self): + build_info = self.software_update.build_info + self.assertEqual(build_info['disabled_addons'], None) + self.assertIn('Mozilla/', build_info['user_agent']) + self.assertEqual(build_info['mar_channels'], set(['expected', 'channels'])) + self.assertTrue(build_info['version']) + self.assertTrue(build_info['buildid'].isdigit()) + self.assertTrue(build_info['locale']) + self.assertIn('force=1', build_info['update_url']) + self.assertIn('xml', build_info['update_snippet']) + self.assertEqual(build_info['channel'], self.software_update.update_channel) + + def test_force_fallback(self): + status_file = os.path.join(self.software_update.staging_directory, 'update.status') + + try: + self.software_update.force_fallback() + with open(status_file, 'r') as f: + content = f.read() + self.assertEqual(content, 'failed: 6\n') + finally: + os.remove(status_file) + + def test_get_update_url(self): + update_url = self.software_update.get_update_url() + self.assertIn('Firefox', update_url) + self.assertNotIn('force=1', update_url) + update_url = self.software_update.get_update_url(True) + self.assertIn('Firefox', update_url) + self.assertIn('force=1', update_url) + + def test_os_version(self): + self.assertTrue(self.software_update.os_version) + + def test_staging_directory(self): + self.assertTrue(self.software_update.staging_directory) + + +class TestUpdateChannel(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestUpdateChannel, self).setUp() + + self.software_update = SoftwareUpdate(self.marionette) + + self.saved_channel = self.software_update.update_channel + self.software_update.update_channel = 'expected_channel' + + def tearDown(self): + try: + self.software_update.update_channel = self.saved_channel + finally: + super(TestUpdateChannel, self).tearDown() + + def test_update_channel_default_channel(self): + # Without a restart the update channel will not change. + self.assertEqual(self.software_update.update_channel, self.saved_channel) + + def test_update_channel_set_channel(self): + try: + # Use the clean option to force a non in_app restart, which would allow + # Firefox to dump the logs to the console. + self.restart(clean=True) + self.assertEqual(self.software_update.update_channel, 'expected_channel') + finally: + self.software_update.update_channel = self.saved_channel + self.restart(clean=True) + + +class TestMARChannels(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestMARChannels, self).setUp() + + self.software_update = SoftwareUpdate(self.marionette) + + self.saved_mar_channels = self.software_update.mar_channels.channels + self.software_update.mar_channels.channels = set(['expected', 'channels']) + + def tearDown(self): + try: + self.software_update.mar_channels.channels = self.saved_mar_channels + finally: + super(TestMARChannels, self).tearDown() + + def test_mar_channels_channels(self): + self.assertEqual(self.software_update.mar_channels.channels, set(['expected', 'channels'])) + + def test_mar_channels_set_channels(self): + self.software_update.mar_channels.channels = set(['a', 'b', 'c']) + self.assertEqual(self.software_update.mar_channels.channels, set(['a', 'b', 'c'])) + + def test_mar_channels_add_channels(self): + self.software_update.mar_channels.add_channels(set(['some', 'new', 'channels'])) + self.assertEqual( + self.software_update.mar_channels.channels, + set(['expected', 'channels', 'some', 'new'])) + + def test_mar_channels_remove_channels(self): + self.software_update.mar_channels.remove_channels(set(['expected'])) + self.assertEqual(self.software_update.mar_channels.channels, set(['channels'])) diff --git a/testing/firefox-ui/tests/puppeteer/test_tabbar.py b/testing/firefox-ui/tests/puppeteer/test_tabbar.py new file mode 100644 index 000000000..7da3f7ee7 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_tabbar.py @@ -0,0 +1,191 @@ +# 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.errors import NoCertificateError +from marionette_harness import MarionetteTestCase + + +class TestTabBar(PuppeteerMixin, MarionetteTestCase): + + def tearDown(self): + try: + self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]]) + finally: + super(TestTabBar, self).tearDown() + + def test_basics(self): + tabbar = self.browser.tabbar + + self.assertEqual(tabbar.window, self.browser) + + self.assertEqual(len(tabbar.tabs), 1) + self.assertEqual(tabbar.tabs[0].handle, self.marionette.current_window_handle) + + self.assertEqual(tabbar.newtab_button.get_property('localName'), 'toolbarbutton') + self.assertEqual(tabbar.toolbar.get_property('localName'), 'tabs') + + def test_open_close(self): + tabbar = self.browser.tabbar + + self.assertEqual(len(tabbar.tabs), 1) + self.assertEqual(tabbar.selected_index, 0) + + # Open with default trigger, and force closing the tab + tabbar.open_tab() + tabbar.close_tab(force=True) + + # Open a new tab by each trigger method + open_strategies = ('button', + 'menu', + 'shortcut', + lambda tab: tabbar.newtab_button.click() + ) + for trigger in open_strategies: + new_tab = tabbar.open_tab(trigger=trigger) + self.assertEqual(len(tabbar.tabs), 2) + self.assertEqual(new_tab.handle, self.marionette.current_window_handle) + self.assertEqual(new_tab.handle, tabbar.tabs[1].handle) + + tabbar.close_tab() + self.assertEqual(len(tabbar.tabs), 1) + self.assertEqual(tabbar.tabs[0].handle, self.marionette.current_window_handle) + self.assertNotEqual(new_tab.handle, tabbar.tabs[0].handle) + + # Close a tab by each trigger method + close_strategies = ('button', + 'menu', + 'shortcut', + lambda tab: tab.close_button.click()) + for trigger in close_strategies: + new_tab = tabbar.open_tab() + self.assertEqual(len(tabbar.tabs), 2) + self.assertEqual(new_tab.handle, self.marionette.current_window_handle) + self.assertEqual(new_tab.handle, tabbar.tabs[1].handle) + + tabbar.close_tab(trigger=trigger) + self.assertEqual(len(tabbar.tabs), 1) + self.assertEqual(tabbar.tabs[0].handle, self.marionette.current_window_handle) + self.assertNotEqual(new_tab.handle, tabbar.tabs[0].handle) + + def test_close_not_selected_tab(self): + tabbar = self.browser.tabbar + + new_tab = tabbar.open_tab() + tabbar.close_tab(tabbar.tabs[0], trigger="button") + + self.assertEqual(len(tabbar.tabs), 1) + self.assertEqual(new_tab, tabbar.tabs[0]) + + def test_close_all_tabs_except_first(self): + tabbar = self.browser.tabbar + + orig_tab = tabbar.tabs[0] + + for i in range(0, 3): + tabbar.open_tab() + + tabbar.close_all_tabs([orig_tab]) + self.assertEqual(len(tabbar.tabs), 1) + self.assertEqual(orig_tab.handle, self.marionette.current_window_handle) + + def test_switch_to(self): + tabbar = self.browser.tabbar + + # Open a new tab in the foreground (will be auto-selected) + new_tab = tabbar.open_tab() + self.assertEqual(new_tab.handle, self.marionette.current_window_handle) + self.assertEqual(tabbar.selected_index, 1) + self.assertEqual(tabbar.selected_tab, new_tab) + + # Switch by index + tabbar.switch_to(0) + self.assertEqual(tabbar.tabs[0].handle, self.marionette.current_window_handle) + + # Switch by tab + tabbar.switch_to(new_tab) + self.assertEqual(new_tab.handle, self.marionette.current_window_handle) + + # Switch by callback + tabbar.switch_to(lambda tab: tab.window.tabbar.selected_tab != tab) + self.assertEqual(tabbar.tabs[0].handle, self.marionette.current_window_handle) + + tabbar.close_tab(tabbar.tabs[1]) + + +class TestTab(PuppeteerMixin, MarionetteTestCase): + + def tearDown(self): + try: + self.browser.tabbar.close_all_tabs([self.browser.tabbar.tabs[0]]) + finally: + super(TestTab, self).tearDown() + + def test_basic(self): + tab = self.browser.tabbar.tabs[0] + + self.assertEqual(tab.window, self.browser) + + self.assertEqual(tab.tab_element.get_property('localName'), 'tab') + self.assertEqual(tab.close_button.get_property('localName'), 'toolbarbutton') + + def test_certificate(self): + url = self.marionette.absolute_url('layout/mozilla.html') + + with self.marionette.using_context(self.marionette.CONTEXT_CONTENT): + self.marionette.navigate(url) + with self.assertRaises(NoCertificateError): + self.browser.tabbar.tabs[0].certificate + + def test_close(self): + tabbar = self.browser.tabbar + + self.assertEqual(len(tabbar.tabs), 1) + self.assertEqual(tabbar.selected_index, 0) + + # Force closing the tab + new_tab = tabbar.open_tab() + new_tab.close(force=True) + + # Close a tab by each trigger method + close_strategies = ('button', + 'menu', + 'shortcut', + lambda tab: tab.close_button.click()) + for trigger in close_strategies: + new_tab = tabbar.open_tab() + self.assertEqual(len(tabbar.tabs), 2) + self.assertEqual(new_tab.handle, self.marionette.current_window_handle) + self.assertEqual(new_tab.handle, tabbar.tabs[1].handle) + + new_tab.close(trigger=trigger) + self.assertEqual(len(tabbar.tabs), 1) + self.assertEqual(tabbar.tabs[0].handle, self.marionette.current_window_handle) + self.assertNotEqual(new_tab.handle, tabbar.tabs[0].handle) + + def test_location(self): + url = self.marionette.absolute_url('layout/mozilla.html') + with self.marionette.using_context(self.marionette.CONTEXT_CONTENT): + self.marionette.navigate(url) + self.assertEqual(self.browser.tabbar.tabs[0].location, url) + + def test_switch_to(self): + tabbar = self.browser.tabbar + + new_tab = tabbar.open_tab() + + # Switch to the first tab, which will not select it + tabbar.tabs[0].switch_to() + self.assertEqual(tabbar.tabs[0].handle, self.marionette.current_window_handle) + # Bug 1128656: We cannot test as long as switch_to_window() auto-selects the tab + # self.assertEqual(tabbar.selected_index, 1) + # self.assertEqual(tabbar.selected_tab, new_tab) + + # Now select the first tab + tabbar.tabs[0].select() + self.assertEqual(tabbar.tabs[0].handle, self.marionette.current_window_handle) + self.assertTrue(tabbar.tabs[0].selected) + self.assertFalse(tabbar.tabs[1].selected) + + new_tab.close() diff --git a/testing/firefox-ui/tests/puppeteer/test_toolbars.py b/testing/firefox-ui/tests/puppeteer/test_toolbars.py new file mode 100644 index 000000000..8150be7e1 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_toolbars.py @@ -0,0 +1,283 @@ +# 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 expected, By, Wait +from marionette_driver.errors import NoSuchElementException +from marionette_harness import MarionetteTestCase + + +class TestNavBar(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestNavBar, self).setUp() + + self.navbar = self.browser.navbar + self.url = self.marionette.absolute_url('layout/mozilla.html') + + with self.marionette.using_context('content'): + self.marionette.navigate('about:blank') + + # TODO: check why self.puppeteer.places.remove_all_history() does not work here + self.marionette.execute_script(""" + let count = gBrowser.sessionHistory.count; + gBrowser.sessionHistory.PurgeHistory(count); + """) + + def test_elements(self): + self.assertEqual(self.navbar.back_button.get_property('localName'), 'toolbarbutton') + self.assertEqual(self.navbar.forward_button.get_property('localName'), 'toolbarbutton') + self.assertEqual(self.navbar.home_button.get_property('localName'), 'toolbarbutton') + self.assertEqual(self.navbar.menu_button.get_property('localName'), 'toolbarbutton') + self.assertEqual(self.navbar.toolbar.get_property('localName'), 'toolbar') + + def test_buttons(self): + self.marionette.set_context('content') + + # Load initial web page + self.marionette.navigate(self.url) + Wait(self.marionette).until(expected.element_present(lambda m: + m.find_element(By.ID, 'mozilla_logo'))) + + with self.marionette.using_context('chrome'): + # Both buttons are disabled + self.assertFalse(self.navbar.back_button.is_enabled()) + self.assertFalse(self.navbar.forward_button.is_enabled()) + + # Go to the homepage + self.navbar.home_button.click() + + Wait(self.marionette).until(expected.element_not_present(lambda m: + m.find_element(By.ID, 'mozilla_logo'))) + self.assertEqual(self.marionette.get_url(), self.browser.default_homepage) + + with self.marionette.using_context('chrome'): + # Only back button is enabled + self.assertTrue(self.navbar.back_button.is_enabled()) + self.assertFalse(self.navbar.forward_button.is_enabled()) + + # Navigate back + self.navbar.back_button.click() + + Wait(self.marionette).until(expected.element_present(lambda m: + m.find_element(By.ID, 'mozilla_logo'))) + self.assertEqual(self.marionette.get_url(), self.url) + + with self.marionette.using_context('chrome'): + # Only forward button is enabled + self.assertFalse(self.navbar.back_button.is_enabled()) + self.assertTrue(self.navbar.forward_button.is_enabled()) + + # Navigate forward + self.navbar.forward_button.click() + + Wait(self.marionette).until(expected.element_not_present(lambda m: + m.find_element(By.ID, 'mozilla_logo'))) + self.assertEqual(self.marionette.get_url(), self.browser.default_homepage) + + +class TestLocationBar(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestLocationBar, self).setUp() + + self.locationbar = self.browser.navbar.locationbar + + def test_elements(self): + self.assertEqual(self.locationbar.urlbar.get_property('localName'), 'textbox') + self.assertIn('urlbar-input', self.locationbar.urlbar_input.get_property('className')) + + self.assertEqual(self.locationbar.connection_icon.get_property('localName'), 'image') + self.assertEqual(self.locationbar.identity_box.get_property('localName'), 'box') + self.assertEqual(self.locationbar.identity_country_label.get_property('localName'), + 'label') + self.assertEqual(self.locationbar.identity_organization_label.get_property('localName'), + 'label') + self.assertEqual(self.locationbar.identity_icon.get_property('localName'), 'image') + self.assertEqual(self.locationbar.history_drop_marker.get_property('localName'), + 'dropmarker') + self.assertEqual(self.locationbar.reload_button.get_property('localName'), + 'toolbarbutton') + self.assertEqual(self.locationbar.stop_button.get_property('localName'), + 'toolbarbutton') + + self.assertEqual(self.locationbar.contextmenu.get_property('localName'), 'menupopup') + self.assertEqual(self.locationbar.get_contextmenu_entry('paste').get_attribute('cmd'), + 'cmd_paste') + + def test_reload(self): + event_types = ["shortcut", "shortcut2", "button"] + for event in event_types: + # TODO: Until we have waitForPageLoad, this only tests API + # compatibility. + self.locationbar.reload_url(event, force=True) + self.locationbar.reload_url(event, force=False) + + def test_focus_and_clear(self): + self.locationbar.urlbar.send_keys("zyx") + self.locationbar.clear() + self.assertEqual(self.locationbar.value, '') + + self.locationbar.urlbar.send_keys("zyx") + self.assertEqual(self.locationbar.value, 'zyx') + + self.locationbar.clear() + self.assertEqual(self.locationbar.value, '') + + def test_load_url(self): + data_uri = 'data:text/html,<title>Title</title>' + self.locationbar.load_url(data_uri) + + with self.marionette.using_context('content'): + Wait(self.marionette).until(lambda mn: mn.get_url() == data_uri) + + +class TestAutoCompleteResults(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestAutoCompleteResults, self).setUp() + + self.browser.navbar.locationbar.clear() + + self.autocomplete_results = self.browser.navbar.locationbar.autocomplete_results + + def tearDown(self): + try: + self.autocomplete_results.close(force=True) + except NoSuchElementException: + # TODO: A NoSuchElementException is thrown here when tests accessing the + # autocomplete_results element are skipped. + pass + finally: + super(TestAutoCompleteResults, self).tearDown() + + def test_popup_elements(self): + # TODO: This test is not very robust because it relies on the history + # in the default profile. + self.assertFalse(self.autocomplete_results.is_open) + self.browser.navbar.locationbar.urlbar.send_keys('a') + results = self.autocomplete_results.results + Wait(self.marionette).until(lambda _: self.autocomplete_results.is_complete) + visible_result_count = len(self.autocomplete_results.visible_results) + self.assertTrue(visible_result_count > 0) + self.assertEqual(visible_result_count, + int(results.get_property('itemCount'))) + + def test_close(self): + self.browser.navbar.locationbar.urlbar.send_keys('a') + Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open) + # The Wait in the library implementation will fail this if this doesn't + # end up closing. + self.autocomplete_results.close() + + def test_force_close(self): + self.browser.navbar.locationbar.urlbar.send_keys('a') + Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open) + # The Wait in the library implementation will fail this if this doesn't + # end up closing. + self.autocomplete_results.close(force=True) + + def test_matching_text(self): + # The default profile always has existing bookmarks. So no sites have to + # be visited and bookmarked. + for input_text in ('about', 'zilla'): + self.browser.navbar.locationbar.urlbar.clear() + self.browser.navbar.locationbar.urlbar.send_keys(input_text) + Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open) + Wait(self.marionette).until(lambda _: self.autocomplete_results.is_complete) + visible_results = self.autocomplete_results.visible_results + self.assertTrue(len(visible_results) > 0) + + for result in visible_results: + # check matching text only for results of type bookmark + if result.get_attribute('type') != 'bookmark': + continue + title_matches = self.autocomplete_results.get_matching_text(result, "title") + url_matches = self.autocomplete_results.get_matching_text(result, "url") + all_matches = title_matches + url_matches + self.assertTrue(len(all_matches) > 0) + for match_fragment in all_matches: + self.assertIn(match_fragment.lower(), input_text) + + self.autocomplete_results.close() + + +class TestIdentityPopup(PuppeteerMixin, MarionetteTestCase): + def setUp(self): + super(TestIdentityPopup, self).setUp() + + self.locationbar = self.browser.navbar.locationbar + self.identity_popup = self.locationbar.identity_popup + + self.url = 'https://ssl-ev.mozqa.com' + + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + def tearDown(self): + try: + self.identity_popup.close(force=True) + finally: + super(TestIdentityPopup, self).tearDown() + + def test_elements(self): + self.locationbar.open_identity_popup() + + # Test main view elements + main = self.identity_popup.view.main + self.assertEqual(main.element.get_property('localName'), 'panelview') + + self.assertEqual(main.expander.get_property('localName'), 'button') + self.assertEqual(main.host.get_property('localName'), 'label') + self.assertEqual(main.insecure_connection_label.get_property('localName'), + 'description') + self.assertEqual(main.internal_connection_label.get_property('localName'), + 'description') + self.assertEqual(main.secure_connection_label.get_property('localName'), + 'description') + + self.assertEqual(main.permissions.get_property('localName'), 'vbox') + + # Test security view elements + security = self.identity_popup.view.security + self.assertEqual(security.element.get_property('localName'), 'panelview') + + self.assertEqual(security.host.get_property('localName'), 'label') + self.assertEqual(security.insecure_connection_label.get_property('localName'), + 'description') + self.assertEqual(security.secure_connection_label.get_property('localName'), + 'description') + + self.assertEqual(security.owner.get_property('localName'), 'description') + self.assertEqual(security.owner_location.get_property('localName'), 'description') + self.assertEqual(security.verifier.get_property('localName'), 'description') + + self.assertEqual(security.disable_mixed_content_blocking_button.get_property('localName'), + 'button') + self.assertEqual(security.enable_mixed_content_blocking_button.get_property('localName'), + 'button') + + self.assertEqual(security.more_info_button.get_property('localName'), 'button') + + def test_open_close(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + self.assertFalse(self.identity_popup.is_open) + + self.locationbar.open_identity_popup() + + self.identity_popup.close() + self.assertFalse(self.identity_popup.is_open) + + def test_force_close(self): + with self.marionette.using_context('content'): + self.marionette.navigate(self.url) + + self.assertFalse(self.identity_popup.is_open) + + self.locationbar.open_identity_popup() + + self.identity_popup.close(force=True) + self.assertFalse(self.identity_popup.is_open) diff --git a/testing/firefox-ui/tests/puppeteer/test_update_wizard.py b/testing/firefox-ui/tests/puppeteer/test_update_wizard.py new file mode 100644 index 000000000..7170ea8e2 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_update_wizard.py @@ -0,0 +1,67 @@ +# 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.deck import Panel +from firefox_puppeteer.ui.update_wizard import UpdateWizardDialog +from marionette_harness import MarionetteTestCase + + +class TestUpdateWizard(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestUpdateWizard, self).setUp() + + def opener(win): + self.marionette.execute_script(""" + let updatePrompt = Components.classes["@mozilla.org/updates/update-prompt;1"] + .createInstance(Components.interfaces.nsIUpdatePrompt); + updatePrompt.checkForUpdates(); + """) + + self.dialog = self.browser.open_window(callback=opener, + expected_window_class=UpdateWizardDialog) + self.wizard = self.dialog.wizard + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + finally: + super(TestUpdateWizard, self).tearDown() + + def test_basic(self): + self.assertEqual(self.dialog.window_type, 'Update:Wizard') + self.assertNotEqual(self.dialog.dtds, []) + self.assertNotEqual(self.dialog.properties, []) + + def test_elements(self): + """Test correct retrieval of elements.""" + self.assertEqual(self.wizard.element.get_property('localName'), 'wizard') + + buttons = ('cancel_button', 'extra1_button', 'extra2_button', + 'finish_button', 'next_button', 'previous_button', + ) + for button in buttons: + self.assertEqual(getattr(self.wizard, button).get_property('localName'), + 'button') + + panels = ('checking', 'downloading', 'dummy', 'error_patching', 'error', + 'error_extra', 'finished', 'finished_background', + 'manual_update', 'no_updates_found', 'updates_found_basic', + ) + for panel in panels: + self.assertEqual(getattr(self.wizard, panel).element.get_property('localName'), + 'wizardpage') + + # elements of the checking panel + self.assertEqual(self.wizard.checking.progress.get_property('localName'), + 'progressmeter') + + # elements of the downloading panel + self.assertEqual(self.wizard.downloading.progress.get_property('localName'), + 'progressmeter') + + # check wizard attributes + self.assertIsInstance(self.wizard.selected_index, int) + self.assertIsInstance(self.wizard.selected_panel, Panel) diff --git a/testing/firefox-ui/tests/puppeteer/test_utils.py b/testing/firefox-ui/tests/puppeteer/test_utils.py new file mode 100644 index 000000000..664722cce --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_utils.py @@ -0,0 +1,48 @@ +# 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 TestSanitize(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + super(TestSanitize, self).setUp() + + # Clear all previous history and cookies. + self.puppeteer.places.remove_all_history() + with self.marionette.using_context('content'): + self.marionette.delete_all_cookies() + + self.urls = [ + 'layout/mozilla_projects.html', + 'layout/mozilla.html', + 'layout/mozilla_mission.html', + 'cookies/cookie_single.html' + ] + self.urls = [self.marionette.absolute_url(url) for url in self.urls] + + # Open the test urls, including the single cookie setting page. + def load_urls(): + with self.marionette.using_context('content'): + for url in self.urls: + self.marionette.navigate(url) + self.puppeteer.places.wait_for_visited(self.urls, load_urls) + + def test_sanitize_history(self): + """ Clears history. """ + self.assertEqual(self.puppeteer.places.get_all_urls_in_history(), self.urls) + self.puppeteer.utils.sanitize(data_type={"history": True}) + self.assertEqual(self.puppeteer.places.get_all_urls_in_history(), []) + + def test_sanitize_cookies(self): + """ Clears cookies. """ + with self.marionette.using_context('content'): + self.assertIsNotNone(self.marionette.get_cookie('litmus_1')) + + self.puppeteer.utils.sanitize(data_type={"cookies": True}) + + with self.marionette.using_context('content'): + self.assertIsNone(self.marionette.get_cookie('litmus_1')) diff --git a/testing/firefox-ui/tests/puppeteer/test_windows.py b/testing/firefox-ui/tests/puppeteer/test_windows.py new file mode 100644 index 000000000..1ba13fa37 --- /dev/null +++ b/testing/firefox-ui/tests/puppeteer/test_windows.py @@ -0,0 +1,259 @@ +# 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 firefox_puppeteer.errors as errors + +from firefox_puppeteer import PuppeteerMixin +from firefox_puppeteer.ui.windows import BaseWindow +from marionette_driver import By, Wait +from marionette_driver.errors import NoSuchWindowException +from marionette_harness import MarionetteTestCase + + +class BaseWindowTestCase(PuppeteerMixin, MarionetteTestCase): + + def setUp(self): + """ + These tests open and close windows pretty rapidly, which + (since bug 1261842) can cause content processes to be + spawned and discarded in large numbers. By default, Firefox + has a 5 second timeout for shutting down content processes, + but we can get into cases where the content process just + doesn't have enough time to get itself all sorted before + the timeout gets hit, which results in the parent killing + the content process manually, which generates a crash report, + which causes these tests to orange. We side-step this by + setting dom.ipc.tabs.shutdownTimeoutSecs to 0, which disables + the shutdown timer. + """ + super(BaseWindowTestCase, self).setUp() + + self.marionette.set_pref('dom.ipc.tabs.shutdownTimeoutSecs', 0) + + def tearDown(self): + try: + self.marionette.clear_pref('dom.ipc.tabs.shutdownTimeoutSecs') + finally: + super(BaseWindowTestCase, self).tearDown() + + +class TestWindows(BaseWindowTestCase): + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + finally: + super(TestWindows, self).tearDown() + + def test_switch_to(self): + url = self.marionette.absolute_url('layout/mozilla.html') + + # Open two more windows + for index in range(0, 2): + self.marionette.execute_script(""" window.open(); """) + + windows = self.puppeteer.windows.all + self.assertEquals(len(windows), 3) + + # Switch to the 2nd window + self.puppeteer.windows.switch_to(windows[1].handle) + self.assertEquals(windows[1].handle, self.marionette.current_chrome_window_handle) + + # TODO: Needs updated tabs module for improved navigation + with self.marionette.using_context('content'): + self.marionette.navigate(url) + + # Switch to the last window and find 2nd window by URL + self.puppeteer.windows.switch_to(windows[2].handle) + + # TODO: A window can have multiple tabs, so this may need an update + # when the tabs module gets implemented + def find_by_url(win): + with win.marionette.using_context('content'): + return win.marionette.get_url() == url + + self.puppeteer.windows.switch_to(find_by_url) + self.assertEquals(windows[1].handle, self.marionette.current_chrome_window_handle) + + self.puppeteer.windows.switch_to(find_by_url) + + # Switching to an unknown handles has to fail + self.assertRaises(NoSuchWindowException, + self.puppeteer.windows.switch_to, "humbug") + self.assertRaises(NoSuchWindowException, + self.puppeteer.windows.switch_to, lambda win: False) + + self.puppeteer.windows.close_all([self.browser]) + self.browser.switch_to() + + self.assertEqual(len(self.puppeteer.windows.all), 1) + + def test_switch_to_unknown_window_type(self): + def open_by_js(_): + with self.marionette.using_context('chrome'): + self.marionette.execute_script(""" + window.open('chrome://browser/content/safeMode.xul', '_blank', + 'chrome,centerscreen,resizable=no'); + """) + + win = self.browser.open_window(callback=open_by_js, expected_window_class=BaseWindow) + win.close() + self.browser.switch_to() + + +class TestBaseWindow(BaseWindowTestCase): + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + finally: + BaseWindowTestCase.tearDown(self) + + def test_basics(self): + # force BaseWindow instance + win1 = BaseWindow(self.marionette, self.browser.handle) + + self.assertEquals(win1.handle, self.marionette.current_chrome_window_handle) + self.assertEquals(win1.window_element, + self.marionette.find_element(By.CSS_SELECTOR, ':root')) + self.assertEquals(win1.window_element.get_attribute('windowtype'), + self.marionette.get_window_type()) + self.assertFalse(win1.closed) + + # Test invalid parameters for BaseWindow constructor + self.assertRaises(errors.UnknownWindowError, + BaseWindow, self.marionette, 10) + + # Test invalid shortcuts + self.assertRaises(KeyError, + win1.send_shortcut, 'l', acel=True) + + def test_open_close(self): + # force BaseWindow instance + win1 = BaseWindow(self.marionette, self.browser.handle) + + # Open a new window (will be focused), and check states + win2 = win1.open_window() + + # force BaseWindow instance + win2 = BaseWindow(self.marionette, win2.handle) + + self.assertEquals(len(self.marionette.chrome_window_handles), 2) + self.assertNotEquals(win1.handle, win2.handle) + self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) + + win2.close() + + self.assertTrue(win2.closed) + self.assertEquals(len(self.marionette.chrome_window_handles), 1) + self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) + Wait(self.marionette).until(lambda _: win1.focused) # catch the no focused window + + win1.focus() + + # Open and close a new window by a custom callback + def opener(window): + window.marionette.execute_script(""" window.open(); """) + + def closer(window): + window.marionette.execute_script(""" window.close(); """) + + win2 = win1.open_window(callback=opener) + + # force BaseWindow instance + win2 = BaseWindow(self.marionette, win2.handle) + + self.assertEquals(len(self.marionette.chrome_window_handles), 2) + win2.close(callback=closer) + + win1.focus() + + # Check for an unexpected window class + self.assertRaises(errors.UnexpectedWindowTypeError, + win1.open_window, expected_window_class=BaseWindow) + self.puppeteer.windows.close_all([win1]) + + def test_switch_to_and_focus(self): + # force BaseWindow instance + win1 = BaseWindow(self.marionette, self.browser.handle) + + # Open a new window (will be focused), and check states + win2 = win1.open_window() + + # force BaseWindow instance + win2 = BaseWindow(self.marionette, win2.handle) + + self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) + self.assertEquals(win2.handle, self.puppeteer.windows.focused_chrome_window_handle) + self.assertFalse(win1.focused) + self.assertTrue(win2.focused) + + # Switch back to win1 without moving the focus, but focus separately + win1.switch_to() + self.assertEquals(win1.handle, self.marionette.current_chrome_window_handle) + self.assertTrue(win2.focused) + + win1.focus() + self.assertTrue(win1.focused) + + # Switch back to win2 by focusing it directly + win2.focus() + self.assertEquals(win2.handle, self.marionette.current_chrome_window_handle) + self.assertEquals(win2.handle, self.puppeteer.windows.focused_chrome_window_handle) + self.assertTrue(win2.focused) + + # Close win2, and check that it keeps active but looses focus + win2.switch_to() + win2.close() + + win1.switch_to() + + +class TestBrowserWindow(BaseWindowTestCase): + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + finally: + BaseWindowTestCase.tearDown(self) + + def test_basic(self): + self.assertNotEqual(self.browser.dtds, []) + self.assertNotEqual(self.browser.properties, []) + + self.assertFalse(self.browser.is_private) + + self.assertIsNotNone(self.browser.menubar) + self.assertIsNotNone(self.browser.navbar) + self.assertIsNotNone(self.browser.tabbar) + + def test_open_close(self): + # open and close a new browser windows by menu + win2 = self.browser.open_browser(trigger='menu') + self.assertEquals(win2, self.puppeteer.windows.current) + self.assertFalse(self.browser.is_private) + win2.close(trigger='menu') + + # open and close a new browser window by shortcut + win2 = self.browser.open_browser(trigger='shortcut') + self.assertEquals(win2, self.puppeteer.windows.current) + self.assertFalse(self.browser.is_private) + win2.close(trigger='shortcut') + + # open and close a new private browsing window + win2 = self.browser.open_browser(is_private=True) + self.assertEquals(win2, self.puppeteer.windows.current) + self.assertTrue(win2.is_private) + win2.close() + + # open and close a new private browsing window + win2 = self.browser.open_browser(trigger='shortcut', is_private=True) + self.assertEquals(win2, self.puppeteer.windows.current) + self.assertTrue(win2.is_private) + win2.close() + + # force closing a window + win2 = self.browser.open_browser() + self.assertEquals(win2, self.puppeteer.windows.current) + win2.close(force=True) diff --git a/testing/firefox-ui/tests/update/direct/manifest.ini b/testing/firefox-ui/tests/update/direct/manifest.ini new file mode 100644 index 000000000..f5edb3c10 --- /dev/null +++ b/testing/firefox-ui/tests/update/direct/manifest.ini @@ -0,0 +1,4 @@ +[DEFAULT] +tags = direct + +[test_direct_update.py] diff --git a/testing/firefox-ui/tests/update/direct/test_direct_update.py b/testing/firefox-ui/tests/update/direct/test_direct_update.py new file mode 100644 index 000000000..41842349e --- /dev/null +++ b/testing/firefox-ui/tests/update/direct/test_direct_update.py @@ -0,0 +1,21 @@ +# 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_ui_harness.testcases import UpdateTestCase + + +class TestDirectUpdate(UpdateTestCase): + + def setUp(self): + UpdateTestCase.setUp(self, is_fallback=False) + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + finally: + UpdateTestCase.tearDown(self) + + def test_update(self): + self.download_and_apply_available_update(force_fallback=False) + self.check_update_applied() diff --git a/testing/firefox-ui/tests/update/fallback/manifest.ini b/testing/firefox-ui/tests/update/fallback/manifest.ini new file mode 100644 index 000000000..704686db7 --- /dev/null +++ b/testing/firefox-ui/tests/update/fallback/manifest.ini @@ -0,0 +1,4 @@ +[DEFAULT] +tags = fallback + +[test_fallback_update.py] diff --git a/testing/firefox-ui/tests/update/fallback/test_fallback_update.py b/testing/firefox-ui/tests/update/fallback/test_fallback_update.py new file mode 100644 index 000000000..264142bd8 --- /dev/null +++ b/testing/firefox-ui/tests/update/fallback/test_fallback_update.py @@ -0,0 +1,22 @@ +# 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_ui_harness.testcases import UpdateTestCase + + +class TestFallbackUpdate(UpdateTestCase): + + def setUp(self): + UpdateTestCase.setUp(self, is_fallback=True) + + def tearDown(self): + try: + self.puppeteer.windows.close_all([self.browser]) + finally: + UpdateTestCase.tearDown(self) + + def test_update(self): + self.download_and_apply_available_update(force_fallback=True) + self.download_and_apply_forced_update() + self.check_update_applied() diff --git a/testing/firefox-ui/tests/update/manifest.ini b/testing/firefox-ui/tests/update/manifest.ini new file mode 100644 index 000000000..2a126e331 --- /dev/null +++ b/testing/firefox-ui/tests/update/manifest.ini @@ -0,0 +1,2 @@ +[include:direct/manifest.ini] +[include:fallback/manifest.ini] |