diff --git a/test/test_js_instrument_non_existing_properties.py b/test/test_js_instrument_existing_window_property_with_partially_existing_attributes.py similarity index 86% rename from test/test_js_instrument_non_existing_properties.py rename to test/test_js_instrument_existing_window_property_with_partially_existing_attributes.py index 75128fe6..0bdf7e8b 100644 --- a/test/test_js_instrument_non_existing_properties.py +++ b/test/test_js_instrument_existing_window_property_with_partially_existing_attributes.py @@ -19,13 +19,14 @@ METHOD_CALLS = { ('nonExistingMethod1', 'call', '["hello","{\\\"world\\\":true}"]'), } +TEST_PAGE = ("instrument_existing_window_property_" + "with_partially_existing_attributes.html") TOP_URL = ( - u"%s/js_instrument/instrument_non_existing_properties.html" % ( - util.BASE_TEST_URL) + u"%s/js_instrument/%s" % (util.BASE_TEST_URL, TEST_PAGE) ) -class TestJSInstrumentNonExistingProperties(OpenWPMTest): +class TestJSInstrumentExistingWindowPropertyWithPartiallyExistingAttributes(OpenWPMTest): def get_config(self, data_dir=""): manager_params, browser_params = self.get_test_config(data_dir) @@ -56,8 +57,7 @@ class TestJSInstrumentNonExistingProperties(OpenWPMTest): def test_instrument_object(self): """ Ensure instrumentObject logs all property gets, sets, and calls """ - db = self.visit( - '/js_instrument/instrument_non_existing_properties.html') + db = self.visit('/js_instrument/%s' % TEST_PAGE) rows = db_utils.get_javascript_entries(db, all_columns=True) # Check calls of non-recursive instrumentation diff --git a/test/test_js_instrument_mock_window_property.py b/test/test_js_instrument_mock_window_property.py new file mode 100644 index 00000000..7f0bc247 --- /dev/null +++ b/test/test_js_instrument_mock_window_property.py @@ -0,0 +1,64 @@ +from __future__ import absolute_import + +import re + +from ..automation.utilities import db_utils +from . import utilities as util +from .openwpmtest import OpenWPMTest + +GETS_AND_SETS = { + ("existingProp", "get", "foo"), + ("existingProp", "set", "blah1"), + ("existingProp", "get", "blah1"), + ("nonExistingProp1", "get", "undefined"), + ("nonExistingProp1", "set", "blah2"), + ("nonExistingProp1", "get", "blah2"), +} + +METHOD_CALLS = { + ('nonExistingMethod1', 'call', '["hello","{\\\"world\\\":true}"]'), +} + +TEST_PAGE = "instrument_mock_window_property.html" +TOP_URL = ( + u"%s/js_instrument/%s" % (util.BASE_TEST_URL, TEST_PAGE) +) + + +class TestJSInstrumentMockWindowProperty(OpenWPMTest): + + def get_config(self, data_dir=""): + manager_params, browser_params = self.get_test_config(data_dir) + browser_params[0]['js_instrument'] = True + manager_params['testing'] = True + return manager_params, browser_params + + def _check_calls(self, rows, symbol_prefix, doc_url, top_url): + """Helper to check method calls and accesses in each frame""" + observed_gets_and_sets = set() + observed_calls = set() + for row in rows: + if not row['symbol'].startswith(symbol_prefix): + continue + symbol = re.sub(symbol_prefix, '', row['symbol']) + assert row['document_url'] == doc_url + assert row['top_level_url'] == top_url + if row['operation'] == 'get' or row['operation'] == 'set': + observed_gets_and_sets.add( + (symbol, row['operation'], row['value']) + ) + else: + observed_calls.add( + (symbol, row['operation'], row['arguments']) + ) + assert observed_calls == METHOD_CALLS + assert observed_gets_and_sets == GETS_AND_SETS + + def test_instrument_object(self): + """ Ensure instrumentObject logs all property gets, sets, and calls """ + db = self.visit('/js_instrument/%s' % TEST_PAGE) + rows = db_utils.get_javascript_entries(db, all_columns=True) + + # Check calls of non-recursive instrumentation + self._check_calls(rows, 'window.alreadyInstantiatedMockClassInstance', TOP_URL, TOP_URL) + self._check_calls(rows, 'window.newMockClassInstance', TOP_URL, TOP_URL) diff --git a/test/test_js_instrument_non_existing_window_property.py b/test/test_js_instrument_non_existing_window_property.py index fb72ecec..92132d72 100644 --- a/test/test_js_instrument_non_existing_window_property.py +++ b/test/test_js_instrument_non_existing_window_property.py @@ -19,13 +19,13 @@ METHOD_CALLS = { ('nonExistingMethod1', 'call', '["hello","{\\\"world\\\":true}"]'), } +TEST_PAGE = "instrument_non_existing_window_property.html" TOP_URL = ( - u"%s/js_instrument/instrument_non_existing_object.html" % ( - util.BASE_TEST_URL) + u"%s/js_instrument/%s" % (util.BASE_TEST_URL, TEST_PAGE) ) -class TestJSInstrumentNonExistingObject(OpenWPMTest): +class TestJSInstrumentNonExistingWindowProperty(OpenWPMTest): def get_config(self, data_dir=""): manager_params, browser_params = self.get_test_config(data_dir) @@ -56,8 +56,7 @@ class TestJSInstrumentNonExistingObject(OpenWPMTest): def test_instrument_object(self): """ Ensure instrumentObject logs all property gets, sets, and calls """ - db = self.visit( - '/js_instrument/instrument_non_existing_object.html') + db = self.visit('/js_instrument/%s' % TEST_PAGE) rows = db_utils.get_javascript_entries(db, all_columns=True) # Check calls of non-recursive instrumentation diff --git a/test/test_pages/js_instrument/instrument_non_existing_properties.html b/test/test_pages/js_instrument/instrument_existing_window_property_with_partially_existing_attributes.html similarity index 94% rename from test/test_pages/js_instrument/instrument_non_existing_properties.html rename to test/test_pages/js_instrument/instrument_existing_window_property_with_partially_existing_attributes.html index cfa10db9..ffcd6e61 100644 --- a/test/test_pages/js_instrument/instrument_non_existing_properties.html +++ b/test/test_pages/js_instrument/instrument_existing_window_property_with_partially_existing_attributes.html @@ -1,10 +1,10 @@
- This page defines several types of objects and tests the js
instrument's instrumentObject() method.
NOTE: The platform config option `manager_params['testing']` must be set
diff --git a/test/test_pages/js_instrument/instrument_mock_window_property.html b/test/test_pages/js_instrument/instrument_mock_window_property.html
new file mode 100644
index 00000000..e3702976
--- /dev/null
+++ b/test/test_pages/js_instrument/instrument_mock_window_property.html
@@ -0,0 +1,146 @@
+
+
+
This page defines several types of objects and tests the js
+ instrument's instrumentObject() method.
+ NOTE: The platform config option `manager_params['testing']` must be set
+ to True otherwise the instrumentObject method won't be exposed to this
+ test script.
+
This page defines several types of objects and tests the js
instrument's instrumentObject() method.
NOTE: The platform config option `manager_params['testing']` must be set