Esempio n. 1
0
    def test_profile_addon_cleanup(self):

        # sanity check: the empty addon should be here
        self.assertTrue(os.path.exists(self.addon))
        self.assertTrue(os.path.isdir(self.addon))
        self.assertTrue(os.path.exists(os.path.join(self.addon,
                                                    'install.rdf')))

        # because we are testing data loss, let's make sure we make a copy
        shutil.rmtree(self.tmpdir)
        shutil.copytree(self.addon, self.tmpdir)
        self.assertTrue(
            os.path.exists(os.path.join(self.tmpdir, 'install.rdf')))

        # make a starter profile
        profile = mozprofile.FirefoxProfile()
        path = profile.profile

        # make a new profile based on the old
        newprofile = mozprofile.FirefoxProfile(profile=path,
                                               addons=[self.tmpdir])
        newprofile.cleanup()

        # the source addon *should* still exist
        self.assertTrue(os.path.exists(self.tmpdir))
        self.assertTrue(
            os.path.exists(os.path.join(self.tmpdir, 'install.rdf')))
Esempio n. 2
0
def test_profile_addon_cleanup(tmpdir):
    tmpdir = tmpdir.mkdtemp().strpath
    addon = os.path.join(here, "addons", "empty")

    # sanity check: the empty addon should be here
    assert os.path.exists(addon)
    assert os.path.isdir(addon)
    assert os.path.exists(os.path.join(addon, "install.rdf"))

    # because we are testing data loss, let's make sure we make a copy
    shutil.rmtree(tmpdir)
    shutil.copytree(addon, tmpdir)
    assert os.path.exists(os.path.join(tmpdir, "install.rdf"))

    # make a starter profile
    profile = mozprofile.FirefoxProfile()
    path = profile.profile

    # make a new profile based on the old
    newprofile = mozprofile.FirefoxProfile(profile=path, addons=[tmpdir])
    newprofile.cleanup()

    # the source addon *should* still exist
    assert os.path.exists(tmpdir)
    assert os.path.exists(os.path.join(tmpdir, "install.rdf"))
Esempio n. 3
0
    def test_profile_addon_cleanup(self):

        # sanity check: the empty addon should be here
        empty = os.path.join(here, 'addons', 'empty')
        self.assertTrue(os.path.exists(empty))
        self.assertTrue(os.path.isdir(empty))
        self.assertTrue(os.path.exists(os.path.join(empty, 'install.rdf')))

        # because we are testing data loss, let's make sure we make a copy
        tmpdir = tempfile.mktemp()
        shutil.copytree(empty, tmpdir)
        self.assertTrue(os.path.exists(os.path.join(tmpdir, 'install.rdf')))

        # make a starter profile
        profile = mozprofile.FirefoxProfile()
        path = profile.profile

        # make a new profile based on the old
        newprofile = mozprofile.FirefoxProfile(profile=path, addons=[tmpdir])
        newprofile.cleanup()

        # the source addon *should* still exist
        self.assertTrue(os.path.exists(tmpdir))
        self.assertTrue(os.path.exists(os.path.join(tmpdir, 'install.rdf')))

        # remove vestiges
        shutil.rmtree(tmpdir)
Esempio n. 4
0
    def setUp(self):
        self.pids = []
        self.threads = []

        self.profile = mozprofile.FirefoxProfile()
        self.runner = mozrunner.FirefoxRunner(os.environ['BROWSER_PATH'],
                                              profile=self.profile)
    def test_profileprint(self):
        """
        test the summary function
        """

        keys = set(['Files', 'Path', 'user.js'])
        ff_prefs = mozprofile.FirefoxProfile.preferences  # shorthand
        pref_string = '\n'.join([
            '%s: %s' % (key, ff_prefs[key]) for key in sorted(ff_prefs.keys())
        ])

        tempdir = tempfile.mkdtemp()
        try:
            profile = mozprofile.FirefoxProfile(tempdir)
            parts = profile.summary(return_parts=True)
            parts = dict(parts)

            self.assertEqual(parts['Path'], tempdir)
            self.assertEqual(set(parts.keys()), keys)
            self.assertEqual(pref_string, parts['user.js'].strip())

        except BaseException:
            raise
        finally:
            mozfile.rmtree(tempdir)
def test_profileprint(tmpdir):
    """Test the summary function."""
    keys = set(['Files', 'Path'])

    tmpdir = tmpdir.strpath
    profile = mozprofile.FirefoxProfile(tmpdir)
    parts = profile.summary(return_parts=True)
    parts = dict(parts)

    assert parts['Path'] == tmpdir
    assert set(parts.keys()) == keys
Esempio n. 7
0
def test_profileprint(tmpdir):
    """
    test the summary function
    """

    keys = set(['Files', 'Path', 'user.js'])
    ff_prefs = mozprofile.FirefoxProfile.preferences  # shorthand
    pref_string = '\n'.join(['%s: %s' % (key, ff_prefs[key])
                             for key in sorted(ff_prefs.keys())])

    tmpdir = tmpdir.strpath
    profile = mozprofile.FirefoxProfile(tmpdir)
    parts = profile.summary(return_parts=True)
    parts = dict(parts)

    assert parts['Path'] == tmpdir
    assert set(parts.keys()) == keys
    assert pref_string == parts['user.js'].strip()
    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))
Esempio n. 9
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)
Esempio n. 10
0
    def run_test(self, testname, testvars={}):
        if not self.ready:
            return self.error("run_test() called before setup")

        self.info("Beginning marionette test '%s'" % testname)

        e10s = testvars.get("e10s", False)

        prefs = {
            # disable network access
            "network.proxy.socks": "localhost",
            "network.proxy.socks_port": testvars.get("proxyPort", 90000),
            "network.proxy.socks_remote_dns": True,
            "network.proxy.type": 1,  # Socks

            # Don't open the first-run dialog, it loads a video
            'startup.homepage_welcome_url': '',
            'startup.homepage_override_url': '',
            'browser.newtab.url': 'about:blank',

            # make sure e10s is enabled
            "browser.tabs.remote.autostart": e10s,
            "browser.tabs.remote.autostart.1": e10s,
            "browser.tabs.remote.autostart.2": e10s,

            # We're not testing flash memory usage. Also: it likes to crash in VNC sessions.
            "plugin.disable": True,

            # Specify a communications port
            "marionette.defaultPrefs.port": self.port,

            # override image expiration in hopes of getting less volatile numbers
            "image.mem.surfacecache.min_expiration_ms": 10000
        }

        # Setup a test runner with our prefs and a default logger.
        # TODO(ER): We might want to use a larger set of "automation" preferences
        #           until marionette sets them for us. See bug 1123683.
        profile = mozprofile.FirefoxProfile(preferences=prefs)

        debug = testvars.get("debug", False)
        if debug:
            commandline.formatter_option_defaults['level'] = 'debug'

        logger = commandline.setup_logging("MarionetteTest", {})
        runner = MarionetteTestRunner(binary=self.tester.binary,
                                      profile=profile,
                                      logger=logger,
                                      address="localhost:%d" % self.port,
                                      gecko_log=self.gecko_log,
                                      startup_timeout=60)

        # Add test
        testpath = os.path.join(*testvars['test'])
        if not os.path.exists(testpath):
            return self.error(
                "Test '%s' specifies a test that doesn't exist: %s" %
                (testname, testpath))

        # Add our testvars
        runner.testvars.update(testvars)

        # Run test
        self.info("Marionette - starting browser")
        try:
            self.info("Marionette - running test")
            runner.run_tests([testpath])
            failures = runner.failed
        except Exception, e:
            try:
                runner.cleanup()
            except:
                pass
            return self.error("Marionette test run failed -- %s: %s" %
                              (type(e), e))
Esempio n. 11
0
    def open_urls(self, urls, marionette_port=24242):
        testvars = {
            'perTabPause': self.per_tab_pause,
            'settleWaitTime': self.settle_wait_time,
            'entities': len(urls),
            'urls': urls,
            'stats': self.stats,
        }

        e10s = self.process_count > 0

        prefs = {

            # Don't open the first-run dialog, it loads a video
            'startup.homepage_welcome_url': '',
            'startup.homepage_override_url': '',
            'browser.newtab.url': 'about:blank',

            # make sure e10s is enabled
            "browser.tabs.remote.autostart": e10s,
            "browser.tabs.remote.autostart.1": e10s,
            "browser.tabs.remote.autostart.2": e10s,
            "browser.tabs.remote.autostart.3": e10s,
            "browser.tabs.remote.autostart.4": e10s,
            "browser.tabs.remote.autostart.5": e10s,
            "browser.tabs.remote.autostart.6": e10s,
            "dom.ipc.processCount": self.process_count,

            # prevent "You're using e10s!" dialog from showing up
            "browser.displayedE10SNotice": 1000,

            # override image expiration in hopes of getting less volatile
            # numbers
            "image.mem.surfacecache.min_expiration_ms": 10000,

            # Specify a communications port
            "marionette.defaultPrefs.port": marionette_port,
        }

        if self.proxy:
            # disable network access
            prefs.update({
                "network.proxy.socks": self.proxy,
                "network.proxy.socks_port": self.proxy_port,
                "network.proxy.socks_remote_dns": True,
                "network.proxy.type": 1,  # Socks
            })

        profile = mozprofile.FirefoxProfile(preferences=prefs)

        # TODO(ER): Figure out how to turn on debug level info again
        #commandline.formatter_option_defaults['level'] = 'debug'

        logger = commandline.setup_logging("MarionetteTest", {})
        runner = MarionetteTestRunner(binary=self.binary,
                                      profile=profile,
                                      logger=logger,
                                      startup_timeout=60,
                                      address="localhost:%d" % marionette_port,
                                      gecko_log="gecko_%d.log" %
                                      self.process_count)

        # Add our testvars
        runner.testvars.update(testvars)

        test_path = os.path.join(MODULE_DIR, "test_memory_usage.py")
        try:
            print "Marionette - running test"
            runner.run_tests([test_path])
            failures = runner.failed
        except Exception, e:
            print e
            pass
Esempio n. 12
0
    def setUp(self):
        self.pids = []
        self.threads = [ ]

        self.profile = mozprofile.FirefoxProfile()
        self.runner = mozrunner.FirefoxRunner(self.profile)