Index: tools/telemetry/telemetry/page/actions/drag_unittest.py |
diff --git a/tools/telemetry/telemetry/page/actions/drag_unittest.py b/tools/telemetry/telemetry/page/actions/drag_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d516719f5aa4bec494b1e00a67b76f896cbc2c37 |
--- /dev/null |
+++ b/tools/telemetry/telemetry/page/actions/drag_unittest.py |
@@ -0,0 +1,54 @@ |
+# Copyright 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+import math |
+import os |
+ |
+from telemetry.page.actions import drag |
+from telemetry.unittest_util import tab_test_case |
+ |
+ |
+class DragActionTest(tab_test_case.TabTestCase): |
+ def testDragAction(self): |
+ self.Navigate('draggable.html') |
+ |
+ with open(os.path.join(os.path.dirname(__file__), |
+ 'gesture_common.js')) as f: |
+ js = f.read() |
+ self._tab.ExecuteJavaScript(js) |
+ |
+ div_width = self._tab.EvaluateJavaScript( |
+ '__GestureCommon_GetBoundingVisibleRect(document.body).width') |
+ div_height = self._tab.EvaluateJavaScript( |
+ '__GestureCommon_GetBoundingVisibleRect(document.body).height') |
+ |
+ i = drag.DragAction(left_start_ratio=0.5, top_start_ratio=0.5, |
+ left_end_ratio=0.75, top_end_ratio=0.75) |
+ i.WillRunAction(self._tab) |
+ self._tab.ExecuteJavaScript(""" |
+ window.__dragAction.beginMeasuringHook = function() { |
+ window.__didBeginMeasuring = true; |
+ }; |
+ window.__dragAction.endMeasuringHook = function() { |
+ window.__didEndMeasuring = true; |
+ };""") |
+ i.RunAction(self._tab) |
+ |
+ self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) |
+ self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) |
+ |
+ div_position_x = self._tab.EvaluateJavaScript( |
+ 'document.getElementById("drag_div").offsetLeft') |
+ div_position_y = self._tab.EvaluateJavaScript( |
+ 'document.getElementById("drag_div").offsetTop') |
+ |
+ # 0.25 is the ratio of displacement to the initial size. |
+ expected_x = math.floor(div_width * -0.25) |
picksi
2015/03/03 13:36:06
Where has the minus signed come from? I'm confused
ssid
2015/03/03 14:50:08
I changed the ratio moved to drag up instead of do
|
+ expected_y = math.floor(div_height * -0.25) |
+ |
+ self.assertEquals(div_position_x, expected_x, |
+ msg="Moved element's left coordinate: %d, expected: %d" % |
+ (div_position_x, expected_x)) |
+ self.assertEquals(div_position_y, expected_y, |
+ msg="Moved element's top coordinate: %d, expected: %d" % |
+ (div_position_y, expected_y)) |