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..efe849e1abd775e6c66f7cf823064c6879cc4127 |
--- /dev/null |
+++ b/tools/telemetry/telemetry/page/actions/drag_unittest.py |
@@ -0,0 +1,49 @@ |
+# 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 os |
+ |
+from telemetry.page.actions import drag |
+from telemetry.unittest_util import tab_test_case |
+ |
Sami
2015/03/02 14:03:56
nit: two blank lines between top-level entries.
ssid
2015/03/02 20:09:41
Done.
|
+class DragActionTest(tab_test_case.TabTestCase): |
+ def testDragAction(self): |
Sami
2015/03/02 14:03:56
Does this test also work on Android with the mouse
ssid
2015/03/02 20:09:41
Added touch events to work on android.
|
+ 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.25, top_end_ratio=0.25) |
+ i.WillRunAction(self._tab) |
+ self._tab.ExecuteJavaScript(""" |
+ window.__dragAction.beginMeasuringHook = function() { |
picksi
2015/03/02 14:11:05
You use single quotes around embedded code in drag
ssid
2015/03/02 20:09:42
Is this your suggestion?
'window.__dragAc
picksi
2015/03/03 13:36:06
I'm suggesting you either stick with """ or ''', c
ssid
2015/03/03 14:50:08
Yes! now I I get it. Thanks.
|
+ 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. |
picksi
2015/03/02 14:11:05
nit: Change 0.25 in the comment to '4' or (probabl
ssid
2015/03/02 20:09:42
Changed.
|
+ self.assertTrue(div_position_x == div_width / 4, |
Sami
2015/03/02 14:03:56
This looks like it might fail if anything adds rou
ssid
2015/03/02 20:09:42
It converts the result to int because both the ope
|
+ msg="Moved element's left coordinate: %d, expected: %d" % |
+ (div_position_x, div_width / 4)) |
+ self.assertTrue(div_position_y == div_height / 4, |
+ msg="Moved element's top coordinate: %d, expected: %d" % |
+ (div_position_y, div_height / 4)) |