From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- testing/firefox-ui/.flake8 | 3 + testing/firefox-ui/harness/MANIFEST.in | 2 + .../harness/firefox_ui_harness/__init__.py | 8 + .../firefox_ui_harness/arguments/__init__.py | 6 + .../harness/firefox_ui_harness/arguments/base.py | 18 + .../harness/firefox_ui_harness/arguments/update.py | 65 ++++ .../harness/firefox_ui_harness/cli_functional.py | 21 ++ .../harness/firefox_ui_harness/cli_update.py | 21 ++ .../harness/firefox_ui_harness/runners/__init__.py | 6 + .../harness/firefox_ui_harness/runners/base.py | 45 +++ .../harness/firefox_ui_harness/runners/update.py | 101 +++++ .../harness/firefox_ui_harness/testcases.py | 420 +++++++++++++++++++++ testing/firefox-ui/harness/requirements.txt | 5 + testing/firefox-ui/harness/setup.py | 44 +++ testing/firefox-ui/mach_commands.py | 120 ++++++ testing/firefox-ui/moz.build | 11 + .../addons/extensions/restartless_addon_signed.xpi | Bin 0 -> 186036 bytes .../extensions/restartless_addon_unsigned.xpi | Bin 0 -> 177535 bytes .../resources/cookies/cookie_single.html | 16 + .../resources/images/firefox_favicon.ico | Bin 0 -> 1150 bytes .../resources/images/mozilla_favicon.ico | Bin 0 -> 1406 bytes .../firefox-ui/resources/images/mozilla_logo.jpg | Bin 0 -> 3298 bytes testing/firefox-ui/resources/layout/mozilla.html | 45 +++ .../resources/layout/mozilla_community.html | 57 +++ .../resources/layout/mozilla_contribute.html | 70 ++++ .../resources/layout/mozilla_governance.html | 38 ++ .../resources/layout/mozilla_grants.html | 72 ++++ .../resources/layout/mozilla_mission.html | 51 +++ .../resources/layout/mozilla_organizations.html | 39 ++ .../resources/layout/mozilla_projects.html | 60 +++ .../resources/private_browsing/about.html | 10 + .../resources/security/enable_privilege.html | 21 ++ testing/firefox-ui/resources/support.html | 19 + .../functional/keyboard_shortcuts/manifest.ini | 4 + .../keyboard_shortcuts/test_browser_window.py | 56 +++ .../tests/functional/locationbar/manifest.ini | 9 + .../locationbar/test_access_locationbar.py | 60 +++ .../locationbar/test_escape_autocomplete.py | 56 +++ .../locationbar/test_favicon_in_autocomplete.py | 62 +++ .../locationbar/test_suggest_bookmarks.py | 96 +++++ testing/firefox-ui/tests/functional/manifest.ini | 5 + .../tests/functional/private_browsing/manifest.ini | 4 + .../test_about_private_browsing.py | 60 +++ .../tests/functional/security/manifest.ini | 22 ++ .../functional/security/test_dv_certificate.py | 85 +++++ .../functional/security/test_enable_privilege.py | 17 + .../functional/security/test_ev_certificate.py | 112 ++++++ .../functional/security/test_mixed_content_page.py | 55 +++ .../security/test_mixed_script_content_blocking.py | 87 +++++ .../functional/security/test_no_certificate.py | 81 ++++ .../test_safe_browsing_initial_download.py | 84 +++++ .../security/test_safe_browsing_notification.py | 149 ++++++++ .../security/test_safe_browsing_warning_pages.py | 115 ++++++ .../security/test_security_notification.py | 62 +++ .../security/test_ssl_disabled_error_page.py | 60 +++ .../security/test_ssl_status_after_restart.py | 124 ++++++ .../test_submit_unencrypted_info_warning.py | 65 ++++ .../functional/security/test_unknown_issuer.py | 34 ++ .../test_untrusted_connection_error_page.py | 35 ++ .../tests/functional/sessionstore/manifest.ini | 5 + .../test_restore_windows_after_restart.py | 150 ++++++++ testing/firefox-ui/tests/puppeteer/manifest.ini | 24 ++ .../tests/puppeteer/test_about_window.py | 74 ++++ testing/firefox-ui/tests/puppeteer/test_appinfo.py | 31 ++ testing/firefox-ui/tests/puppeteer/test_l10n.py | 51 +++ testing/firefox-ui/tests/puppeteer/test_menubar.py | 30 ++ .../tests/puppeteer/test_notifications.py | 82 ++++ .../tests/puppeteer/test_page_info_window.py | 100 +++++ testing/firefox-ui/tests/puppeteer/test_places.py | 85 +++++ .../firefox-ui/tests/puppeteer/test_security.py | 45 +++ .../tests/puppeteer/test_software_update.py | 134 +++++++ testing/firefox-ui/tests/puppeteer/test_tabbar.py | 191 ++++++++++ .../firefox-ui/tests/puppeteer/test_toolbars.py | 283 ++++++++++++++ .../tests/puppeteer/test_update_wizard.py | 67 ++++ testing/firefox-ui/tests/puppeteer/test_utils.py | 48 +++ testing/firefox-ui/tests/puppeteer/test_windows.py | 259 +++++++++++++ .../firefox-ui/tests/update/direct/manifest.ini | 4 + .../tests/update/direct/test_direct_update.py | 21 ++ .../firefox-ui/tests/update/fallback/manifest.ini | 4 + .../tests/update/fallback/test_fallback_update.py | 22 ++ testing/firefox-ui/tests/update/manifest.ini | 2 + 81 files changed, 4705 insertions(+) create mode 100644 testing/firefox-ui/.flake8 create mode 100644 testing/firefox-ui/harness/MANIFEST.in create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/__init__.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/arguments/__init__.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/arguments/base.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/arguments/update.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/cli_functional.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/cli_update.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/runners/__init__.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/runners/base.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/runners/update.py create mode 100644 testing/firefox-ui/harness/firefox_ui_harness/testcases.py create mode 100644 testing/firefox-ui/harness/requirements.txt create mode 100644 testing/firefox-ui/harness/setup.py create mode 100644 testing/firefox-ui/mach_commands.py create mode 100644 testing/firefox-ui/moz.build create mode 100644 testing/firefox-ui/resources/addons/extensions/restartless_addon_signed.xpi create mode 100644 testing/firefox-ui/resources/addons/extensions/restartless_addon_unsigned.xpi create mode 100644 testing/firefox-ui/resources/cookies/cookie_single.html create mode 100644 testing/firefox-ui/resources/images/firefox_favicon.ico create mode 100644 testing/firefox-ui/resources/images/mozilla_favicon.ico create mode 100644 testing/firefox-ui/resources/images/mozilla_logo.jpg create mode 100644 testing/firefox-ui/resources/layout/mozilla.html create mode 100644 testing/firefox-ui/resources/layout/mozilla_community.html create mode 100644 testing/firefox-ui/resources/layout/mozilla_contribute.html create mode 100644 testing/firefox-ui/resources/layout/mozilla_governance.html create mode 100644 testing/firefox-ui/resources/layout/mozilla_grants.html create mode 100644 testing/firefox-ui/resources/layout/mozilla_mission.html create mode 100644 testing/firefox-ui/resources/layout/mozilla_organizations.html create mode 100644 testing/firefox-ui/resources/layout/mozilla_projects.html create mode 100644 testing/firefox-ui/resources/private_browsing/about.html create mode 100644 testing/firefox-ui/resources/security/enable_privilege.html create mode 100644 testing/firefox-ui/resources/support.html create mode 100644 testing/firefox-ui/tests/functional/keyboard_shortcuts/manifest.ini create mode 100644 testing/firefox-ui/tests/functional/keyboard_shortcuts/test_browser_window.py create mode 100644 testing/firefox-ui/tests/functional/locationbar/manifest.ini create mode 100644 testing/firefox-ui/tests/functional/locationbar/test_access_locationbar.py create mode 100644 testing/firefox-ui/tests/functional/locationbar/test_escape_autocomplete.py create mode 100644 testing/firefox-ui/tests/functional/locationbar/test_favicon_in_autocomplete.py create mode 100644 testing/firefox-ui/tests/functional/locationbar/test_suggest_bookmarks.py create mode 100644 testing/firefox-ui/tests/functional/manifest.ini create mode 100644 testing/firefox-ui/tests/functional/private_browsing/manifest.ini create mode 100644 testing/firefox-ui/tests/functional/private_browsing/test_about_private_browsing.py create mode 100644 testing/firefox-ui/tests/functional/security/manifest.ini create mode 100644 testing/firefox-ui/tests/functional/security/test_dv_certificate.py create mode 100644 testing/firefox-ui/tests/functional/security/test_enable_privilege.py create mode 100644 testing/firefox-ui/tests/functional/security/test_ev_certificate.py create mode 100644 testing/firefox-ui/tests/functional/security/test_mixed_content_page.py create mode 100644 testing/firefox-ui/tests/functional/security/test_mixed_script_content_blocking.py create mode 100644 testing/firefox-ui/tests/functional/security/test_no_certificate.py create mode 100644 testing/firefox-ui/tests/functional/security/test_safe_browsing_initial_download.py create mode 100644 testing/firefox-ui/tests/functional/security/test_safe_browsing_notification.py create mode 100644 testing/firefox-ui/tests/functional/security/test_safe_browsing_warning_pages.py create mode 100644 testing/firefox-ui/tests/functional/security/test_security_notification.py create mode 100644 testing/firefox-ui/tests/functional/security/test_ssl_disabled_error_page.py create mode 100644 testing/firefox-ui/tests/functional/security/test_ssl_status_after_restart.py create mode 100644 testing/firefox-ui/tests/functional/security/test_submit_unencrypted_info_warning.py create mode 100644 testing/firefox-ui/tests/functional/security/test_unknown_issuer.py create mode 100644 testing/firefox-ui/tests/functional/security/test_untrusted_connection_error_page.py create mode 100644 testing/firefox-ui/tests/functional/sessionstore/manifest.ini create mode 100644 testing/firefox-ui/tests/functional/sessionstore/test_restore_windows_after_restart.py create mode 100644 testing/firefox-ui/tests/puppeteer/manifest.ini create mode 100644 testing/firefox-ui/tests/puppeteer/test_about_window.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_appinfo.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_l10n.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_menubar.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_notifications.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_page_info_window.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_places.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_security.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_software_update.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_tabbar.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_toolbars.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_update_wizard.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_utils.py create mode 100644 testing/firefox-ui/tests/puppeteer/test_windows.py create mode 100644 testing/firefox-ui/tests/update/direct/manifest.ini create mode 100644 testing/firefox-ui/tests/update/direct/test_direct_update.py create mode 100644 testing/firefox-ui/tests/update/fallback/manifest.ini create mode 100644 testing/firefox-ui/tests/update/fallback/test_fallback_update.py create mode 100644 testing/firefox-ui/tests/update/manifest.ini (limited to 'testing/firefox-ui') diff --git a/testing/firefox-ui/.flake8 b/testing/firefox-ui/.flake8 new file mode 100644 index 000000000..ad0819adf --- /dev/null +++ b/testing/firefox-ui/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 99 +exclude = __init__.py, diff --git a/testing/firefox-ui/harness/MANIFEST.in b/testing/firefox-ui/harness/MANIFEST.in new file mode 100644 index 000000000..cf628b039 --- /dev/null +++ b/testing/firefox-ui/harness/MANIFEST.in @@ -0,0 +1,2 @@ +exclude MANIFEST.in +include requirements.txt diff --git a/testing/firefox-ui/harness/firefox_ui_harness/__init__.py b/testing/firefox-ui/harness/firefox_ui_harness/__init__.py new file mode 100644 index 000000000..02ae10cdf --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/__init__.py @@ -0,0 +1,8 @@ +# 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/. + +__version__ = '1.4.0' + +import cli_functional +import cli_update diff --git a/testing/firefox-ui/harness/firefox_ui_harness/arguments/__init__.py b/testing/firefox-ui/harness/firefox_ui_harness/arguments/__init__.py new file mode 100644 index 000000000..57dc77f60 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/arguments/__init__.py @@ -0,0 +1,6 @@ +# 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.arguments.base import FirefoxUIArguments +from firefox_ui_harness.arguments.update import UpdateArguments diff --git a/testing/firefox-ui/harness/firefox_ui_harness/arguments/base.py b/testing/firefox-ui/harness/firefox_ui_harness/arguments/base.py new file mode 100644 index 000000000..e6427e764 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/arguments/base.py @@ -0,0 +1,18 @@ +# 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_harness import BaseMarionetteArguments + + +class FirefoxUIBaseArguments(object): + name = 'Firefox UI Tests' + args = [] + + +class FirefoxUIArguments(BaseMarionetteArguments): + + def __init__(self, **kwargs): + super(FirefoxUIArguments, self).__init__(**kwargs) + + self.register_argument_container(FirefoxUIBaseArguments()) diff --git a/testing/firefox-ui/harness/firefox_ui_harness/arguments/update.py b/testing/firefox-ui/harness/firefox_ui_harness/arguments/update.py new file mode 100644 index 000000000..9b6d3e5e0 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/arguments/update.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 base import FirefoxUIArguments + + +class UpdateBaseArguments(object): + name = 'Firefox UI Update Tests' + args = [ + [['--update-allow-mar-channel'], { + 'dest': 'update_mar_channels', + 'default': [], + 'action': 'append', + 'metavar': 'MAR_CHANNEL', + 'help': 'Additional MAR channel to be allowed for updates, ' + 'e.g. "firefox-mozilla-beta" for updating a release ' + 'build to the latest beta build.' + }], + [['--update-channel'], { + 'dest': 'update_channel', + 'metavar': 'CHANNEL', + 'help': 'Channel to use for the update check.' + }], + [['--update-direct-only'], { + 'dest': 'update_direct_only', + 'default': False, + 'action': 'store_true', + 'help': 'Only perform a direct update' + }], + [['--update-fallback-only'], { + 'dest': 'update_fallback_only', + 'default': False, + 'action': 'store_true', + 'help': 'Only perform a fallback update' + }], + [['--update-override-url'], { + 'dest': 'update_override_url', + 'metavar': 'URL', + 'help': 'Force specified URL to use for update checks.' + }], + [['--update-target-version'], { + 'dest': 'update_target_version', + 'metavar': 'VERSION', + 'help': 'Version of the updated build.' + }], + [['--update-target-buildid'], { + 'dest': 'update_target_buildid', + 'metavar': 'BUILD_ID', + 'help': 'Build ID of the updated build.' + }], + ] + + def verify_usage_handler(self, args): + if args.update_direct_only and args.update_fallback_only: + raise ValueError('Arguments --update-direct-only and --update-fallback-only ' + 'are mutually exclusive.') + + +class UpdateArguments(FirefoxUIArguments): + + def __init__(self, **kwargs): + super(UpdateArguments, self).__init__(**kwargs) + + self.register_argument_container(UpdateBaseArguments()) diff --git a/testing/firefox-ui/harness/firefox_ui_harness/cli_functional.py b/testing/firefox-ui/harness/firefox_ui_harness/cli_functional.py new file mode 100644 index 000000000..e83d88b51 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/cli_functional.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +# 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_harness.runtests import cli as mn_cli + +from firefox_ui_harness.arguments import FirefoxUIArguments +from firefox_ui_harness.runners import FirefoxUITestRunner + + +def cli(args=None): + mn_cli(runner_class=FirefoxUITestRunner, + parser_class=FirefoxUIArguments, + args=args, + ) + + +if __name__ == '__main__': + cli() diff --git a/testing/firefox-ui/harness/firefox_ui_harness/cli_update.py b/testing/firefox-ui/harness/firefox_ui_harness/cli_update.py new file mode 100644 index 000000000..27446a099 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/cli_update.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +# 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_harness.runtests import cli as mn_cli + +from firefox_ui_harness.arguments import UpdateArguments +from firefox_ui_harness.runners import UpdateTestRunner + + +def cli(args=None): + mn_cli(runner_class=UpdateTestRunner, + parser_class=UpdateArguments, + args=args, + ) + + +if __name__ == '__main__': + cli() diff --git a/testing/firefox-ui/harness/firefox_ui_harness/runners/__init__.py b/testing/firefox-ui/harness/firefox_ui_harness/runners/__init__.py new file mode 100644 index 000000000..9022a45b8 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/runners/__init__.py @@ -0,0 +1,6 @@ +# 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.runners.base import FirefoxUITestRunner +from firefox_ui_harness.runners.update import UpdateTestRunner diff --git a/testing/firefox-ui/harness/firefox_ui_harness/runners/base.py b/testing/firefox-ui/harness/firefox_ui_harness/runners/base.py new file mode 100644 index 000000000..66c2a5308 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/runners/base.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/. + +import os +import shutil +import tempfile + +import mozfile +import mozinfo + +from marionette_harness import BaseMarionetteTestRunner, MarionetteTestCase + + +class FirefoxUITestRunner(BaseMarionetteTestRunner): + + def __init__(self, **kwargs): + super(FirefoxUITestRunner, self).__init__(**kwargs) + + # select the appropriate GeckoInstance + self.app = 'fxdesktop' + + self.test_handlers = [MarionetteTestCase] + + def duplicate_application(self, application_folder): + """Creates a copy of the specified binary.""" + + if self.workspace: + target_folder = os.path.join(self.workspace_path, 'application.copy') + else: + target_folder = tempfile.mkdtemp('.application.copy') + + self.logger.info('Creating a copy of the application at "%s".' % target_folder) + mozfile.remove(target_folder) + shutil.copytree(application_folder, target_folder) + + return target_folder + + def get_application_folder(self, binary): + """Returns the directory of the application.""" + if mozinfo.isMac: + end_index = binary.find('.app') + 4 + return binary[:end_index] + else: + return os.path.dirname(binary) diff --git a/testing/firefox-ui/harness/firefox_ui_harness/runners/update.py b/testing/firefox-ui/harness/firefox_ui_harness/runners/update.py new file mode 100644 index 000000000..fe4936f68 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/runners/update.py @@ -0,0 +1,101 @@ +# 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 sys + +import mozfile +import mozinstall + +from firefox_ui_harness.runners import FirefoxUITestRunner +from firefox_ui_harness.testcases import UpdateTestCase + + +DEFAULT_PREFS = { + # Bug 1355026: Re-enable when support for the new simplified UI update is available + 'app.update.doorhanger': False, + 'app.update.log': True, + 'startup.homepage_override_url': 'about:blank', +} + + +class UpdateTestRunner(FirefoxUITestRunner): + + def __init__(self, **kwargs): + super(UpdateTestRunner, self).__init__(**kwargs) + + self.original_bin = self.bin + + self.prefs.update(DEFAULT_PREFS) + + # In case of overriding the update URL, set the appropriate preference + override_url = kwargs.pop('update_override_url', None) + if override_url: + self.prefs.update({'app.update.url.override': override_url}) + + self.run_direct_update = not kwargs.pop('update_fallback_only', False) + self.run_fallback_update = not kwargs.pop('update_direct_only', False) + + self.test_handlers = [UpdateTestCase] + + def run_tests(self, tests): + # Used to store the last occurred exception because we execute + # run_tests() multiple times + self.exc_info = None + + failed = 0 + source_folder = self.get_application_folder(self.original_bin) + + results = {} + + def _run_tests(tags): + application_folder = None + + try: + # Backup current tags + test_tags = self.test_tags + + application_folder = self.duplicate_application(source_folder) + self.bin = mozinstall.get_binary(application_folder, 'Firefox') + + self.test_tags = tags + super(UpdateTestRunner, self).run_tests(tests) + + except Exception: + self.exc_info = sys.exc_info() + self.logger.error('Failure during execution of the update test.', + exc_info=self.exc_info) + + finally: + self.test_tags = test_tags + + self.logger.info('Removing copy of the application at "%s"' % application_folder) + try: + mozfile.remove(application_folder) + except IOError as e: + self.logger.error('Cannot remove copy of application: "%s"' % str(e)) + + # Run direct update tests if wanted + if self.run_direct_update: + _run_tests(tags=['direct']) + failed += self.failed + results['Direct'] = False if self.failed else True + + # Run fallback update tests if wanted + if self.run_fallback_update: + _run_tests(tags=['fallback']) + failed += self.failed + results['Fallback'] = False if self.failed else True + + self.logger.info("Summary of update tests:") + for test_type, result in results.iteritems(): + self.logger.info("\t%s update test ran and %s" % + (test_type, 'PASSED' if result else 'FAILED')) + + # Combine failed tests for all run_test() executions + self.failed = failed + + # If exceptions happened, re-throw the last one + if self.exc_info: + ex_type, exception, tb = self.exc_info + raise ex_type, exception, tb diff --git a/testing/firefox-ui/harness/firefox_ui_harness/testcases.py b/testing/firefox-ui/harness/firefox_ui_harness/testcases.py new file mode 100644 index 000000000..abcbd6555 --- /dev/null +++ b/testing/firefox-ui/harness/firefox_ui_harness/testcases.py @@ -0,0 +1,420 @@ +# 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 +import pprint +from datetime import datetime + +import mozfile + +from firefox_puppeteer import PuppeteerMixin +from firefox_puppeteer.api.software_update import SoftwareUpdate +from firefox_puppeteer.ui.update_wizard import UpdateWizardDialog +from marionette_driver import Wait +from marionette_driver.errors import NoSuchWindowException +from marionette_harness import MarionetteTestCase + + +class UpdateTestCase(PuppeteerMixin, MarionetteTestCase): + + TIMEOUT_UPDATE_APPLY = 300 + TIMEOUT_UPDATE_CHECK = 30 + TIMEOUT_UPDATE_DOWNLOAD = 720 + + # For the old update wizard, the errors are displayed inside the dialog. For the + # handling of updates in the about window the errors are displayed in new dialogs. + # When the old wizard is open we have to set the preference, so the errors will be + # shown as expected, otherwise we would have unhandled modal dialogs when errors are + # raised. See: + # http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/update/nsUpdateService.js?rev=a9240b1eb2fb#4813 + # http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/update/nsUpdateService.js?rev=a9240b1eb2fb#4756 + PREF_APP_UPDATE_ALTWINDOWTYPE = 'app.update.altwindowtype' + + def __init__(self, *args, **kwargs): + super(UpdateTestCase, self).__init__(*args, **kwargs) + + self.update_channel = kwargs.pop('update_channel') + self.update_mar_channels = set(kwargs.pop('update_mar_channels')) + + self.target_buildid = kwargs.pop('update_target_buildid') + self.target_version = kwargs.pop('update_target_version') + + def setUp(self, is_fallback=False): + super(UpdateTestCase, self).setUp() + + self.software_update = SoftwareUpdate(self.marionette) + self.download_duration = None + + # If a custom update channel has to be set, force a restart of + # Firefox to actually get it applied as a default pref. Use the clean + # option to force a non in_app restart, which would allow Firefox to + # dump the logs to the console. + if self.update_channel: + self.software_update.update_channel = self.update_channel + self.restart(clean=True) + + self.assertEqual(self.software_update.update_channel, self.update_channel) + + # If requested modify the list of allowed MAR channels + if self.update_mar_channels: + self.software_update.mar_channels.add_channels(self.update_mar_channels) + + self.assertTrue(self.update_mar_channels.issubset( + self.software_update.mar_channels.channels), + 'Allowed MAR channels have been set: expected "{}" in "{}"'.format( + ', '.join(self.update_mar_channels), + ', '.join(self.software_update.mar_channels.channels))) + + # Ensure that there exists no already partially downloaded update + self.remove_downloaded_update() + + # Dictionary which holds the information for each update + self.update_status = { + 'build_pre': self.software_update.build_info, + 'build_post': None, + 'fallback': is_fallback, + 'patch': {}, + 'success': False, + } + + # Check if the user has permissions to run the update + self.assertTrue(self.software_update.allowed, + 'Current user has permissions to update the application.') + + def tearDown(self): + try: + self.browser.tabbar.close_all_tabs([self.browser.tabbar.selected_tab]) + + # Add content of the update log file for detailed failures when applying an update + self.update_status['update_log'] = self.read_update_log() + + # Print results for now until we have treeherder integration + output = pprint.pformat(self.update_status) + self.logger.info('Update test results: \n{}'.format(output)) + finally: + super(UpdateTestCase, self).tearDown() + + # Ensure that no trace of an partially downloaded update remain + self.remove_downloaded_update() + + @property + def patch_info(self): + """ Returns information about the active update in the queue. + + :returns: A dictionary with information about the active patch + """ + patch = self.software_update.patch_info + patch['download_duration'] = self.download_duration + + return patch + + def check_for_updates(self, about_window, timeout=TIMEOUT_UPDATE_CHECK): + """Clicks on "Check for Updates" button, and waits for check to complete. + + :param about_window: Instance of :class:`AboutWindow`. + :param timeout: How long to wait for the update check to finish. Optional, + defaults to 60s. + + :returns: True, if an update is available. + """ + self.assertEqual(about_window.deck.selected_panel, + about_window.deck.check_for_updates) + + about_window.deck.check_for_updates.button.click() + Wait(self.marionette, timeout=self.TIMEOUT_UPDATE_CHECK).until( + lambda _: about_window.deck.selected_panel not in + (about_window.deck.check_for_updates, about_window.deck.checking_for_updates), + message='Check for updates has been finished.') + + return about_window.deck.selected_panel != about_window.deck.no_updates_found + + def check_update_applied(self): + """Check that the update has been applied correctly""" + self.update_status['build_post'] = self.software_update.build_info + + # Ensure that the target version is the same or higher. No downgrade + # should have happened. + version_check = self.marionette.execute_script(""" + Components.utils.import("resource://gre/modules/Services.jsm"); + + return Services.vc.compare(arguments[0], arguments[1]); + """, script_args=(self.update_status['build_post']['version'], + self.update_status['build_pre']['version'])) + + self.assertGreaterEqual(version_check, 0, + 'A downgrade from version {} to {} is not allowed'.format( + self.update_status['build_pre']['version'], + self.update_status['build_post']['version'])) + + self.assertNotEqual(self.update_status['build_post']['buildid'], + self.update_status['build_pre']['buildid'], + 'The staged update to buildid {} has not been applied'.format( + self.update_status['patch']['buildid'])) + + self.assertEqual(self.update_status['build_post']['buildid'], + self.update_status['patch']['buildid'], + 'Unexpected target buildid after applying the patch, {} != {}'.format( + self.update_status['build_post']['buildid'], + self.update_status['patch']['buildid'])) + + self.assertEqual(self.update_status['build_post']['locale'], + self.update_status['build_pre']['locale'], + 'Unexpected change of the locale from {} to {}'.format( + self.update_status['build_pre']['locale'], + self.update_status['build_post']['locale'])) + + self.assertEqual(self.update_status['build_post']['disabled_addons'], + self.update_status['build_pre']['disabled_addons'], + 'Application-wide addons have been unexpectedly disabled: {}'.format( + ', '.join(set(self.update_status['build_pre']['locale']) - + set(self.update_status['build_post']['locale'])) + )) + + if self.target_version: + self.assertEqual(self.update_status['build_post']['version'], + self.target_version, + 'Current target version {} does not match expected version {}'.format( + self.update_status['build_post']['version'], self.target_version)) + + if self.target_buildid: + self.assertEqual(self.update_status['build_post']['buildid'], + self.target_buildid, + 'Current target buildid {} does not match expected buildid {}'.format( + self.update_status['build_post']['buildid'], self.target_buildid)) + + self.update_status['success'] = True + + def check_update_not_applied(self): + """Check that the update has not been applied due to a forced invalidation of the patch""" + build_info = self.software_update.build_info + + # Ensure that the version has not been changed + version_check = self.marionette.execute_script(""" + Components.utils.import("resource://gre/modules/Services.jsm"); + + return Services.vc.compare(arguments[0], arguments[1]); + """, script_args=(build_info['version'], + self.update_status['build_pre']['version'])) + + self.assertEqual(version_check, 0, + 'An update from version {} to {} has been unexpectedly applied'.format( + self.update_status['build_pre']['version'], + build_info['version'])) + + # Check that the build id of the source build and the current build are identical + self.assertEqual(build_info['buildid'], + self.update_status['build_pre']['buildid'], + 'The build id has been unexpectedly changed from {} to {}'.format( + self.update_status['build_pre']['buildid'], build_info['buildid'])) + + def download_update(self, window, wait_for_finish=True, timeout=TIMEOUT_UPDATE_DOWNLOAD): + """ Download the update patch. + + :param window: Instance of :class:`AboutWindow` or :class:`UpdateWizardDialog`. + :param wait_for_finish: If True the function has to wait for the download to be finished. + Optional, default to `True`. + :param timeout: How long to wait for the download to finish. Optional, default to 360s. + """ + + def download_via_update_wizard(dialog): + """ Download the update via the old update wizard dialog. + + :param dialog: Instance of :class:`UpdateWizardDialog`. + """ + self.marionette.set_pref(self.PREF_APP_UPDATE_ALTWINDOWTYPE, dialog.window_type) + + try: + # If updates have already been found, proceed to download + if dialog.wizard.selected_panel in [dialog.wizard.updates_found_basic, + dialog.wizard.error_patching, + ]: + dialog.select_next_page() + + # If incompatible add-on are installed, skip over the wizard page + # TODO: Remove once we no longer support version Firefox 45.0ESR + if self.puppeteer.utils.compare_version(self.puppeteer.appinfo.version, + '49.0a1') == -1: + if dialog.wizard.selected_panel == dialog.wizard.incompatible_list: + dialog.select_next_page() + + # Updates were stored in the cache, so no download is necessary + if dialog.wizard.selected_panel in [dialog.wizard.finished, + dialog.wizard.finished_background, + ]: + pass + + # Download the update + elif dialog.wizard.selected_panel == dialog.wizard.downloading: + if wait_for_finish: + start_time = datetime.now() + self.wait_for_download_finished(dialog, timeout) + self.download_duration = (datetime.now() - start_time).total_seconds() + + Wait(self.marionette).until(lambda _: ( + dialog.wizard.selected_panel in [dialog.wizard.finished, + dialog.wizard.finished_background, + ]), + message='Final wizard page has been selected.') + + else: + raise Exception('Invalid wizard page for downloading an update: {}'.format( + dialog.wizard.selected_panel)) + + finally: + self.marionette.clear_pref(self.PREF_APP_UPDATE_ALTWINDOWTYPE) + + # The old update wizard dialog has to be handled differently. It's necessary + # for fallback updates and invalid add-on versions. + if isinstance(window, UpdateWizardDialog): + download_via_update_wizard(window) + return + + if window.deck.selected_panel == window.deck.download_and_install: + window.deck.download_and_install.button.click() + + # Wait for the download to start + Wait(self.marionette).until(lambda _: ( + window.deck.selected_panel != window.deck.download_and_install), + message='Download of the update has been started.') + + if wait_for_finish: + start_time = datetime.now() + self.wait_for_download_finished(window, timeout) + self.download_duration = (datetime.now() - start_time).total_seconds() + + def download_and_apply_available_update(self, force_fallback=False): + """Checks, downloads, and applies an available update. + + :param force_fallback: Optional, if `True` invalidate current update status. + Defaults to `False`. + """ + # Open the about window and check for updates + about_window = self.browser.open_about_window() + + try: + update_available = self.check_for_updates(about_window) + self.assertTrue(update_available, + "Available update has been found") + + # Download update and wait until it has been applied + self.download_update(about_window) + self.wait_for_update_applied(about_window) + + finally: + self.update_status['patch'] = self.patch_info + + if force_fallback: + # Set the downloaded update into failed state + self.software_update.force_fallback() + + # Restart Firefox to apply the downloaded update + self.restart() + + def download_and_apply_forced_update(self): + self.check_update_not_applied() + + # The update wizard dialog opens automatically after the restart but with a short delay + dialog = Wait(self.marionette, ignored_exceptions=[NoSuchWindowException]).until( + lambda _: self.puppeteer.windows.switch_to(lambda win: type(win) is UpdateWizardDialog) + ) + + # In case of a broken complete update the about window has to be used + if self.update_status['patch']['is_complete']: + about_window = None + try: + self.assertEqual(dialog.wizard.selected_panel, + dialog.wizard.error) + dialog.close() + + # Open the about window and check for updates + about_window = self.browser.open_about_window() + update_available = self.check_for_updates(about_window) + self.assertTrue(update_available, + 'Available update has been found') + + # Download update and wait until it has been applied + self.download_update(about_window) + self.wait_for_update_applied(about_window) + + finally: + if about_window: + self.update_status['patch'] = self.patch_info + + else: + try: + self.assertEqual(dialog.wizard.selected_panel, + dialog.wizard.error_patching) + + # Start downloading the fallback update + self.download_update(dialog) + + finally: + self.update_status['patch'] = self.patch_info + + # Restart Firefox to apply the update + self.restart() + + def read_update_log(self): + """Read the content of the update log file for the last update attempt.""" + path = os.path.join(os.path.dirname(self.software_update.staging_directory), + 'last-update.log') + try: + with open(path, 'rb') as f: + return f.read().splitlines() + except IOError as exc: + self.logger.warning(str(exc)) + return None + + def remove_downloaded_update(self): + """Remove an already downloaded update from the update staging directory. + + Hereby not only remove the update subdir but everything below 'updates'. + """ + path = os.path.dirname(self.software_update.staging_directory) + self.logger.info('Clean-up update staging directory: {}'.format(path)) + mozfile.remove(path) + + def wait_for_download_finished(self, window, timeout=TIMEOUT_UPDATE_DOWNLOAD): + """ Waits until download is completed. + + :param window: Instance of :class:`AboutWindow` or :class:`UpdateWizardDialog`. + :param timeout: How long to wait for the download to finish. Optional, + default to 360 seconds. + """ + # The old update wizard dialog has to be handled differently. It's necessary + # for fallback updates and invalid add-on versions. + if isinstance(window, UpdateWizardDialog): + Wait(self.marionette, timeout=timeout).until( + lambda _: window.wizard.selected_panel != window.wizard.downloading, + message='Download has been completed.') + + self.assertNotIn(window.wizard.selected_panel, + [window.wizard.error, window.wizard.error_extra]) + return + + Wait(self.marionette, timeout=timeout).until( + lambda _: window.deck.selected_panel not in + (window.deck.download_and_install, window.deck.downloading), + message='Download has been completed.') + + self.assertNotEqual(window.deck.selected_panel, + window.deck.download_failed) + + def wait_for_update_applied(self, about_window, timeout=TIMEOUT_UPDATE_APPLY): + """ Waits until the downloaded update has been applied. + + :param about_window: Instance of :class:`AboutWindow`. + :param timeout: How long to wait for the update to apply. Optional, + default to 300 seconds + """ + Wait(self.marionette, timeout=timeout).until( + lambda _: about_window.deck.selected_panel == about_window.deck.apply, + message='Final wizard page has been selected.') + + # Wait for update to be staged because for update tests we modify the update + # status file to enforce the fallback update. If we modify the file before + # Firefox does, Firefox will override our change and we will have no fallback update. + Wait(self.marionette, timeout=timeout).until( + lambda _: 'applied' in self.software_update.active_update.state, + message='Update has been applied.') diff --git a/testing/firefox-ui/harness/requirements.txt b/testing/firefox-ui/harness/requirements.txt new file mode 100644 index 000000000..54114debb --- /dev/null +++ b/testing/firefox-ui/harness/requirements.txt @@ -0,0 +1,5 @@ +firefox-puppeteer >= 52.1.0, <53.0.0 +marionette-harness >= 4.0.0 +mozfile >= 1.2 +mozinfo >= 0.8 +mozinstall >= 1.12 diff --git a/testing/firefox-ui/harness/setup.py b/testing/firefox-ui/harness/setup.py new file mode 100644 index 000000000..1799d5057 --- /dev/null +++ b/testing/firefox-ui/harness/setup.py @@ -0,0 +1,44 @@ +# 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 +import re +from setuptools import setup, find_packages + +THIS_DIR = os.path.dirname(os.path.realpath(__name__)) + + +def read(*parts): + with open(os.path.join(THIS_DIR, *parts)) as f: + return f.read() + + +def get_version(): + return re.findall("__version__ = '([\d\.]+)'", + read('firefox_ui_harness', '__init__.py'), re.M)[0] + +long_description = """Custom Marionette runner classes and entry scripts for Firefox Desktop +specific Marionette tests. +""" + +setup(name='firefox-ui-harness', + version=get_version(), + description="Firefox UI Harness", + long_description=long_description, + classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers + keywords='mozilla', + author='Auto-tools', + author_email='tools-marionette@lists.mozilla.org', + url='https://wiki.mozilla.org/Auto-tools/Projects/Marionette/Harnesses/FirefoxUI', + license='MPL', + packages=find_packages(), + include_package_data=True, + zip_safe=False, + install_requires=read('requirements.txt').splitlines(), + entry_points=""" + [console_scripts] + firefox-ui-functional = firefox_ui_harness.cli_functional:cli + firefox-ui-update = firefox_ui_harness.cli_update:cli + """, + ) diff --git a/testing/firefox-ui/mach_commands.py b/testing/firefox-ui/mach_commands.py new file mode 100644 index 000000000..368b673a2 --- /dev/null +++ b/testing/firefox-ui/mach_commands.py @@ -0,0 +1,120 @@ +# 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 __future__ import absolute_import, unicode_literals + +import os +import sys + +from mozbuild.base import ( + MachCommandBase, + MachCommandConditions as conditions, +) + +from mach.decorators import ( + Command, + CommandProvider, +) + + +def setup_argument_parser_functional(): + from firefox_ui_harness.arguments.base import FirefoxUIArguments + from mozlog.structured import commandline + parser = FirefoxUIArguments() + commandline.add_logging_group(parser) + return parser + + +def setup_argument_parser_update(): + from firefox_ui_harness.arguments.update import UpdateArguments + from mozlog.structured import commandline + parser = UpdateArguments() + commandline.add_logging_group(parser) + return parser + + +def run_firefox_ui_test(testtype=None, topsrcdir=None, **kwargs): + from mozlog.structured import commandline + from argparse import Namespace + import firefox_ui_harness + + if testtype == 'functional': + parser = setup_argument_parser_functional() + else: + parser = setup_argument_parser_update() + + test_types = { + 'functional': { + 'default_tests': [ + os.path.join('puppeteer', 'manifest.ini'), + os.path.join('functional', 'manifest.ini'), + ], + 'cli_module': firefox_ui_harness.cli_functional, + }, + 'update': { + 'default_tests': [ + os.path.join('update', 'manifest.ini'), + ], + 'cli_module': firefox_ui_harness.cli_update, + } + } + + fxui_dir = os.path.join(topsrcdir, 'testing', 'firefox-ui') + + # Set the resources path which is used to serve test data via wptserve + if not kwargs['server_root']: + kwargs['server_root'] = os.path.join(fxui_dir, 'resources') + + # If called via "mach test" a dictionary of tests is passed in + if 'test_objects' in kwargs: + tests = [] + for obj in kwargs['test_objects']: + tests.append(obj['file_relpath']) + kwargs['tests'] = tests + elif not kwargs.get('tests'): + # If no tests have been selected, set default ones + kwargs['tests'] = [os.path.join(fxui_dir, 'tests', test) + for test in test_types[testtype]['default_tests']] + + kwargs['logger'] = commandline.setup_logging('Firefox UI - {} Tests'.format(testtype), + {"mach": sys.stdout}) + + args = Namespace() + + for k, v in kwargs.iteritems(): + setattr(args, k, v) + + parser.verify_usage(args) + + failed = test_types[testtype]['cli_module'].cli(args=vars(args)) + + if failed > 0: + return 1 + else: + return 0 + + +@CommandProvider +class MachCommands(MachCommandBase): + """Mach command provider for Firefox ui tests.""" + + @Command('firefox-ui-functional', category='testing', + conditions=[conditions.is_firefox], + description='Run the functional test suite of Firefox UI tests.', + parser=setup_argument_parser_functional, + ) + def run_firefox_ui_functional(self, **kwargs): + kwargs['binary'] = kwargs['binary'] or self.get_binary_path('app') + return run_firefox_ui_test(testtype='functional', + topsrcdir=self.topsrcdir, **kwargs) + + @Command('firefox-ui-update', category='testing', + conditions=[conditions.is_firefox], + description='Run the update test suite of Firefox UI tests.', + parser=setup_argument_parser_update, + ) + def run_firefox_ui_update(self, **kwargs): + kwargs['binary'] = kwargs['binary'] or self.get_binary_path('app') + return run_firefox_ui_test(testtype='update', + topsrcdir=self.topsrcdir, **kwargs) diff --git a/testing/firefox-ui/moz.build b/testing/firefox-ui/moz.build new file mode 100644 index 000000000..dd7311c03 --- /dev/null +++ b/testing/firefox-ui/moz.build @@ -0,0 +1,11 @@ +# 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/. + +FIREFOX_UI_FUNCTIONAL_MANIFESTS += ["tests/functional/manifest.ini"] +FIREFOX_UI_UPDATE_MANIFESTS += ["tests/update/manifest.ini"] +# TODO: Move to testing/marionette/puppeteer/firefox +PUPPETEER_FIREFOX_MANIFESTS += ["tests/puppeteer/manifest.ini"] + +with Files("**"): + BUG_COMPONENT = ("Testing", "Firefox UI Tests") diff --git a/testing/firefox-ui/resources/addons/extensions/restartless_addon_signed.xpi b/testing/firefox-ui/resources/addons/extensions/restartless_addon_signed.xpi new file mode 100644 index 000000000..ed86213e7 Binary files /dev/null and b/testing/firefox-ui/resources/addons/extensions/restartless_addon_signed.xpi differ diff --git a/testing/firefox-ui/resources/addons/extensions/restartless_addon_unsigned.xpi b/testing/firefox-ui/resources/addons/extensions/restartless_addon_unsigned.xpi new file mode 100644 index 000000000..d0768103d Binary files /dev/null and b/testing/firefox-ui/resources/addons/extensions/restartless_addon_unsigned.xpi differ diff --git a/testing/firefox-ui/resources/cookies/cookie_single.html b/testing/firefox-ui/resources/cookies/cookie_single.html new file mode 100644 index 000000000..d4a02b45b --- /dev/null +++ b/testing/firefox-ui/resources/cookies/cookie_single.html @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/testing/firefox-ui/resources/images/firefox_favicon.ico b/testing/firefox-ui/resources/images/firefox_favicon.ico new file mode 100644 index 000000000..2c2f81768 Binary files /dev/null and b/testing/firefox-ui/resources/images/firefox_favicon.ico differ diff --git a/testing/firefox-ui/resources/images/mozilla_favicon.ico b/testing/firefox-ui/resources/images/mozilla_favicon.ico new file mode 100644 index 000000000..d44438903 Binary files /dev/null and b/testing/firefox-ui/resources/images/mozilla_favicon.ico differ diff --git a/testing/firefox-ui/resources/images/mozilla_logo.jpg b/testing/firefox-ui/resources/images/mozilla_logo.jpg new file mode 100644 index 000000000..231b385ee Binary files /dev/null and b/testing/firefox-ui/resources/images/mozilla_logo.jpg differ diff --git a/testing/firefox-ui/resources/layout/mozilla.html b/testing/firefox-ui/resources/layout/mozilla.html new file mode 100644 index 000000000..9224533bf --- /dev/null +++ b/testing/firefox-ui/resources/layout/mozilla.html @@ -0,0 +1,45 @@ + + + + Mozilla + + + + + + + + + Community | + Project | + Organization + +
+

+ We believe that the internet should be public, + open and accessible. +

+ +

Community

+

+ We're a global community of thousands who believe in the power + of technology to enrich people's lives. + More +

+ +

Project

+

+ We're an open source project whose code is used for some of the + Internet's most innovative applications. + More +

+ +

Organization

+

+ We're a public benefit organization dedicated to making the + Internet better for everyone. + More +

+
+ + diff --git a/testing/firefox-ui/resources/layout/mozilla_community.html b/testing/firefox-ui/resources/layout/mozilla_community.html new file mode 100644 index 000000000..c8da6afd8 --- /dev/null +++ b/testing/firefox-ui/resources/layout/mozilla_community.html @@ -0,0 +1,57 @@ + + + + Mozilla Community + + + + + + + + + History | + Communicate | + More + +
+

Our Community

+ +

History

+

+ When www.mozilla.org was launched in 1998 all community activity + occurred right here on this site. Since then the community has + grown much bigger and there are now many different sites, + forums, blogs and newsgroups in different places that track + different parts of the project. These pages aim to be a + comprehensive list to all of the different community resources + available. If you know of something that's not on these lists + that should be, please contact us and we'll update these + pages. +

+ +

Communicate

+

+ There are a number of different ways community members + communicate and coordinate (people use mailing lists and + newsgroups, blogs, forums, wikis and they even meet in real + life sometimes too) and all of these options might be + overwhelming at first. Hopefully this set of links will provide + some useful pointers to help you figure out where to go to find + what you're looking for. If you do get lost though and need + some help, feel free to ask for more information. +

+ +

More

+

+ Please note that this is intended to be an entry point that + provides a high-level overview of the different community areas. + If you're looking for more detailed information about a specific + topic, please look at our Developer, + Contribute and Support + pages or take a look at the other information referenced + throughout this site. +

+
+ + diff --git a/testing/firefox-ui/resources/layout/mozilla_contribute.html b/testing/firefox-ui/resources/layout/mozilla_contribute.html new file mode 100644 index 000000000..cf5e54b85 --- /dev/null +++ b/testing/firefox-ui/resources/layout/mozilla_contribute.html @@ -0,0 +1,70 @@ + + + + Mozilla Contribute + + + + + + + + + Summary | + Contribute + +
+

Get Involved

+ +

Summary

+

+ You can build a better Internet + by getting involved with Mozilla. You don't have to be a C++ + guru (or even know what that means!) and you don't need to spend + lots of time. Take a look at the opportunities below and feel + free to ask if you have any questions. +

+ +

Contribute

+

+

Area of Interest

+ Browse contribution opportunities by area of interest. + + +

+
+ + diff --git a/testing/firefox-ui/resources/layout/mozilla_governance.html b/testing/firefox-ui/resources/layout/mozilla_governance.html new file mode 100644 index 000000000..8e25aaabd --- /dev/null +++ b/testing/firefox-ui/resources/layout/mozilla_governance.html @@ -0,0 +1,38 @@ + + + + Mozilla Governance + + + + + + + + + Summary | + More + +
+

Governance

+ +

Summary

+

+ Mozilla is an open source project governed as a meritocracy. Our + community is structured as a virtual organization where + authority is distributed to both volunteer and employed + community members as they show their abilities through + contributions to the project. +

+ +

More

+

+

+

+
+ + diff --git a/testing/firefox-ui/resources/layout/mozilla_grants.html b/testing/firefox-ui/resources/layout/mozilla_grants.html new file mode 100644 index 000000000..c8935c4fb --- /dev/null +++ b/testing/firefox-ui/resources/layout/mozilla_grants.html @@ -0,0 +1,72 @@ + + + + Mozilla Grants + + + + + + + + + Summary | + Goals + +
+

Mozilla Grants

+ +

Summary

+

+ Since 2006, Mozilla has awarded over two million dollars to fund + projects that contribute to the health of the Open Web. The + Mozilla Grants program is jointly funded by the Mozilla + Corporation and the Mozilla Foundation, and awards financial + support to individuals and organizations whose work supports and + enhances the mission and values of the Mozilla Project. +

+ +

Goals

+

+ Mozilla makes grants to individuals and organizations all over + the world. We mainly fund activity that supports the Mozilla + Grants program's four target areas: + +

+

+
+ + diff --git a/testing/firefox-ui/resources/layout/mozilla_mission.html b/testing/firefox-ui/resources/layout/mozilla_mission.html new file mode 100644 index 000000000..c9ed2bd85 --- /dev/null +++ b/testing/firefox-ui/resources/layout/mozilla_mission.html @@ -0,0 +1,51 @@ + + + + Mozilla Mission + + + + + + + + + Mission | + Organization | + Goal + +
+

Mission

+ +

Mission

+

+ Mozilla's mission is to promote openness, innovation, + and opportunity on the web. We do this by creating + great software, like the Firefox browser, and building + movements, like Drumbeat, that give people tools to take control + of their online lives. +

+ +

Organization

+

+ As a non-profit organization, we define success in terms of + building communities and enriching people's lives instead of + benefiting our shareholders (guess what: we don't even have + shareholders). We believe in the power and potential of the + Internet and want to see it thrive for everyone, everywhere. +

+ +

Goal

+

+ + Building a better Internet is an ambitious goal, but we + believe that it is possible + + when people who share our passion get involved. Coders, artists, + writers, testers, surfers, students, grandparents; anyone who + uses and cares about the web can help make it even better. + Find out how you can help. +

+
+ + diff --git a/testing/firefox-ui/resources/layout/mozilla_organizations.html b/testing/firefox-ui/resources/layout/mozilla_organizations.html new file mode 100644 index 000000000..9d2ae9ff0 --- /dev/null +++ b/testing/firefox-ui/resources/layout/mozilla_organizations.html @@ -0,0 +1,39 @@ + + + + Mozilla Organizations + + + + + + + + + Summary | + Organization + +
+

Mozilla Organizations

+ +

Summary

+

+ Mozilla is a global community of people creating a better + Internet. We build public benefit into the Internet by creating + free, open source products and technologies that improve the + online experience for people everywhere. +

+ +

Organization

+

+ There are several organizations that support the Mozilla + community and Mozilla's principles. They include the non-profit + Mozilla Foundation as well as two wholly owned taxable + subsidiaries, the Mozilla Corporation and Mozilla Messaging. + Mozilla considers itself a hybrid organization, combining non- + profit and market strategies to ensure the Internet remains a + shared public resource. +

+
+ + diff --git a/testing/firefox-ui/resources/layout/mozilla_projects.html b/testing/firefox-ui/resources/layout/mozilla_projects.html new file mode 100644 index 000000000..a4ec7c840 --- /dev/null +++ b/testing/firefox-ui/resources/layout/mozilla_projects.html @@ -0,0 +1,60 @@ + + + + Mozilla Projects + + + + + + + + + Summary | + Applications + +
+

Our Projects

+ +

Summary

+

+ The Mozilla community produces a lot of great software and acts + as an incubator for innovative ideas as a way to advance our + mission of building a better + Internet. +

+ +

Applications

+

+

+ These applications are developed by the Mozilla community + and their code is hosted on mozilla.org. +

+ + +

+
+ + diff --git a/testing/firefox-ui/resources/private_browsing/about.html b/testing/firefox-ui/resources/private_browsing/about.html new file mode 100644 index 000000000..30b211be6 --- /dev/null +++ b/testing/firefox-ui/resources/private_browsing/about.html @@ -0,0 +1,10 @@ + + + + + + + +
About Private Browsing
+ + diff --git a/testing/firefox-ui/resources/security/enable_privilege.html b/testing/firefox-ui/resources/security/enable_privilege.html new file mode 100644 index 000000000..9d18e4684 --- /dev/null +++ b/testing/firefox-ui/resources/security/enable_privilege.html @@ -0,0 +1,21 @@ + + + + Test page for enablePrivilege + + + +

+ + diff --git a/testing/firefox-ui/resources/support.html b/testing/firefox-ui/resources/support.html new file mode 100644 index 000000000..b794e9ef9 --- /dev/null +++ b/testing/firefox-ui/resources/support.html @@ -0,0 +1,19 @@ + + + + + + + + +
+ + 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' + 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] -- cgit v1.2.3