Chromium Code Reviews| Index: tools/telemetry/telemetry/page/actions/action_runner_unittest.py |
| diff --git a/tools/telemetry/telemetry/page/actions/action_runner_unittest.py b/tools/telemetry/telemetry/page/actions/action_runner_unittest.py |
| index 4bcbb198b79a596d10fc5cf443ca939108766f98..b696964bd855566de7302e0dee6e5c81c4e684b0 100644 |
| --- a/tools/telemetry/telemetry/page/actions/action_runner_unittest.py |
| +++ b/tools/telemetry/telemetry/page/actions/action_runner_unittest.py |
| @@ -2,6 +2,8 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import cStringIO |
| + |
| from telemetry import benchmark |
| from telemetry.core import exceptions |
| from telemetry.core import util |
| @@ -14,222 +16,228 @@ from telemetry.web_perf import timeline_interaction_record as tir_module |
| class ActionRunnerInteractionTest(tab_test_case.TabTestCase): |
| - def GetInteractionRecords(self, trace_data): |
| - timeline_model = model.TimelineModel(trace_data) |
| - renderer_thread = timeline_model.GetRendererThreadFromTabId(self._tab.id) |
| - return [ |
| - tir_module.TimelineInteractionRecord.FromAsyncEvent(e) |
| - for e in renderer_thread.async_slices |
| - if tir_module.IsTimelineInteractionRecord(e.name) |
| - ] |
| - |
| - def VerifyIssuingInteractionRecords(self, **interaction_kwargs): |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - self.Navigate('interaction_enabled_page.html') |
| - action_runner.Wait(1) |
| - self._browser.StartTracing() |
| - interaction = action_runner.BeginInteraction('InteractionName', |
| - **interaction_kwargs) |
| - interaction.End() |
| - trace_data = self._browser.StopTracing() |
| - |
| - records = self.GetInteractionRecords(trace_data) |
| - self.assertEqual( |
| - 1, len(records), |
| - 'Failed to issue the interaction record on the tracing timeline.' |
| - ' Trace data:\n%s' % repr(trace_data.EventData())) |
| - self.assertEqual('InteractionName', records[0].label) |
| - for attribute_name in interaction_kwargs: |
| - self.assertTrue(getattr(records[0], attribute_name)) |
| - |
| - def testIssuingMultipleMeasurementInteractionRecords(self): |
| - self.VerifyIssuingInteractionRecords(is_fast=True) |
| - self.VerifyIssuingInteractionRecords(is_responsive=True) |
| - self.VerifyIssuingInteractionRecords(is_smooth=True) |
| - self.VerifyIssuingInteractionRecords(is_fast=True, is_smooth=True) |
| + def GetInteractionRecords(self, trace_value): |
|
nednguyen
2014/08/05 14:34:34
Something seems wrong with the indentation.
|
| + timeline_model = model.TimelineModel(trace_value) |
| + renderer_thread = timeline_model.GetRendererThreadFromTabId(self._tab.id) |
| + return [ |
| + tir_module.TimelineInteractionRecord.FromAsyncEvent(e) |
| + for e in renderer_thread.async_slices |
| + if tir_module.IsTimelineInteractionRecord(e.name) |
| + ] |
| + |
| + def VerifyIssuingInteractionRecords(self, **interaction_kwargs): |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + self.Navigate('interaction_enabled_page.html') |
| + action_runner.Wait(1) |
| + self._browser.StartTracing() |
| + interaction = action_runner.BeginInteraction('InteractionName', |
| + **interaction_kwargs) |
| + interaction.End() |
| + trace_value = self._browser.StopTracing() |
| + |
| + records = self.GetInteractionRecords(trace_value) |
| + |
| + if len(records) != 1: |
| + f = cStringIO.StringIO() |
| + trace_value.Serialize(f) |
| + trace_value_json = f.getvalue() |
| + |
| + raise Exception( |
| + 'Failed to issue the interaction record on the tracing timeline.' |
| + ' Trace data:\n%s' % trace_value_json) |
| + |
| + self.assertEqual('InteractionName', records[0].label) |
| + for attribute_name in interaction_kwargs: |
| + self.assertTrue(getattr(records[0], attribute_name)) |
| + |
| + def testIssuingMultipleMeasurementInteractionRecords(self): |
| + self.VerifyIssuingInteractionRecords(is_fast=True) |
| + self.VerifyIssuingInteractionRecords(is_responsive=True) |
| + self.VerifyIssuingInteractionRecords(is_smooth=True) |
| + self.VerifyIssuingInteractionRecords(is_fast=True, is_smooth=True) |
| class ActionRunnerTest(tab_test_case.TabTestCase): |
| - def testExecuteJavaScript(self): |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - self.Navigate('blank.html') |
| - action_runner.ExecuteJavaScript('var testing = 42;') |
| - self.assertEqual(42, self._tab.EvaluateJavaScript('testing')) |
| - |
| - def testWaitForNavigate(self): |
| - self.Navigate('page_with_link.html') |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - action_runner.ClickElement('#clickme') |
| - action_runner.WaitForNavigate() |
| - |
| - self.assertTrue(self._tab.EvaluateJavaScript( |
| - 'document.readyState == "interactive" || ' |
| - 'document.readyState == "complete"')) |
| - self.assertEqual( |
| - self._tab.EvaluateJavaScript('document.location.pathname;'), |
| - '/blank.html') |
| - |
| - def testWait(self): |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - self.Navigate('blank.html') |
| - |
| - action_runner.ExecuteJavaScript( |
| - 'window.setTimeout(function() { window.testing = 101; }, 1000);') |
| - action_runner.Wait(2) |
| - self.assertEqual(101, self._tab.EvaluateJavaScript('window.testing')) |
| - |
| - action_runner.ExecuteJavaScript( |
| - 'window.setTimeout(function() { window.testing = 102; }, 2000);') |
| - action_runner.Wait(3) |
| - self.assertEqual(102, self._tab.EvaluateJavaScript('window.testing')) |
| - |
| - def testWaitForJavaScriptCondition(self): |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - self.Navigate('blank.html') |
| - |
| - action_runner.ExecuteJavaScript('window.testing = 219;') |
| - action_runner.WaitForJavaScriptCondition( |
| - 'window.testing == 219', timeout_in_seconds=1) |
| - action_runner.ExecuteJavaScript( |
| - 'window.setTimeout(function() { window.testing = 220; }, 1000);') |
| - action_runner.WaitForJavaScriptCondition( |
| - 'window.testing == 220', timeout_in_seconds=2) |
| - self.assertEqual(220, self._tab.EvaluateJavaScript('window.testing')) |
| - |
| - def testWaitForElement(self): |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - self.Navigate('blank.html') |
| - |
| - action_runner.ExecuteJavaScript( |
| - '(function() {' |
| - ' var el = document.createElement("div");' |
| - ' el.id = "test1";' |
| - ' el.textContent = "foo";' |
| - ' document.body.appendChild(el);' |
| - '})()') |
| - action_runner.WaitForElement('#test1', timeout_in_seconds=1) |
| - action_runner.WaitForElement(text='foo', timeout_in_seconds=1) |
| - action_runner.WaitForElement( |
| - element_function='document.getElementById("test1")') |
| - action_runner.ExecuteJavaScript( |
| - 'window.setTimeout(function() {' |
| - ' var el = document.createElement("div");' |
| - ' el.id = "test2";' |
| - ' document.body.appendChild(el);' |
| - '}, 500)') |
| - action_runner.WaitForElement('#test2', timeout_in_seconds=2) |
| - action_runner.ExecuteJavaScript( |
| - 'window.setTimeout(function() {' |
| - ' document.getElementById("test2").textContent = "bar";' |
| - '}, 500)') |
| - action_runner.WaitForElement(text='bar', timeout_in_seconds=2) |
| - action_runner.ExecuteJavaScript( |
| - 'window.setTimeout(function() {' |
| - ' var el = document.createElement("div");' |
| - ' el.id = "test3";' |
| - ' document.body.appendChild(el);' |
| - '}, 500)') |
| - action_runner.WaitForElement( |
| - element_function='document.getElementById("test3")') |
| - |
| - def testWaitForElementWithWrongText(self): |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - self.Navigate('blank.html') |
| - |
| - action_runner.ExecuteJavaScript( |
| - '(function() {' |
| - ' var el = document.createElement("div");' |
| - ' el.id = "test1";' |
| - ' el.textContent = "foo";' |
| - ' document.body.appendChild(el);' |
| - '})()') |
| - action_runner.WaitForElement('#test1', timeout_in_seconds=1) |
| - def WaitForElement(): |
| - action_runner.WaitForElement(text='oo', timeout_in_seconds=1) |
| - self.assertRaises(util.TimeoutException, WaitForElement) |
| - |
| - def testClickElement(self): |
| - self.Navigate('page_with_clickables.html') |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - |
| - action_runner.ExecuteJavaScript('valueSettableByTest = 1;') |
| - action_runner.ClickElement('#test') |
| - self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest')) |
| - |
| - action_runner.ExecuteJavaScript('valueSettableByTest = 2;') |
| - action_runner.ClickElement(text='Click/tap me') |
| - self.assertEqual(2, action_runner.EvaluateJavaScript('valueToTest')) |
| - |
| - action_runner.ExecuteJavaScript('valueSettableByTest = 3;') |
| - action_runner.ClickElement( |
| - element_function='document.body.firstElementChild;') |
| - self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest')) |
| - |
| - def WillFail(): |
| - action_runner.ClickElement('#notfound') |
| - self.assertRaises(exceptions.EvaluateException, WillFail) |
| - |
| - @benchmark.Disabled('debug') |
| - def testTapElement(self): |
| - self.Navigate('page_with_clickables.html') |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - |
| - action_runner.ExecuteJavaScript('valueSettableByTest = 1;') |
| - action_runner.TapElement('#test') |
| - self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest')) |
| - |
| - action_runner.ExecuteJavaScript('valueSettableByTest = 2;') |
| - action_runner.TapElement(text='Click/tap me') |
| - self.assertEqual(2, action_runner.EvaluateJavaScript('valueToTest')) |
| - |
| - action_runner.ExecuteJavaScript('valueSettableByTest = 3;') |
| - action_runner.TapElement( |
| - element_function='document.body.firstElementChild') |
| - self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest')) |
| - |
| - def WillFail(): |
| - action_runner.TapElement('#notfound') |
| - self.assertRaises(exceptions.EvaluateException, WillFail) |
| - |
| - def testScroll(self): |
| - if not page_action.IsGestureSourceTypeSupported( |
| - self._tab, 'touch'): |
| - return |
| - |
| - self.Navigate('page_with_swipeables.html') |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - |
| - action_runner.ScrollElement( |
| - selector='#left-right', direction='right', left_start_ratio=0.9) |
| - self.assertTrue(action_runner.EvaluateJavaScript( |
| - 'document.querySelector("#left-right").scrollLeft') > 75) |
| - action_runner.ScrollElement( |
| - selector='#top-bottom', direction='down', top_start_ratio=0.9) |
| - self.assertTrue(action_runner.EvaluateJavaScript( |
| - 'document.querySelector("#top-bottom").scrollTop') > 75) |
| - |
| - action_runner.ScrollPage(direction='right', left_start_ratio=0.9, |
| - distance=100) |
| - self.assertTrue(action_runner.EvaluateJavaScript( |
| - 'document.body.scrollLeft') > 75) |
| - |
| - def testSwipe(self): |
| - if not page_action.IsGestureSourceTypeSupported( |
| - self._tab, 'touch'): |
| - return |
| - |
| - self.Navigate('page_with_swipeables.html') |
| - action_runner = action_runner_module.ActionRunner(self._tab) |
| - |
| - action_runner.SwipeElement( |
| - selector='#left-right', direction='left', left_start_ratio=0.9) |
| - self.assertTrue(action_runner.EvaluateJavaScript( |
| - 'document.querySelector("#left-right").scrollLeft') > 75) |
| - action_runner.SwipeElement( |
| - selector='#top-bottom', direction='up', top_start_ratio=0.9) |
| - self.assertTrue(action_runner.EvaluateJavaScript( |
| - 'document.querySelector("#top-bottom").scrollTop') > 75) |
| - |
| - action_runner.SwipePage(direction='left', left_start_ratio=0.9) |
| - self.assertTrue(action_runner.EvaluateJavaScript( |
| - 'document.body.scrollLeft') > 75) |
| + def testExecuteJavaScript(self): |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + self.Navigate('blank.html') |
| + action_runner.ExecuteJavaScript('var testing = 42;') |
| + self.assertEqual(42, self._tab.EvaluateJavaScript('testing')) |
| + |
| + def testWaitForNavigate(self): |
| + self.Navigate('page_with_link.html') |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + action_runner.ClickElement('#clickme') |
| + action_runner.WaitForNavigate() |
| + |
| + self.assertTrue(self._tab.EvaluateJavaScript( |
| + 'document.readyState == "interactive" || ' |
| + 'document.readyState == "complete"')) |
| + self.assertEqual( |
| + self._tab.EvaluateJavaScript('document.location.pathname;'), |
| + '/blank.html') |
| + |
| + def testWait(self): |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + self.Navigate('blank.html') |
| + |
| + action_runner.ExecuteJavaScript( |
| + 'window.setTimeout(function() { window.testing = 101; }, 1000);') |
| + action_runner.Wait(2) |
| + self.assertEqual(101, self._tab.EvaluateJavaScript('window.testing')) |
| + |
| + action_runner.ExecuteJavaScript( |
| + 'window.setTimeout(function() { window.testing = 102; }, 2000);') |
| + action_runner.Wait(3) |
| + self.assertEqual(102, self._tab.EvaluateJavaScript('window.testing')) |
| + |
| + def testWaitForJavaScriptCondition(self): |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + self.Navigate('blank.html') |
| + |
| + action_runner.ExecuteJavaScript('window.testing = 219;') |
| + action_runner.WaitForJavaScriptCondition( |
| + 'window.testing == 219', timeout_in_seconds=1) |
| + action_runner.ExecuteJavaScript( |
| + 'window.setTimeout(function() { window.testing = 220; }, 1000);') |
| + action_runner.WaitForJavaScriptCondition( |
| + 'window.testing == 220', timeout_in_seconds=2) |
| + self.assertEqual(220, self._tab.EvaluateJavaScript('window.testing')) |
| + |
| + def testWaitForElement(self): |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + self.Navigate('blank.html') |
| + |
| + action_runner.ExecuteJavaScript( |
| + '(function() {' |
| + ' var el = document.createElement("div");' |
| + ' el.id = "test1";' |
| + ' el.textContent = "foo";' |
| + ' document.body.appendChild(el);' |
| + '})()') |
| + action_runner.WaitForElement('#test1', timeout_in_seconds=1) |
| + action_runner.WaitForElement(text='foo', timeout_in_seconds=1) |
| + action_runner.WaitForElement( |
| + element_function='document.getElementById("test1")') |
| + action_runner.ExecuteJavaScript( |
| + 'window.setTimeout(function() {' |
| + ' var el = document.createElement("div");' |
| + ' el.id = "test2";' |
| + ' document.body.appendChild(el);' |
| + '}, 500)') |
| + action_runner.WaitForElement('#test2', timeout_in_seconds=2) |
| + action_runner.ExecuteJavaScript( |
| + 'window.setTimeout(function() {' |
| + ' document.getElementById("test2").textContent = "bar";' |
| + '}, 500)') |
| + action_runner.WaitForElement(text='bar', timeout_in_seconds=2) |
| + action_runner.ExecuteJavaScript( |
| + 'window.setTimeout(function() {' |
| + ' var el = document.createElement("div");' |
| + ' el.id = "test3";' |
| + ' document.body.appendChild(el);' |
| + '}, 500)') |
| + action_runner.WaitForElement( |
| + element_function='document.getElementById("test3")') |
| + |
| + def testWaitForElementWithWrongText(self): |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + self.Navigate('blank.html') |
| + |
| + action_runner.ExecuteJavaScript( |
| + '(function() {' |
| + ' var el = document.createElement("div");' |
| + ' el.id = "test1";' |
| + ' el.textContent = "foo";' |
| + ' document.body.appendChild(el);' |
| + '})()') |
| + action_runner.WaitForElement('#test1', timeout_in_seconds=1) |
| + def WaitForElement(): |
| + action_runner.WaitForElement(text='oo', timeout_in_seconds=1) |
| + self.assertRaises(util.TimeoutException, WaitForElement) |
| + |
| + def testClickElement(self): |
| + self.Navigate('page_with_clickables.html') |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + |
| + action_runner.ExecuteJavaScript('valueSettableByTest = 1;') |
| + action_runner.ClickElement('#test') |
| + self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest')) |
| + |
| + action_runner.ExecuteJavaScript('valueSettableByTest = 2;') |
| + action_runner.ClickElement(text='Click/tap me') |
| + self.assertEqual(2, action_runner.EvaluateJavaScript('valueToTest')) |
| + |
| + action_runner.ExecuteJavaScript('valueSettableByTest = 3;') |
| + action_runner.ClickElement( |
| + element_function='document.body.firstElementChild;') |
| + self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest')) |
| + |
| + def WillFail(): |
| + action_runner.ClickElement('#notfound') |
| + self.assertRaises(exceptions.EvaluateException, WillFail) |
| + |
| + @benchmark.Disabled('debug') |
| + def testTapElement(self): |
| + self.Navigate('page_with_clickables.html') |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + |
| + action_runner.ExecuteJavaScript('valueSettableByTest = 1;') |
| + action_runner.TapElement('#test') |
| + self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest')) |
| + |
| + action_runner.ExecuteJavaScript('valueSettableByTest = 2;') |
| + action_runner.TapElement(text='Click/tap me') |
| + self.assertEqual(2, action_runner.EvaluateJavaScript('valueToTest')) |
| + |
| + action_runner.ExecuteJavaScript('valueSettableByTest = 3;') |
| + action_runner.TapElement( |
| + element_function='document.body.firstElementChild') |
| + self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest')) |
| + |
| + def WillFail(): |
| + action_runner.TapElement('#notfound') |
| + self.assertRaises(exceptions.EvaluateException, WillFail) |
| + |
| + def testScroll(self): |
| + if not page_action.IsGestureSourceTypeSupported( |
| + self._tab, 'touch'): |
| + return |
| + |
| + self.Navigate('page_with_swipeables.html') |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + |
| + action_runner.ScrollElement( |
| + selector='#left-right', direction='right', left_start_ratio=0.9) |
| + self.assertTrue(action_runner.EvaluateJavaScript( |
| + 'document.querySelector("#left-right").scrollLeft') > 75) |
| + action_runner.ScrollElement( |
| + selector='#top-bottom', direction='down', top_start_ratio=0.9) |
| + self.assertTrue(action_runner.EvaluateJavaScript( |
| + 'document.querySelector("#top-bottom").scrollTop') > 75) |
| + |
| + action_runner.ScrollPage(direction='right', left_start_ratio=0.9, |
| + distance=100) |
| + self.assertTrue(action_runner.EvaluateJavaScript( |
| + 'document.body.scrollLeft') > 75) |
| + |
| + def testSwipe(self): |
| + if not page_action.IsGestureSourceTypeSupported( |
| + self._tab, 'touch'): |
| + return |
| + |
| + self.Navigate('page_with_swipeables.html') |
| + action_runner = action_runner_module.ActionRunner(self._tab) |
| + |
| + action_runner.SwipeElement( |
| + selector='#left-right', direction='left', left_start_ratio=0.9) |
| + self.assertTrue(action_runner.EvaluateJavaScript( |
| + 'document.querySelector("#left-right").scrollLeft') > 75) |
| + action_runner.SwipeElement( |
| + selector='#top-bottom', direction='up', top_start_ratio=0.9) |
| + self.assertTrue(action_runner.EvaluateJavaScript( |
| + 'document.querySelector("#top-bottom").scrollTop') > 75) |
| + |
| + action_runner.SwipePage(direction='left', left_start_ratio=0.9) |
| + self.assertTrue(action_runner.EvaluateJavaScript( |
| + 'document.body.scrollLeft') > 75) |