コード例 #1
0
    def test_01_default_profile_path(self):
        logging.info("Start test_01_default_profile_path")

        # Setup test directory
        TMPDIR = self.setup_test_directory(True, False)

        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)

        # Get default profile
        self.assertEqual(
            os.path.join(TMPDIR, "robuvvg2.default"),
            firefox_logger.get_default_profile_path())

        # Try to get a default profile from a file without a default one
        self.file_set_contents(
            os.path.join(TMPDIR, "profiles.ini"),
            PROFILES_FILE_CONTENT_NO_DEFAULT)
        self.assertEqual(
            None,
            firefox_logger.get_default_profile_path())

        # Try to read a wrong profiles file
        self.file_set_contents(
            os.path.join(TMPDIR, "profiles.ini"),
            "RESISTANCE IS FUTILE")
        self.assertEqual(
            None,
            firefox_logger.get_default_profile_path())

        logging.info("End test_01_default_profile_path")
コード例 #2
0
    def test_06_profiles_file_monitoring(self):
        logging.info("Start test_06_profiles_file_monitoring")

        # Setup test directory
        TMPDIR = self.setup_test_directory(False, False)

        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)

        # Profiles file is not present. It should not be initialized
        self.assertFalse(firefox_logger.default_profile_initialized)

        # File monitor should be set and waiting for changes
        self.assertTrue(
            os.path.join(TMPDIR, "profiles.ini") in
            firefox_logger.file_monitors)

        # Setup callback for profiles file update
        firefox_logger.test_profiles_file_updated = ml.quit

        # Setup a timeout for this test to quit and fail if timeout is reached
        timeout = GLib.timeout_add(1000, mainloop_quit_callback)

        # Add profiles file
        self.file_set_contents(os.path.join(TMPDIR, "profiles.ini"),
                               PROFILES_FILE_CONTENT)

        # Execute main loop
        ml.run()
        # Default profile preferences should be initialized at this point
        self.assertTrue(firefox_logger.default_profile_initialized)

        logging.info("End test_06_profiles_file_monitoring")
コード例 #3
0
    def test_03_profiles_file_load(self):
        logging.info("Start test_03_profiles_file_load")

        # Setup test directory with profile file
        TMPDIR = self.setup_test_directory(True, False)
        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)
        # Profiles file is present. It should be initialized
        self.assertTrue(firefox_logger.default_profile_initialized)
        # Also there souldn't be any file monitor for it
        self.assertFalse(
            os.path.join(TMPDIR, "/profiles.ini") in
            firefox_logger.file_monitors)

        logging.info("End test_03_profiles_file_load")
コード例 #4
0
    def test_02_read_preferences(self):
        logging.info("Start test_02_read_preferences")

        # Setup test directory
        TMPDIR = self.setup_test_directory(True, False)
        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)

        # Get preferences from given data
        returned = firefox_logger.load_firefox_preferences(RAW_PREFS_DATA)

        self.assertEqual(json.dumps(DEFAULT_PREFERENCES_DATA, sort_keys=True),
                         json.dumps(returned, sort_keys=True))

        logging.info("End test_02_read_preferences")
コード例 #5
0
    def test_08_preferences_file_monitoring(self):
        logging.info("Start test_08_preferences_file_monitoring")

        # Setup test directory
        TMPDIR = self.setup_test_directory(True, False)

        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)
        prefs_path = os.path.join(TMPDIR, "robuvvg2.default/prefs.js")

        # Profiles file is present. It should be initialized
        self.assertTrue(firefox_logger.default_profile_initialized)

        # Preferences file is not present. It shouldn't be initialized
        self.assertFalse(firefox_logger.default_profile_prefs_initialized)

        # Preferences data should be empty
        self.assertEqual(
            json.dumps({}),
            json.dumps(firefox_logger.monitored_preferences))

        # Setup callback on profiles file update
        firefox_logger.test_prefs_file_updated = ml.quit

        # Setup a timeout for this test to quit and fail if timeout is reached
        timeout = GLib.timeout_add(
            1000,
            mainloop_quit_callback)

        # Add profiles file
        self.file_set_contents(
            prefs_path,
            RAW_PREFS_DATA)

        # Execute main loop
        ml.run()

        # Preferences file is now present. It should be initialized
        self.assertTrue(firefox_logger.default_profile_prefs_initialized)

        # Default preference data should be loaded
        self.assertEqual(
            json.dumps({prefs_path: DEFAULT_PREFERENCES_DATA}, sort_keys=True),
            json.dumps(firefox_logger.monitored_preferences, sort_keys=True))

        logging.info("End test_08_preferences_file_monitoring")
コード例 #6
0
    def test_07_preferences_file_monitoring_wrong(self):
        logging.info("Start test_07_preferences_file_monitoring_wrong")

        # Setup test directory
        TMPDIR = self.setup_test_directory(True, False)

        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)
        prefs_path = os.path.join(TMPDIR, "robuvvg2.default/prefs.js")
        # Profiles file is present. It should be initialized
        self.assertTrue(firefox_logger.default_profile_initialized)

        # Default profile preferences file is not present. Shouldn't be initialized
        self.assertFalse(firefox_logger.default_profile_prefs_initialized)

        # Current preferences should be empty
        self.assertEqual(
            json.dumps({}),
            json.dumps(firefox_logger.monitored_preferences))

        # Setup callback on profiles file update
        firefox_logger.test_prefs_file_updated = ml.quit

        # Setup a timeout for this test to quit and fail if timeout is reached
        timeout = GLib.timeout_add(
            1000,
            mainloop_quit_callback)

        # Add profiles file
        self.file_set_contents(
            prefs_path,
            "WRONG CONTENT")

        # Execute main loop
        ml.run()

        # Default profile preferences should be initialized as empty due to
        # wrong contents
        self.assertTrue(firefox_logger.default_profile_prefs_initialized)

        # Wrong content only leads to empty preferences
        self.assertEqual(
            json.dumps({prefs_path: {}}),
            json.dumps(firefox_logger.monitored_preferences))

        logging.info("End test_07_preferences_file_monitoring_wrong")
コード例 #7
0
    def test_04_profiles_file_load_wrong(self):
        logging.info("Start test_04_profiles_file_load_wrong")

        # Setup test directory without profile file
        TMPDIR = self.setup_test_directory(False, False)
        # Add profiles file without default profile
        self.file_set_contents(os.path.join(TMPDIR, "profiles.ini"),
                               PROFILES_FILE_CONTENT_NO_DEFAULT)
        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)
        # Profiles file is present but wrong. It shouldn't be initialized
        self.assertFalse(firefox_logger.default_profile_initialized)
        # Also there souldn't be a file monitor for it
        self.assertTrue(
            os.path.join(TMPDIR, "profiles.ini") in
            firefox_logger.file_monitors)

        logging.info("End test_04_profiles_file_load_wrong")
コード例 #8
0
    def test_09_preferences_file_loading(self):
        logging.info("Start test_09_preferences_file_loading")

        # Setup test directory
        TMPDIR = self.setup_test_directory(True, True)

        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)
        prefs_path = os.path.join(TMPDIR, "robuvvg2.default/prefs.js")

        # Profiles file is present. It should be initialized
        self.assertTrue(firefox_logger.default_profile_initialized)

        # Preferences file is now present. It should be initialized
        self.assertTrue(firefox_logger.default_profile_prefs_initialized)

        # Default preference data should be loaded
        self.assertEqual(
            json.dumps({prefs_path: DEFAULT_PREFERENCES_DATA}, sort_keys=True),
            json.dumps(firefox_logger.monitored_preferences, sort_keys=True))

        logging.info("End test_09_preferences_file_loading")
コード例 #9
0
    def test_10_preferences_update(self):
        logging.info("Start test_10_preferences_update")

        # Setup test directory
        TMPDIR = self.setup_test_directory(True, True)

        mgr = MockConnectionManager()
        firefox_logger = FleetCommander.FirefoxLogger(mgr, TMPDIR)
        prefs_path = os.path.join(TMPDIR, "robuvvg2.default/prefs.js")

        # Profiles file is present. It should be initialized
        self.assertTrue(firefox_logger.default_profile_initialized)

        # Preferences file is now present. It should be initialized
        self.assertTrue(firefox_logger.default_profile_prefs_initialized)

        # Default preference data should be loaded
        self.assertEqual(
            json.dumps({prefs_path: DEFAULT_PREFERENCES_DATA}, sort_keys=True),
            json.dumps(firefox_logger.monitored_preferences, sort_keys=True))

        # Setup callback on profiles file update
        firefox_logger.test_prefs_file_updated = ml.quit

        # Setup a timeout for this test to quit and fail if timeout is reached
        timeout = GLib.timeout_add(1000, mainloop_quit_callback)

        # Overwrite profiles file with modified data
        self.file_set_contents(prefs_path, RAW_PREFS_DATA_MODIFIED)

        # Execute main loop
        ml.run()

        # Check preference data has been updated
        self.assertEqual(
            json.dumps({prefs_path: UPDATED_PREFERENCES_DATA}, sort_keys=True),
            json.dumps(firefox_logger.monitored_preferences, sort_keys=True))

        # Changes queue length should be 3
        self.assertEqual(3, len(mgr.log))

        # Config changes should be submitted
        settings = [
            json.dumps([
                "org.mozilla.firefox",
                json.dumps(
                    {
                        "key": "accessibility.typeaheadfind.flashBar",
                        "value": 1
                    },
                    sort_keys=True)
            ]),
            json.dumps([
                "org.mozilla.firefox",
                json.dumps(
                    {
                        "key": "browser.newtabpage.enhanced",
                        "value": True
                    },
                    sort_keys=True)
            ]),
            json.dumps([
                "org.mozilla.firefox",
                json.dumps({
                    "key": "browser.newtabpage.testValue",
                    "value": 1
                },
                           sort_keys=True)
            ]),
        ]

        while len(mgr.log) > 0:
            setting = mgr.log.pop(0)
            jsonsetting = json.dumps(setting)
            self.assertTrue(jsonsetting in settings)

        # Changes queue length should be 0
        self.assertEqual(0, len(mgr.log))

        logging.info("End test_10_preferences_update")