예제 #1
0
    def test_pref_help_added_to_bare_strings(self):
        """Test that a help messages about passing literals directly to
        APIs is added only to bare strings."""

        self.run_script("""
            'browser.startup.homepage';
            Preferences.set('browser.startup.homepage');
        """)

        warnings = self.err.warnings
        self.assert_warnings({'id': PREFERENCE_ERROR_ID},
                             {'id': ('testcases_javascript_actions',
                                     '_call_expression',
                                     'called_set_preference')},
                             exhaustive=True)

        # Check that descriptions and help are the same, except for
        # an added message in the bare string.
        for key in 'description', 'signing_help':
            val1 = maybe_tuple(warnings[0][key])
            val2 = maybe_tuple(warnings[1][key])

            assert val2 == val1[:len(val2)]

            # And that the added message is what we expect.
            assert 'Preferences.get' in val1[-1]
예제 #2
0
    def test_pref_help_added_to_bare_strings(self):
        """Test that a help messages about passing literals directly to
        APIs is added only to bare strings."""

        self.run_script("""
            'browser.startup.homepage';
            Preferences.set('browser.startup.homepage');
        """)

        warnings = self.err.warnings
        self.assert_warnings({'id': PREFERENCE_ERROR_ID}, {
            'id': ('testcases_javascript_actions', '_call_expression',
                   'called_set_preference')
        },
                             exhaustive=True)

        # Check that descriptions and help are the same, except for
        # an added message in the bare string.
        for key in 'description', 'signing_help':
            val1 = maybe_tuple(warnings[0][key])
            val2 = maybe_tuple(warnings[1][key])

            assert val2 == val1[:len(val2)]

            # And that the added message is what we expect.
            assert 'Preferences.get' in val1[-1]
예제 #3
0
def add_pref_help(desc):
    """Add help text to an error description suggesting passing the preference
    directly to preference getter functions.

    This is used to add additional help text to warnings about bare preference
    string literals which would not apply if said literal is being passed
    directly to a known preference API method."""

    desc = desc.copy()
    for key in 'description', 'signing_help':
        if key in desc:
            desc[key] = maybe_tuple(desc[key]) + maybe_tuple(PREF_STRING_HELP)

    return desc