<commit_before>from webapi_tests import MinimalTestCase

class TestProximity(MinimalTestCase):
    def tearDown(self):
        self.marionette.execute_script("""
        window.removeEventListener('devicelight', window.wrappedJSObject.prox_function);
        """)
        MinimalTestCase.tearDown(self)
    def test_proximity_change(self):
        self.instruct("Ensure the phone is unlocked and held in your hand, perpendicular to the floor")
        # set up listener to store changes in an object
        # NOTE: use wrappedJSObject to access non-standard properties of window
        script = """
        window.wrappedJSObject.proximityStates = [];
        window.wrappedJSObject.prox_function = function(event){
                                  console.log("proximity event" + event);
                                  window.wrappedJSObject.proximityStates.push(event.toString());
                                };
        window.addEventListener('devicelight', window.wrappedJSObject.prox_function);
        """
        self.marionette.execute_script(script)
        self.instruct("Move your hand in front of the phone and hit OK when the screen darkens")
        proximity_values = self.marionette.execute_script("return window.wrappedJSObject.proximityStates")
        self.assertNotEqual(0, len(proximity_values))
<commit_msg>add property check on proximity event<commit_after>from webapi_tests import MinimalTestCase

class TestProximity(MinimalTestCase):
    def tearDown(self):
        self.marionette.execute_script("""
        window.removeEventListener('devicelight', window.wrappedJSObject.prox_function);
        """)
        MinimalTestCase.tearDown(self)
    def test_proximity_change(self):
        self.instruct("Ensure the phone is unlocked and held in your hand, perpendicular to the floor")
        # set up listener to store changes in an object
        # NOTE: use wrappedJSObject to access non-standard properties of window
        script = """
        window.wrappedJSObject.proximityStates = [];
        window.wrappedJSObject.prox_function = function(event){
                                  window.wrappedJSObject.proximityStates.push((event.value != undefined));
                                };
        window.addEventListener('devicelight', window.wrappedJSObject.prox_function);
        """
        self.marionette.execute_script(script)
        self.instruct("Move your hand in front of the phone and press 'y' when the screen darkens")
        proximity_values = self.marionette.execute_script("return window.wrappedJSObject.proximityStates")
        self.assertNotEqual(0, len(proximity_values))
        self.assertTrue(proximity_values[0])

{'fraction_non_alphanumeric': 0.08562918838421445, 'fraction_numerical': 0.0011169024571854058, 'mean_word_length': 2.911208151382824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2391481', 'n_tokens_mistral': 715, 'n_tokens_neox': 707, 'n_words': 158}