| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 import mock | 4 import mock |
| 5 import unittest | 5 import unittest |
| 6 | 6 |
| 7 from telemetry.core import exceptions | 7 from telemetry.core import exceptions |
| 8 from telemetry import decorators | 8 from telemetry import decorators |
| 9 from telemetry.internal.actions import action_runner as action_runner_module | 9 from telemetry.internal.actions import action_runner as action_runner_module |
| 10 from telemetry.internal.actions import page_action | 10 from telemetry.internal.actions import page_action |
| 11 from telemetry.testing import tab_test_case | 11 from telemetry.testing import tab_test_case |
| 12 from telemetry.timeline import chrome_trace_category_filter | 12 from telemetry.timeline import chrome_trace_category_filter |
| 13 from telemetry.timeline import model | 13 from telemetry.timeline import model |
| 14 from telemetry.timeline import tracing_config | 14 from telemetry.timeline import tracing_config |
| 15 from telemetry.web_perf import timeline_interaction_record as tir_module | 15 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 16 | 16 |
| 17 import py_utils |
| 18 |
| 17 | 19 |
| 18 class ActionRunnerInteractionTest(tab_test_case.TabTestCase): | 20 class ActionRunnerInteractionTest(tab_test_case.TabTestCase): |
| 19 | 21 |
| 20 def GetInteractionRecords(self, trace_data): | 22 def GetInteractionRecords(self, trace_data): |
| 21 timeline_model = model.TimelineModel(trace_data) | 23 timeline_model = model.TimelineModel(trace_data) |
| 22 renderer_thread = timeline_model.GetRendererThreadFromTabId(self._tab.id) | 24 renderer_thread = timeline_model.GetRendererThreadFromTabId(self._tab.id) |
| 23 return [ | 25 return [ |
| 24 tir_module.TimelineInteractionRecord.FromAsyncEvent(e) | 26 tir_module.TimelineInteractionRecord.FromAsyncEvent(e) |
| 25 for e in renderer_thread.async_slices | 27 for e in renderer_thread.async_slices |
| 26 if tir_module.IsTimelineInteractionRecord(e.name) | 28 if tir_module.IsTimelineInteractionRecord(e.name) |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 action_runner.ExecuteJavaScript( | 206 action_runner.ExecuteJavaScript( |
| 205 '(function() {' | 207 '(function() {' |
| 206 ' var el = document.createElement("div");' | 208 ' var el = document.createElement("div");' |
| 207 ' el.id = "test1";' | 209 ' el.id = "test1";' |
| 208 ' el.textContent = "foo";' | 210 ' el.textContent = "foo";' |
| 209 ' document.body.appendChild(el);' | 211 ' document.body.appendChild(el);' |
| 210 '})()') | 212 '})()') |
| 211 action_runner.WaitForElement('#test1', timeout_in_seconds=0.2) | 213 action_runner.WaitForElement('#test1', timeout_in_seconds=0.2) |
| 212 def WaitForElement(): | 214 def WaitForElement(): |
| 213 action_runner.WaitForElement(text='oo', timeout_in_seconds=0.2) | 215 action_runner.WaitForElement(text='oo', timeout_in_seconds=0.2) |
| 214 self.assertRaises(exceptions.TimeoutException, WaitForElement) | 216 self.assertRaises(py_utils.TimeoutException, WaitForElement) |
| 215 | 217 |
| 216 def testClickElement(self): | 218 def testClickElement(self): |
| 217 self.Navigate('page_with_clickables.html') | 219 self.Navigate('page_with_clickables.html') |
| 218 action_runner = action_runner_module.ActionRunner(self._tab, | 220 action_runner = action_runner_module.ActionRunner(self._tab, |
| 219 skip_waits=True) | 221 skip_waits=True) |
| 220 | 222 |
| 221 action_runner.ExecuteJavaScript('valueSettableByTest = 1;') | 223 action_runner.ExecuteJavaScript('valueSettableByTest = 1;') |
| 222 action_runner.ClickElement('#test') | 224 action_runner.ClickElement('#test') |
| 223 self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest')) | 225 self.assertEqual(1, action_runner.EvaluateJavaScript('valueToTest')) |
| 224 | 226 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 with self.assertRaises(FooException): | 406 with self.assertRaises(FooException): |
| 405 with action_runner_module.Interaction( | 407 with action_runner_module.Interaction( |
| 406 self.mock_action_runner, label='ABC', flags=[]): | 408 self.mock_action_runner, label='ABC', flags=[]): |
| 407 raise FooException() | 409 raise FooException() |
| 408 | 410 |
| 409 # Test that the end console.timeEnd(...) isn't called because exception was | 411 # Test that the end console.timeEnd(...) isn't called because exception was |
| 410 # raised. | 412 # raised. |
| 411 expected_calls = [ | 413 expected_calls = [ |
| 412 mock.call.ExecuteJavaScript('console.time("Interaction.ABC");')] | 414 mock.call.ExecuteJavaScript('console.time("Interaction.ABC");')] |
| 413 self.assertEqual(expected_calls, self.mock_action_runner.mock_calls) | 415 self.assertEqual(expected_calls, self.mock_action_runner.mock_calls) |
| OLD | NEW |