| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 |
| 4 import logging | 5 import logging |
| 5 import math | 6 import math |
| 6 import os | |
| 7 | 7 |
| 8 from telemetry import decorators | 8 from telemetry import decorators |
| 9 from telemetry.internal.actions import drag | 9 from telemetry.internal.actions import drag |
| 10 from telemetry.internal.actions import page_action | 10 from telemetry.internal.actions import page_action |
| 11 from telemetry.internal.actions import utils |
| 11 from telemetry.testing import tab_test_case | 12 from telemetry.testing import tab_test_case |
| 12 | 13 |
| 13 | 14 |
| 14 class DragActionTest(tab_test_case.TabTestCase): | 15 class DragActionTest(tab_test_case.TabTestCase): |
| 15 def CheckWithinRange(self, value, expected, error_ratio): | 16 def CheckWithinRange(self, value, expected, error_ratio): |
| 16 error_range = abs(expected * error_ratio) | 17 error_range = abs(expected * error_ratio) |
| 17 return abs(value - expected) <= error_range | 18 return abs(value - expected) <= error_range |
| 18 | 19 |
| 19 @decorators.Disabled('chromeos') # crbug.com/483212 | 20 @decorators.Disabled('chromeos') # crbug.com/483212 |
| 20 def testDragAction(self): | 21 def testDragAction(self): |
| 21 self.Navigate('draggable.html') | 22 self.Navigate('draggable.html') |
| 22 | 23 |
| 23 with open(os.path.join(os.path.dirname(__file__), | 24 utils.InjectJavaScript(self._tab, 'gesture_common.js') |
| 24 'gesture_common.js')) as f: | |
| 25 js = f.read() | |
| 26 self._tab.ExecuteJavaScript(js) | |
| 27 | 25 |
| 28 div_width = self._tab.EvaluateJavaScript( | 26 div_width = self._tab.EvaluateJavaScript( |
| 29 '__GestureCommon_GetBoundingVisibleRect(document.body).width') | 27 '__GestureCommon_GetBoundingVisibleRect(document.body).width') |
| 30 div_height = self._tab.EvaluateJavaScript( | 28 div_height = self._tab.EvaluateJavaScript( |
| 31 '__GestureCommon_GetBoundingVisibleRect(document.body).height') | 29 '__GestureCommon_GetBoundingVisibleRect(document.body).height') |
| 32 | 30 |
| 33 i = drag.DragAction(left_start_ratio=0.5, top_start_ratio=0.5, | 31 i = drag.DragAction(left_start_ratio=0.5, top_start_ratio=0.5, |
| 34 left_end_ratio=0.25, top_end_ratio=0.25) | 32 left_end_ratio=0.25, top_end_ratio=0.25) |
| 35 try: | 33 try: |
| 36 i.WillRunAction(self._tab) | 34 i.WillRunAction(self._tab) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 62 error_ratio = 0.1 | 60 error_ratio = 0.1 |
| 63 | 61 |
| 64 self.assertTrue( | 62 self.assertTrue( |
| 65 self.CheckWithinRange(div_position_x, expected_x, error_ratio), | 63 self.CheckWithinRange(div_position_x, expected_x, error_ratio), |
| 66 msg="Moved element's left coordinate: %d, expected: %d" % | 64 msg="Moved element's left coordinate: %d, expected: %d" % |
| 67 (div_position_x, expected_x)) | 65 (div_position_x, expected_x)) |
| 68 self.assertTrue( | 66 self.assertTrue( |
| 69 self.CheckWithinRange(div_position_y, expected_y, error_ratio), | 67 self.CheckWithinRange(div_position_y, expected_y, error_ratio), |
| 70 msg="Moved element's top coordinate: %d, expected: %d" % | 68 msg="Moved element's top coordinate: %d, expected: %d" % |
| 71 (div_position_y, expected_y)) | 69 (div_position_y, expected_y)) |
| OLD | NEW |