Example #1
0
    def __init__(self, *args, **kwargs):
        super(PuppeteerRunner, self).__init__(*args, **kwargs)

        self.profile = mozprofile.Profile()

        self.remotedir = os.path.join(self.topsrcdir, "remote")
        self.puppeteerdir = os.path.join(self.remotedir, "test", "puppeteer")
Example #2
0
def view_profile(args=sys.argv[1:]):

    usage = "%prog [options] profile_path <...>"
    parser = optparse.OptionParser(usage=usage, description=__doc__)
    options, args = parser.parse_args(args)
    if not args:
        parser.print_usage()
        parser.exit()

    # check existence
    missing = [i for i in args if not os.path.exists(i)]
    if missing:
        if len(missing) > 1:
            missing_string = "Profiles do not exist"
        else:
            missing_string = "Profile does not exist"
        parser.error("%s: %s" % (missing_string, ", ".join(missing)))

    # print summary for each profile
    while args:
        path = args.pop(0)
        profile = mozprofile.Profile(path)
        print(profile.summary())
        if args:
            print("-" * 4)
def test_str_cast():
    """Test casting to a string."""
    profile = mozprofile.Profile()
    if sys.version_info[0] >= 3:
        assert str(profile) == profile.summary()
    else:
        assert str(profile) == profile.summary().encode("utf-8")
    def test_strcast(self):
        """
        test casting to a string
        """

        profile = mozprofile.Profile()
        self.assertEqual(str(profile), profile.summary())
    def setUp(self):
        super(ExternalProfileMixin, self).setUp()

        # Create external profile
        tmp_dir = tempfile.mkdtemp(suffix="external")
        shutil.rmtree(tmp_dir, ignore_errors=True)

        self.external_profile = mozprofile.Profile(profile=tmp_dir)
        # Prevent profile from being removed during cleanup
        self.external_profile.create_new = False
    def test_profile_diff(self):
        profile1 = mozprofile.Profile()
        profile2 = mozprofile.Profile(preferences=dict(foo='bar'))

        # diff a profile against itself; no difference
        self.assertEqual([], mozprofile.diff(profile1, profile1))

        # diff two profiles
        diff = dict(mozprofile.diff(profile1, profile2))
        self.assertEqual(diff.keys(), ['user.js'])
        lines = [line.strip() for line in diff['user.js'].splitlines()]
        self.assertTrue('+foo: bar' in lines)

        # diff a blank vs FirefoxProfile
        ff_profile = mozprofile.FirefoxProfile()
        diff = dict(mozprofile.diff(profile2, ff_profile))
        self.assertEqual(diff.keys(), ['user.js'])
        lines = [line.strip() for line in diff['user.js'].splitlines()]
        self.assertTrue('-foo: bar' in lines)
        ff_pref_lines = ['+%s: %s' % (key, value)
                         for key, value in mozprofile.FirefoxProfile.preferences.items()]
        self.assertTrue(set(ff_pref_lines).issubset(lines))
Example #7
0
def test_profile_diff():
    profile1 = mozprofile.Profile()
    profile2 = mozprofile.Profile(preferences=dict(foo='bar'))

    # diff a profile against itself; no difference
    assert mozprofile.diff(profile1, profile1) == []

    # diff two profiles
    diff = dict(mozprofile.diff(profile1, profile2))
    assert list(diff.keys()) == ['user.js']
    lines = [line.strip() for line in diff['user.js'].splitlines()]
    assert '+foo: bar' in lines

    # diff a blank vs FirefoxProfile
    ff_profile = mozprofile.FirefoxProfile()
    diff = dict(mozprofile.diff(profile2, ff_profile))
    assert list(diff.keys()) == ['user.js']
    lines = [line.strip() for line in diff['user.js'].splitlines()]
    assert '-foo: bar' in lines
    ff_pref_lines = ['+%s: %s' % (key, value)
                     for key, value in mozprofile.FirefoxProfile.preferences.items()]
    assert set(ff_pref_lines).issubset(lines)
Example #8
0
    def start(self, profile_file=None):
        print "Starting %s... " % self.appname

        # for fennec only, we create and use a profile
        if self.appname.startswith('org.mozilla'):
            args = []
            self.is_profiling = profile_file != None
            preferences = {
                'gfx.show_checkerboard_pattern': False,
                'browser.firstrun.show.uidiscovery': False,
                'toolkit.telemetry.prompted': 2
            }

            # Add frame counter to correlate video capture with profile
            if self.is_profiling:
                preferences['layers.acceleration.frame-counter'] = True

            profile = mozprofile.Profile(preferences=preferences)
            self.remote_profile_dir = "/".join(
                [self.dm.getDeviceRoot(),
                 os.path.basename(profile.profile)])
            if not self.dm.pushDir(profile.profile, self.remote_profile_dir):
                raise Exception("Failed to copy profile to device")

            if self.is_profiling:
                self.profile_file = profile_file
                mozEnv = {"MOZ_PROFILER_STARTUP": "true"}
            else:
                mozEnv = None

            args.extend(["-profile", self.remote_profile_dir])

            # sometimes fennec fails to start, so we'll try three times...
            for i in range(3):
                print "Launching %s (try %s of 3)" % (self.appname, i + 1)
                if self.dm.launchFennec(self.appname,
                                        url=self.url,
                                        mozEnv=mozEnv,
                                        extraArgs=args):
                    return
            raise Exception("Failed to start Fennec after three tries")
        else:
            self.is_profiling = False  # never profiling with non-fennec browsers
            self.dm.launchApplication(self.appname,
                                      self.activity,
                                      self.intent,
                                      url=self.url)
Example #9
0
    def initialize_user_profile(self):
        # This is broken out from start() so we can call it explicitly if
        # we want to initialize the user profile by starting the app seperate
        # from the test itself
        if self.appname == "com.android.chrome":
            # for chrome, we just delete existing browser state
            # (opened tabs, etc.) so we can start reasonably fresh
            self.dm.shellCheckOutput(
                ["sh", "-c", "rm -f /data/user/0/com.android.chrome/files/*"],
                root=True)
        elif self.appname == "com.google.android.browser":
            # for stock browser, ditto
            self.dm.shellCheckOutput([
                "rm", "-f",
                "/data/user/0/com.google.android.browser/cache/browser_state.parcel"
            ],
                                     root=True)
        elif not self.appname.startswith('org.mozilla'):
            # some other browser which we don't know how to handle, just
            # return
            return

        preferences = {
            'gfx.show_checkerboard_pattern': False,
            'browser.firstrun.show.uidiscovery': False,
            'layers.low-precision-buffer': False,  # bug 815175
            'toolkit.telemetry.prompted': 2,
            'toolkit.telemetry.rejected': True,
            'browser.snippets.enabled': False,
            'browser.snippets.syncPromo.enabled': False
        }
        # Add frame counter to correlate video capture with profile
        if self.enable_profiling:
            preferences['layers.acceleration.frame-counter'] = True

        preferences.update(self.extra_prefs)
        profile = mozprofile.Profile(preferences=preferences)
        self.remote_profile_dir = "/".join(
            [self.dm.getDeviceRoot(),
             os.path.basename(profile.profile)])
        self.dm.pushDir(profile.profile, self.remote_profile_dir)
        if self.preinitialize_user_profile:
            # initialize user profile by launching to about:home then
            # waiting for 10 seconds
            self.launch_fennec(None, "about:home")
            time.sleep(10)
            self.dm.killProcess(self.appname)
Example #10
0
    def createReftestProfile(self,
                             options,
                             manifest,
                             server='localhost',
                             special_powers=True,
                             profile_to_clone=None):
        """
      Sets up a profile for reftest.
      'manifest' is the path to the reftest.list file we want to test with.  This is used in
      the remote subclass in remotereftest.py so we can write it to a preference for the
      bootstrap extension.
    """

        locations = mozprofile.permissions.ServerLocations()
        locations.add_host(server, port=0)
        locations.add_host('<file>', port=0)

        # Set preferences for communication between our command line arguments
        # and the reftest harness.  Preferences that are required for reftest
        # to work should instead be set in reftest-cmdline.js .
        prefs = {}
        prefs['reftest.timeout'] = options.timeout * 1000
        if options.totalChunks:
            prefs['reftest.totalChunks'] = options.totalChunks
        if options.thisChunk:
            prefs['reftest.thisChunk'] = options.thisChunk
        if options.logFile:
            prefs['reftest.logFile'] = options.logFile
        if options.ignoreWindowSize:
            prefs['reftest.ignoreWindowSize'] = True
        if options.filter:
            prefs['reftest.filter'] = options.filter
        if options.shuffle:
            prefs['reftest.shuffle'] = True
        prefs['reftest.focusFilterMode'] = options.focusFilterMode

        # Ensure that telemetry is disabled, so we don't connect to the telemetry
        # server in the middle of the tests.
        prefs['toolkit.telemetry.enabled'] = False
        # Likewise for safebrowsing.
        prefs['browser.safebrowsing.enabled'] = False
        prefs['browser.safebrowsing.malware.enabled'] = False
        # And for snippets.
        prefs['browser.snippets.enabled'] = False
        prefs['browser.snippets.syncPromo.enabled'] = False
        prefs['browser.snippets.firstrunHomepage.enabled'] = False
        # And for useragent updates.
        prefs['general.useragent.updates.enabled'] = False
        # And for webapp updates.  Yes, it is supposed to be an integer.
        prefs['browser.webapps.checkForUpdates'] = 0
        # And for about:newtab content fetch and pings.
        prefs[
            'browser.newtabpage.directory.source'] = 'data:application/json,{"reftest":1}'
        prefs['browser.newtabpage.directory.ping'] = ''

        #Don't use auto-enabled e10s
        prefs['browser.tabs.remote.autostart.1'] = False
        if options.e10s:
            prefs['browser.tabs.remote.autostart'] = True

        for v in options.extraPrefs:
            thispref = v.split('=')
            if len(thispref) < 2:
                print "Error: syntax error in --setpref=" + v
                sys.exit(1)
            prefs[thispref[0]] = mozprofile.Preferences.cast(
                thispref[1].strip())

        # install the reftest extension bits into the profile
        addons = []
        addons.append(os.path.join(SCRIPT_DIRECTORY, "reftest"))

        # I would prefer to use "--install-extension reftest/specialpowers", but that requires tight coordination with
        # release engineering and landing on multiple branches at once.
        if special_powers and (manifest.endswith('crashtests.list')
                               or manifest.endswith('jstests.list')):
            addons.append(os.path.join(SCRIPT_DIRECTORY, 'specialpowers'))
            # SpecialPowers requires insecure automation-only features that we put behind a pref.
            prefs[
                'security.turn_off_all_security_so_that_viruses_can_take_over_this_computer'] = True

        # Install distributed extensions, if application has any.
        distExtDir = os.path.join(options.app[:options.app.rfind(os.sep)],
                                  "distribution", "extensions")
        if os.path.isdir(distExtDir):
            for f in os.listdir(distExtDir):
                addons.append(os.path.join(distExtDir, f))

        # Install custom extensions.
        for f in options.extensionsToInstall:
            addons.append(self.getFullPath(f))

        kwargs = {
            'addons': addons,
            'preferences': prefs,
            'locations': locations
        }
        if profile_to_clone:
            profile = mozprofile.Profile.clone(profile_to_clone, **kwargs)
        else:
            profile = mozprofile.Profile(**kwargs)

        self.copyExtraFilesToProfile(options, profile)
        return profile
Example #11
0
    def createReftestProfile(self,
                             options,
                             manifests,
                             server='localhost',
                             port=0,
                             profile_to_clone=None,
                             startAfter=None):
        """Sets up a profile for reftest.

        :param options: Object containing command line options
        :param manifests: Dictionary of the form {manifest_path: [filters]}
        :param server: Server name to use for http tests
        :param profile_to_clone: Path to a profile to use as the basis for the
                                 test profile
        """

        locations = mozprofile.permissions.ServerLocations()
        locations.add_host(server, scheme='http', port=port)
        locations.add_host(server, scheme='https', port=port)

        # Set preferences for communication between our command line arguments
        # and the reftest harness.  Preferences that are required for reftest
        # to work should instead be set in reftest-preferences.js .
        prefs = {}
        prefs['reftest.timeout'] = options.timeout * 1000
        if options.totalChunks:
            prefs['reftest.totalChunks'] = options.totalChunks
        if options.thisChunk:
            prefs['reftest.thisChunk'] = options.thisChunk
        if options.logFile:
            prefs['reftest.logFile'] = options.logFile
        if options.ignoreWindowSize:
            prefs['reftest.ignoreWindowSize'] = True
        if options.shuffle:
            prefs['reftest.shuffle'] = True
        if options.repeat:
            prefs['reftest.repeat'] = options.repeat
        if options.runUntilFailure:
            prefs['reftest.runUntilFailure'] = True
        if options.cleanupCrashes:
            prefs['reftest.cleanupPendingCrashes'] = True
        prefs['reftest.focusFilterMode'] = options.focusFilterMode
        prefs['reftest.logLevel'] = options.log_tbpl_level or 'info'
        prefs['reftest.manifests'] = json.dumps(manifests)

        if startAfter not in (None, self.TEST_SEEN_INITIAL,
                              self.TEST_SEEN_FINAL):
            self.log.info("Setting reftest.startAfter to %s" % startAfter)
            prefs['reftest.startAfter'] = startAfter

        if options.e10s:
            prefs['browser.tabs.remote.autostart'] = True
            prefs['extensions.e10sBlocksEnabling'] = False

        # Bug 1262954: For winXP + e10s disable acceleration
        if platform.system() in ("Windows", "Microsoft") and \
           '5.1' in platform.version() and options.e10s:
            prefs['layers.acceleration.disabled'] = True

        sandbox_whitelist_paths = [SCRIPT_DIRECTORY]
        try:
            if options.workPath:
                sandbox_whitelist_paths.append(options.workPath)
        except AttributeError:
            pass
        try:
            if options.objPath:
                sandbox_whitelist_paths.append(options.objPath)
        except AttributeError:
            pass
        if (platform.system() == "Linux"
                or platform.system() in ("Windows", "Microsoft")):
            # Trailing slashes are needed to indicate directories on Linux and Windows
            sandbox_whitelist_paths = map(lambda p: os.path.join(p, ""),
                                          sandbox_whitelist_paths)

        # Bug 1300355: Disable canvas cache for win7 as it uses
        # too much memory and causes OOMs.
        if platform.system() in ("Windows", "Microsoft") and \
           '6.1' in platform.version():
            prefs['reftest.nocache'] = True

        if options.marionette:
            port = options.marionette.split(':')[1]
            prefs['marionette.defaultPrefs.port'] = int(port)

        preference_file = os.path.join(here, 'reftest-preferences.js')
        prefs.update(mozprofile.Preferences.read_prefs(preference_file))

        for v in options.extraPrefs:
            thispref = v.split('=')
            if len(thispref) < 2:
                print "Error: syntax error in --setpref=" + v
                sys.exit(1)
            prefs[thispref[0]] = thispref[1].strip()

        addons = []
        if not self.use_marionette:
            addons.append(options.reftestExtensionPath)

        if options.specialPowersExtensionPath is not None:
            if not self.use_marionette:
                addons.append(options.specialPowersExtensionPath)

        for pref in prefs:
            prefs[pref] = mozprofile.Preferences.cast(prefs[pref])

        # Install distributed extensions, if application has any.
        distExtDir = os.path.join(options.app[:options.app.rfind(os.sep)],
                                  "distribution", "extensions")
        if os.path.isdir(distExtDir):
            for f in os.listdir(distExtDir):
                addons.append(os.path.join(distExtDir, f))

        # Install custom extensions.
        for f in options.extensionsToInstall:
            addons.append(self.getFullPath(f))

        kwargs = {
            'addons': addons,
            'preferences': prefs,
            'locations': locations,
            'whitelistpaths': sandbox_whitelist_paths
        }
        if profile_to_clone:
            profile = mozprofile.Profile.clone(profile_to_clone, **kwargs)
        else:
            profile = mozprofile.Profile(**kwargs)

        if os.path.join(here, 'chrome') not in options.extraProfileFiles:
            options.extraProfileFiles.append(os.path.join(here, 'chrome'))

        self.copyExtraFilesToProfile(options, profile)
        return profile
Example #12
0
    def createReftestProfile(self,
                             options,
                             manifests,
                             server='localhost',
                             port=0,
                             profile_to_clone=None):
        """Sets up a profile for reftest.

        :param options: Object containing command line options
        :param manifests: Dictionary of the form {manifest_path: [filters]}
        :param server: Server name to use for http tests
        :param profile_to_clone: Path to a profile to use as the basis for the
                                 test profile"""

        locations = mozprofile.permissions.ServerLocations()
        locations.add_host(server, scheme='http', port=port)
        locations.add_host(server, scheme='https', port=port)

        # Set preferences for communication between our command line arguments
        # and the reftest harness.  Preferences that are required for reftest
        # to work should instead be set in reftest-cmdline.js .
        prefs = {}
        prefs['reftest.timeout'] = options.timeout * 1000
        if options.totalChunks:
            prefs['reftest.totalChunks'] = options.totalChunks
        if options.thisChunk:
            prefs['reftest.thisChunk'] = options.thisChunk
        if options.logFile:
            prefs['reftest.logFile'] = options.logFile
        if options.ignoreWindowSize:
            prefs['reftest.ignoreWindowSize'] = True
        if options.shuffle:
            prefs['reftest.shuffle'] = True
        prefs['reftest.focusFilterMode'] = options.focusFilterMode
        prefs['reftest.manifests'] = json.dumps(manifests)

        # Ensure that telemetry is disabled, so we don't connect to the telemetry
        # server in the middle of the tests.
        prefs['toolkit.telemetry.enabled'] = False
        prefs['toolkit.telemetry.unified'] = False
        # Likewise for safebrowsing.
        prefs['browser.safebrowsing.enabled'] = False
        prefs['browser.safebrowsing.malware.enabled'] = False
        # Likewise for tracking protection.
        prefs['privacy.trackingprotection.enabled'] = False
        prefs['privacy.trackingprotection.pbmode.enabled'] = False
        # And for snippets.
        prefs['browser.snippets.enabled'] = False
        prefs['browser.snippets.syncPromo.enabled'] = False
        prefs['browser.snippets.firstrunHomepage.enabled'] = False
        # And for useragent updates.
        prefs['general.useragent.updates.enabled'] = False
        # And for webapp updates.  Yes, it is supposed to be an integer.
        prefs['browser.webapps.checkForUpdates'] = 0
        # And for about:newtab content fetch and pings.
        prefs[
            'browser.newtabpage.directory.source'] = 'data:application/json,{"reftest":1}'
        prefs['browser.newtabpage.directory.ping'] = ''
        # Only allow add-ons from the profile and app and allow foreign
        # injection
        prefs["extensions.enabledScopes"] = 5
        prefs["extensions.autoDisableScopes"] = 0
        # Allow unsigned add-ons
        prefs['xpinstall.signatures.required'] = False

        # Don't use auto-enabled e10s
        prefs['browser.tabs.remote.autostart.1'] = False
        prefs['browser.tabs.remote.autostart.2'] = False
        if options.e10s:
            prefs['browser.tabs.remote.autostart'] = True

        for v in options.extraPrefs:
            thispref = v.split('=')
            if len(thispref) < 2:
                print "Error: syntax error in --setpref=" + v
                sys.exit(1)
            prefs[thispref[0]] = mozprofile.Preferences.cast(
                thispref[1].strip())

        # install the reftest extension bits into the profile
        addons = [options.reftestExtensionPath]

        if options.specialPowersExtensionPath is not None:
            addons.append(options.specialPowersExtensionPath)
            # SpecialPowers requires insecure automation-only features that we
            # put behind a pref.
            prefs[
                'security.turn_off_all_security_so_that_viruses_can_take_over_this_computer'] = True

        # Install distributed extensions, if application has any.
        distExtDir = os.path.join(options.app[:options.app.rfind(os.sep)],
                                  "distribution", "extensions")
        if os.path.isdir(distExtDir):
            for f in os.listdir(distExtDir):
                addons.append(os.path.join(distExtDir, f))

        # Install custom extensions.
        for f in options.extensionsToInstall:
            addons.append(self.getFullPath(f))

        kwargs = {
            'addons': addons,
            'preferences': prefs,
            'locations': locations
        }
        if profile_to_clone:
            profile = mozprofile.Profile.clone(profile_to_clone, **kwargs)
        else:
            profile = mozprofile.Profile(**kwargs)

        self.copyExtraFilesToProfile(options, profile)
        return profile
Example #13
0
    def createReftestProfile(self, options, manifests, server='localhost', port=0,
                             profile_to_clone=None):
        """Sets up a profile for reftest.

        :param options: Object containing command line options
        :param manifests: Dictionary of the form {manifest_path: [filters]}
        :param server: Server name to use for http tests
        :param profile_to_clone: Path to a profile to use as the basis for the
                                 test profile
        """

        locations = mozprofile.permissions.ServerLocations()
        locations.add_host(server, scheme='http', port=port)
        locations.add_host(server, scheme='https', port=port)

        # Set preferences for communication between our command line arguments
        # and the reftest harness.  Preferences that are required for reftest
        # to work should instead be set in reftest-preferences.js .
        prefs = {}
        prefs['reftest.timeout'] = options.timeout * 1000
        if options.totalChunks:
            prefs['reftest.totalChunks'] = options.totalChunks
        if options.thisChunk:
            prefs['reftest.thisChunk'] = options.thisChunk
        if options.logFile:
            prefs['reftest.logFile'] = options.logFile
        if options.ignoreWindowSize:
            prefs['reftest.ignoreWindowSize'] = True
        if options.shuffle:
            prefs['reftest.shuffle'] = True
        if options.repeat:
            prefs['reftest.repeat'] = options.repeat
        if options.runUntilFailure:
            prefs['reftest.runUntilFailure'] = True
        prefs['reftest.focusFilterMode'] = options.focusFilterMode
        prefs['reftest.logLevel'] = options.log_tbpl_level or 'info'
        prefs['reftest.manifests'] = json.dumps(manifests)

        if options.e10s:
            prefs['browser.tabs.remote.autostart'] = True
            prefs['extensions.e10sBlocksEnabling'] = False

        # Bug 1262954: For winXP + e10s disable acceleration
        if platform.system() in ("Windows", "Microsoft") and \
           '5.1' in platform.version() and options.e10s:
            prefs['layers.acceleration.disabled'] = True

        # Bug 1300355: Disable canvas cache for win7 as it uses
        # too much memory and causes OOMs.
        if platform.system() in ("Windows", "Microsoft") and \
           '6.1' in platform.version():
            prefs['reftest.nocache'] = True

        if options.marionette:
            port = options.marionette.split(':')[1]
            prefs['marionette.defaultPrefs.port'] = int(port)

        preference_file = os.path.join(here, 'reftest-preferences.js')
        prefs.update(mozprofile.Preferences.read_prefs(preference_file))

        for v in options.extraPrefs:
            thispref = v.split('=')
            if len(thispref) < 2:
                print "Error: syntax error in --setpref=" + v
                sys.exit(1)
            prefs[thispref[0]] = thispref[1].strip()

        addons = []
        if not self.use_marionette:
            addons.append(options.reftestExtensionPath)

        if options.specialPowersExtensionPath is not None:
            if not self.use_marionette:
                addons.append(options.specialPowersExtensionPath)
            # SpecialPowers requires insecure automation-only features that we
            # put behind a pref.
            prefs['security.turn_off_all_security_so_that_viruses_can_take_over_this_computer'] = True

        for pref in prefs:
            prefs[pref] = mozprofile.Preferences.cast(prefs[pref])

        # Install distributed extensions, if application has any.
        distExtDir = os.path.join(options.app[:options.app.rfind(os.sep)],
                                  "distribution", "extensions")
        if os.path.isdir(distExtDir):
            for f in os.listdir(distExtDir):
                addons.append(os.path.join(distExtDir, f))

        # Install custom extensions.
        for f in options.extensionsToInstall:
            addons.append(self.getFullPath(f))

        kwargs = {'addons': addons,
                  'preferences': prefs,
                  'locations': locations}
        if profile_to_clone:
            profile = mozprofile.Profile.clone(profile_to_clone, **kwargs)
        else:
            profile = mozprofile.Profile(**kwargs)

        options.extraProfileFiles.append(os.path.join(here, 'chrome'))

        self.copyExtraFilesToProfile(options, profile)
        return profile
Example #14
0
    def createReftestProfile(self,
                             options,
                             tests=None,
                             manifests=None,
                             server='localhost',
                             port=0,
                             profile_to_clone=None,
                             prefs=None):
        """Sets up a profile for reftest.

        :param options: Object containing command line options
        :param tests: List of test objects to run
        :param manifests: List of manifest files to parse (only takes effect
                          if tests were not passed in)
        :param server: Server name to use for http tests
        :param profile_to_clone: Path to a profile to use as the basis for the
                                 test profile
        :param prefs: Extra preferences to set in the profile
        """
        locations = mozprofile.permissions.ServerLocations()
        locations.add_host(server, scheme='http', port=port)
        locations.add_host(server, scheme='https', port=port)

        sandbox_whitelist_paths = options.sandboxReadWhitelist
        if (platform.system() == "Linux"
                or platform.system() in ("Windows", "Microsoft")):
            # Trailing slashes are needed to indicate directories on Linux and Windows
            sandbox_whitelist_paths = map(lambda p: os.path.join(p, ""),
                                          sandbox_whitelist_paths)

        addons = []
        if not self.use_marionette:
            addons.append(options.reftestExtensionPath)

        if options.specialPowersExtensionPath is not None:
            if not self.use_marionette:
                addons.append(options.specialPowersExtensionPath)

        # Install distributed extensions, if application has any.
        distExtDir = os.path.join(options.app[:options.app.rfind(os.sep)],
                                  "distribution", "extensions")
        if os.path.isdir(distExtDir):
            for f in os.listdir(distExtDir):
                addons.append(os.path.join(distExtDir, f))

        # Install custom extensions.
        for f in options.extensionsToInstall:
            addons.append(self.getFullPath(f))

        kwargs = {
            'addons': addons,
            'locations': locations,
            'whitelistpaths': sandbox_whitelist_paths
        }
        if profile_to_clone:
            profile = mozprofile.Profile.clone(profile_to_clone, **kwargs)
        else:
            profile = mozprofile.Profile(**kwargs)

        # First set prefs from the base profiles under testing/profiles.
        profile_data_dir = os.path.join(SCRIPT_DIRECTORY, 'profile_data')

        # If possible, read profile data from topsrcdir. This prevents us from
        # requiring a re-build to pick up newly added extensions in the
        # <profile>/extensions directory.
        if build_obj:
            path = os.path.join(build_obj.topsrcdir, 'testing', 'profiles')
            if os.path.isdir(path):
                profile_data_dir = path

        with open(os.path.join(profile_data_dir, 'profiles.json'), 'r') as fh:
            base_profiles = json.load(fh)['reftest']

        for name in base_profiles:
            path = os.path.join(profile_data_dir, name)
            profile.merge(path)

        # Second set preferences for communication between our command line
        # arguments and the reftest harness. Preferences that are required for
        # reftest to work should instead be set under srcdir/testing/profiles.
        prefs = prefs or {}
        prefs['reftest.timeout'] = options.timeout * 1000
        if options.logFile:
            prefs['reftest.logFile'] = options.logFile
        if options.ignoreWindowSize:
            prefs['reftest.ignoreWindowSize'] = True
        if options.shuffle:
            prefs['reftest.shuffle'] = True
        if options.repeat:
            prefs['reftest.repeat'] = options.repeat
        if options.runUntilFailure:
            prefs['reftest.runUntilFailure'] = True
        if options.verify:
            prefs['reftest.verify'] = True
        if options.cleanupCrashes:
            prefs['reftest.cleanupPendingCrashes'] = True
        prefs['reftest.focusFilterMode'] = options.focusFilterMode
        prefs['reftest.logLevel'] = options.log_tbpl_level or 'info'
        prefs['reftest.suite'] = options.suite
        prefs['gfx.font_ahem_antialias_none'] = True

        # Set tests to run or manifests to parse.
        if tests:
            testlist = os.path.join(profile.profile, 'reftests.json')
            with open(testlist, 'w') as fh:
                json.dump(tests, fh)
            prefs['reftest.tests'] = testlist
        elif manifests:
            prefs['reftest.manifests'] = json.dumps(manifests)

        # Unconditionally update the e10s pref.
        if options.e10s:
            prefs['browser.tabs.remote.autostart'] = True
        else:
            prefs['browser.tabs.remote.autostart'] = False

        if not self.run_by_manifest:
            if options.totalChunks:
                prefs['reftest.totalChunks'] = options.totalChunks
            if options.thisChunk:
                prefs['reftest.thisChunk'] = options.thisChunk

        # Bug 1262954: For winXP + e10s disable acceleration
        if platform.system() in ("Windows", "Microsoft") and \
           '5.1' in platform.version() and options.e10s:
            prefs['layers.acceleration.disabled'] = True

        # Bug 1300355: Disable canvas cache for win7 as it uses
        # too much memory and causes OOMs.
        if platform.system() in ("Windows", "Microsoft") and \
           '6.1' in platform.version():
            prefs['reftest.nocache'] = True

        if options.marionette:
            # options.marionette can specify host:port
            port = options.marionette.split(":")[1]
            prefs["marionette.port"] = int(port)

        # Enable tracing output for detailed failures in case of
        # failing connection attempts, and hangs (bug 1397201)
        prefs["marionette.log.level"] = "Trace"

        # Third, set preferences passed in via the command line.
        for v in options.extraPrefs:
            thispref = v.split('=')
            if len(thispref) < 2:
                print "Error: syntax error in --setpref=" + v
                sys.exit(1)
            prefs[thispref[0]] = thispref[1].strip()

        for pref in prefs:
            prefs[pref] = mozprofile.Preferences.cast(prefs[pref])
        profile.set_preferences(prefs)

        if os.path.join(here, 'chrome') not in options.extraProfileFiles:
            options.extraProfileFiles.append(os.path.join(here, 'chrome'))

        self.copyExtraFilesToProfile(options, profile)
        return profile
Example #15
0
  def createReftestProfile(self, options, manifest, server='localhost',
                           special_powers=True, profile_to_clone=None):
    """
      Sets up a profile for reftest.
      'manifest' is the path to the reftest.list file we want to test with.  This is used in
      the remote subclass in remotereftest.py so we can write it to a preference for the
      bootstrap extension.
    """

    locations = mozprofile.permissions.ServerLocations()
    locations.add_host(server, port=0)
    locations.add_host('<file>', port=0)

    # Set preferences for communication between our command line arguments
    # and the reftest harness.  Preferences that are required for reftest
    # to work should instead be set in reftest-cmdline.js .
    prefs = {}
    prefs['reftest.timeout'] = options.timeout * 1000
    if options.totalChunks:
      prefs['reftest.totalChunks'] = options.totalChunks
    if options.thisChunk:
      prefs['reftest.thisChunk'] = options.thisChunk
    if options.logFile:
      prefs['reftest.logFile'] = options.logFile
    if options.ignoreWindowSize:
      prefs['reftest.ignoreWindowSize'] = True
    if options.filter:
      prefs['reftest.filter'] = options.filter
    if options.shuffle:
      prefs['reftest.shuffle'] = True
    prefs['reftest.focusFilterMode'] = options.focusFilterMode

    # Ensure that telemetry is disabled, so we don't connect to the telemetry
    # server in the middle of the tests.
    prefs['toolkit.telemetry.enabled'] = False

    if options.e10s:
      prefs['browser.tabs.remote.autostart'] = True

    for v in options.extraPrefs:
      thispref = v.split('=')
      if len(thispref) < 2:
        print "Error: syntax error in --setpref=" + v
        sys.exit(1)
      prefs[thispref[0]] = mozprofile.Preferences.cast(thispref[1].strip())

    # install the reftest extension bits into the profile
    addons = []
    addons.append(os.path.join(SCRIPT_DIRECTORY, "reftest"))

    # I would prefer to use "--install-extension reftest/specialpowers", but that requires tight coordination with
    # release engineering and landing on multiple branches at once.
    if special_powers and (manifest.endswith('crashtests.list') or manifest.endswith('jstests.list')):
      addons.append(os.path.join(SCRIPT_DIRECTORY, 'specialpowers'))

    # Install distributed extensions, if application has any.
    distExtDir = os.path.join(options.app[ : options.app.rfind(os.sep)], "distribution", "extensions")
    if os.path.isdir(distExtDir):
      for f in os.listdir(distExtDir):
        addons.append(os.path.join(distExtDir, f))

    # Install custom extensions.
    for f in options.extensionsToInstall:
      addons.append(self.getFullPath(f))

    kwargs = { 'addons': addons,
               'preferences': prefs,
               'locations': locations }
    if profile_to_clone:
        profile = mozprofile.Profile.clone(profile_to_clone, **kwargs)
    else:
        profile = mozprofile.Profile(**kwargs)

    self.copyExtraFilesToProfile(options, profile)
    return profile
Example #16
0
    args = parser.parse_args()

    os.chdir(args.root)

    host = moznetwork.get_ip()
    port = NetworkTools().findOpenPort(host, 8000)
    args.url = "http://%s:%d/%s" % (host, port, args.fuzzer)

    # Setup HTTPd
    server = mozhttpd.MozHttpd(port=port, host=host, docroot=args.root)
    server.start()

    # Setup B2G and Firefox preferences
    pref = mozprofile.Preferences()
    pref.add(pref.read_prefs(args.prefs))
    profile = mozprofile.Profile(preferences=pref())  # Bug 908793

    # Setup Marionette
    marionette = marionette.Marionette(
        emulator='arm',
        homedir=args.b2g_dir,
        symbols_path=args.symbols_path,
        gecko_path=None,
        #logcat_dir=args.logcat_dir
    )

    # Setup DeviceManager for ADB
    device = mozdevice.DeviceManagerADB(loglevel=10)

    # Setup B2G with profile and marionette over ADB
    runner = mozrunner.B2GRunner(profile,
def test_str_cast():
    """Test casting to a string."""
    profile = mozprofile.Profile()
    assert str(profile) == profile.summary().encode("utf-8")
Example #18
0
    def createReftestProfile(self, options, tests=None, manifests=None,
                             server='localhost', port=0, profile_to_clone=None,
                             startAfter=None, prefs=None):
        """Sets up a profile for reftest.

        :param options: Object containing command line options
        :param tests: List of test objects to run
        :param manifests: List of manifest files to parse (only takes effect
                          if tests were not passed in)
        :param server: Server name to use for http tests
        :param profile_to_clone: Path to a profile to use as the basis for the
                                 test profile
        :param startAfter: Start running tests after the specified test id
        :param prefs: Extra preferences to set in the profile
        """
        locations = mozprofile.permissions.ServerLocations()
        locations.add_host(server, scheme='http', port=port)
        locations.add_host(server, scheme='https', port=port)

        # Set preferences for communication between our command line arguments
        # and the reftest harness.  Preferences that are required for reftest
        # to work should instead be set in reftest-preferences.js .
        prefs = prefs or {}
        prefs['reftest.timeout'] = options.timeout * 1000
        if options.logFile:
            prefs['reftest.logFile'] = options.logFile
        if options.ignoreWindowSize:
            prefs['reftest.ignoreWindowSize'] = True
        if options.shuffle:
            prefs['reftest.shuffle'] = True
        if options.repeat:
            prefs['reftest.repeat'] = options.repeat
        if options.runUntilFailure:
            prefs['reftest.runUntilFailure'] = True
        if options.verify:
            prefs['reftest.verify'] = True
        if options.cleanupCrashes:
            prefs['reftest.cleanupPendingCrashes'] = True
        prefs['reftest.focusFilterMode'] = options.focusFilterMode
        prefs['reftest.logLevel'] = options.log_tbpl_level or 'info'
        prefs['reftest.suite'] = options.suite

        if startAfter not in (None, self.TEST_SEEN_INITIAL, self.TEST_SEEN_FINAL):
            self.log.info("Setting reftest.startAfter to %s" % startAfter)
            prefs['reftest.startAfter'] = startAfter

        # Unconditionally update the e10s pref.
        if options.e10s:
            prefs['browser.tabs.remote.autostart'] = True
        else:
            prefs['browser.tabs.remote.autostart'] = False

        # Bug 1262954: For winXP + e10s disable acceleration
        if platform.system() in ("Windows", "Microsoft") and \
           '5.1' in platform.version() and options.e10s:
            prefs['layers.acceleration.disabled'] = True

        sandbox_whitelist_paths = options.sandboxReadWhitelist
        if (platform.system() == "Linux" or
            platform.system() in ("Windows", "Microsoft")):
            # Trailing slashes are needed to indicate directories on Linux and Windows
            sandbox_whitelist_paths = map(lambda p: os.path.join(p, ""),
                                          sandbox_whitelist_paths)

        # Bug 1300355: Disable canvas cache for win7 as it uses
        # too much memory and causes OOMs.
        if platform.system() in ("Windows", "Microsoft") and \
           '6.1' in platform.version():
            prefs['reftest.nocache'] = True

        if options.marionette:
            # options.marionette can specify host:port
            port = options.marionette.split(":")[1]
            prefs["marionette.port"] = int(port)

        # Enable tracing output for detailed failures in case of
        # failing connection attempts, and hangs (bug 1397201)
        prefs["marionette.log.level"] = "TRACE"

        preference_file = os.path.join(here, 'reftest-preferences.js')
        prefs.update(mozprofile.Preferences.read_prefs(preference_file))

        for v in options.extraPrefs:
            thispref = v.split('=')
            if len(thispref) < 2:
                print "Error: syntax error in --setpref=" + v
                sys.exit(1)
            prefs[thispref[0]] = thispref[1].strip()

        addons = []
        if not self.use_marionette:
            addons.append(options.reftestExtensionPath)

        if options.specialPowersExtensionPath is not None:
            if not self.use_marionette:
                addons.append(options.specialPowersExtensionPath)

        for pref in prefs:
            prefs[pref] = mozprofile.Preferences.cast(prefs[pref])

        # Install distributed extensions, if application has any.
        distExtDir = os.path.join(options.app[:options.app.rfind(os.sep)],
                                  "distribution", "extensions")
        if os.path.isdir(distExtDir):
            for f in os.listdir(distExtDir):
                addons.append(os.path.join(distExtDir, f))

        # Install custom extensions.
        for f in options.extensionsToInstall:
            addons.append(self.getFullPath(f))

        kwargs = {'addons': addons,
                  'preferences': prefs,
                  'locations': locations,
                  'whitelistpaths': sandbox_whitelist_paths}
        if profile_to_clone:
            profile = mozprofile.Profile.clone(profile_to_clone, **kwargs)
        else:
            profile = mozprofile.Profile(**kwargs)

        if tests:
            testlist = os.path.join(profile.profile, 'reftests.json')
            with open(testlist, 'w') as fh:
                json.dump(tests, fh)
            profile.set_preferences({'reftest.tests': testlist})
        elif manifests:
            profile.set_preferences({'reftest.manifests': json.dumps(manifests)})

        if os.path.join(here, 'chrome') not in options.extraProfileFiles:
            options.extraProfileFiles.append(os.path.join(here, 'chrome'))

        self.copyExtraFilesToProfile(options, profile)
        return profile
Example #19
0
def profile():
    return mozprofile.Profile()
Example #20
0
    def createReftestProfile(
        self,
        options,
        tests=None,
        manifests=None,
        server="localhost",
        port=0,
        profile_to_clone=None,
        prefs=None,
    ):
        """Sets up a profile for reftest.

        :param options: Object containing command line options
        :param tests: List of test objects to run
        :param manifests: List of manifest files to parse (only takes effect
                          if tests were not passed in)
        :param server: Server name to use for http tests
        :param profile_to_clone: Path to a profile to use as the basis for the
                                 test profile
        :param prefs: Extra preferences to set in the profile
        """
        locations = mozprofile.permissions.ServerLocations()
        locations.add_host(server, scheme="http", port=port)
        locations.add_host(server, scheme="https", port=port)

        sandbox_whitelist_paths = options.sandboxReadWhitelist
        if platform.system() == "Linux" or platform.system() in (
                "Windows",
                "Microsoft",
        ):
            # Trailing slashes are needed to indicate directories on Linux and Windows
            sandbox_whitelist_paths = map(lambda p: os.path.join(p, ""),
                                          sandbox_whitelist_paths)

        addons = []
        if not self.use_marionette:
            addons.append(options.reftestExtensionPath)

        if options.specialPowersExtensionPath is not None:
            if not self.use_marionette:
                addons.append(options.specialPowersExtensionPath)

        # Install distributed extensions, if application has any.
        distExtDir = os.path.join(options.app[:options.app.rfind(os.sep)],
                                  "distribution", "extensions")
        if os.path.isdir(distExtDir):
            for f in os.listdir(distExtDir):
                addons.append(os.path.join(distExtDir, f))

        # Install custom extensions.
        for f in options.extensionsToInstall:
            addons.append(self.getFullPath(f))

        kwargs = {
            "addons": addons,
            "locations": locations,
            "whitelistpaths": sandbox_whitelist_paths,
        }
        if profile_to_clone:
            profile = mozprofile.Profile.clone(profile_to_clone, **kwargs)
        else:
            profile = mozprofile.Profile(**kwargs)

        # First set prefs from the base profiles under testing/profiles.

        # In test packages used in CI, the profile_data directory is installed
        # in the SCRIPT_DIRECTORY.
        profile_data_dir = os.path.join(SCRIPT_DIRECTORY, "profile_data")
        # If possible, read profile data from topsrcdir. This prevents us from
        # requiring a re-build to pick up newly added extensions in the
        # <profile>/extensions directory.
        if build_obj:
            path = os.path.join(build_obj.topsrcdir, "testing", "profiles")
            if os.path.isdir(path):
                profile_data_dir = path
        # Still not found? Look for testing/profiles relative to layout/tools/reftest.
        if not os.path.isdir(profile_data_dir):
            path = os.path.abspath(
                os.path.join(SCRIPT_DIRECTORY, "..", "..", "..", "testing",
                             "profiles"))
            if os.path.isdir(path):
                profile_data_dir = path

        with open(os.path.join(profile_data_dir, "profiles.json"), "r") as fh:
            base_profiles = json.load(fh)["reftest"]

        for name in base_profiles:
            path = os.path.join(profile_data_dir, name)
            profile.merge(path)

        # Second set preferences for communication between our command line
        # arguments and the reftest harness. Preferences that are required for
        # reftest to work should instead be set under srcdir/testing/profiles.
        prefs = prefs or {}
        prefs["reftest.timeout"] = options.timeout * 1000
        if options.logFile:
            prefs["reftest.logFile"] = options.logFile
        if options.ignoreWindowSize:
            prefs["reftest.ignoreWindowSize"] = True
        if options.shuffle:
            prefs["reftest.shuffle"] = True
        if options.repeat:
            prefs["reftest.repeat"] = options.repeat
        if options.runUntilFailure:
            prefs["reftest.runUntilFailure"] = True
            if not options.repeat:
                prefs["reftest.repeat"] = 30
        if options.verify:
            prefs["reftest.verify"] = True
        if options.cleanupCrashes:
            prefs["reftest.cleanupPendingCrashes"] = True
        prefs["reftest.focusFilterMode"] = options.focusFilterMode
        prefs["reftest.logLevel"] = options.log_tbpl_level or "info"
        prefs["reftest.suite"] = options.suite
        prefs["gfx.font_rendering.ahem_antialias_none"] = True
        # Run the "deferred" font-loader immediately, because if it finishes
        # mid-test, the extra reflow that is triggered can disrupt the test.
        prefs["gfx.font_loader.delay"] = 0
        prefs["gfx.font_loader.interval"] = 0
        # Ensure bundled fonts are activated, even if not enabled by default
        # on the platform, so that tests can rely on them.
        prefs["gfx.bundled-fonts.activate"] = 1
        # Disable dark scrollbars because it's semi-transparent.
        prefs["widget.disable-dark-scrollbar"] = True
        prefs["reftest.isCoverageBuild"] = mozinfo.info.get("ccov", False)

        # config specific flags
        prefs["sandbox.apple_silicon"] = mozinfo.info.get(
            "apple_silicon", False)

        # Set tests to run or manifests to parse.
        if tests:
            testlist = os.path.join(profile.profile, "reftests.json")
            with open(testlist, "w") as fh:
                json.dump(tests, fh)
            prefs["reftest.tests"] = testlist
        elif manifests:
            prefs["reftest.manifests"] = json.dumps(manifests)

        # Unconditionally update the e10s pref.
        if options.e10s:
            prefs["browser.tabs.remote.autostart"] = True
        else:
            prefs["browser.tabs.remote.autostart"] = False

        if options.fission:
            prefs["fission.autostart"] = True
        else:
            prefs["fission.autostart"] = False

        if not self.run_by_manifest:
            if options.totalChunks:
                prefs["reftest.totalChunks"] = options.totalChunks
            if options.thisChunk:
                prefs["reftest.thisChunk"] = options.thisChunk

        # Bug 1262954: For winXP + e10s disable acceleration
        if (platform.system() in ("Windows", "Microsoft")
                and "5.1" in platform.version() and options.e10s):
            prefs["layers.acceleration.disabled"] = True

        # Bug 1300355: Disable canvas cache for win7 as it uses
        # too much memory and causes OOMs.
        if (platform.system() in ("Windows", "Microsoft")
                and "6.1" in platform.version()):
            prefs["reftest.nocache"] = True

        if options.marionette:
            # options.marionette can specify host:port
            port = options.marionette.split(":")[1]
            prefs["marionette.port"] = int(port)

        # Enable tracing output for detailed failures in case of
        # failing connection attempts, and hangs (bug 1397201)
        prefs["marionette.log.level"] = "Trace"

        # Third, set preferences passed in via the command line.
        for v in options.extraPrefs:
            thispref = v.split("=")
            if len(thispref) < 2:
                print("Error: syntax error in --setpref=" + v)
                sys.exit(1)
            prefs[thispref[0]] = thispref[1].strip()

        for pref in prefs:
            prefs[pref] = mozprofile.Preferences.cast(prefs[pref])
        profile.set_preferences(prefs)

        if os.path.join(here, "chrome") not in options.extraProfileFiles:
            options.extraProfileFiles.append(os.path.join(here, "chrome"))

        self.copyExtraFilesToProfile(options, profile)
        return profile
def test_unicode_cast():
    """Test casting to a unicode string."""
    profile = mozprofile.Profile()
    assert text_type(profile) == profile.summary()