Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 import os | |
| 5 | |
| 6 from telemetry.page.actions import drag | |
| 7 from telemetry.unittest_util import tab_test_case | |
| 8 | |
|
Sami
2015/03/02 14:03:56
nit: two blank lines between top-level entries.
ssid
2015/03/02 20:09:41
Done.
| |
| 9 class DragActionTest(tab_test_case.TabTestCase): | |
| 10 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.
| |
| 11 self.Navigate('draggable.html') | |
| 12 | |
| 13 with open(os.path.join(os.path.dirname(__file__), | |
| 14 'gesture_common.js')) as f: | |
| 15 js = f.read() | |
| 16 self._tab.ExecuteJavaScript(js) | |
| 17 | |
| 18 div_width = self._tab.EvaluateJavaScript( | |
| 19 '__GestureCommon_GetBoundingVisibleRect(document.body).width') | |
| 20 div_height = self._tab.EvaluateJavaScript( | |
| 21 '__GestureCommon_GetBoundingVisibleRect(document.body).height') | |
| 22 | |
| 23 i = drag.DragAction(left_start_ratio=0.5, top_start_ratio=0.5, | |
| 24 left_end_ratio=0.25, top_end_ratio=0.25) | |
| 25 i.WillRunAction(self._tab) | |
| 26 self._tab.ExecuteJavaScript(""" | |
| 27 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.
| |
| 28 window.__didBeginMeasuring = true; | |
| 29 }; | |
| 30 window.__dragAction.endMeasuringHook = function() { | |
| 31 window.__didEndMeasuring = true; | |
| 32 };""") | |
| 33 i.RunAction(self._tab) | |
| 34 | |
| 35 self.assertTrue(self._tab.EvaluateJavaScript('window.__didBeginMeasuring')) | |
| 36 self.assertTrue(self._tab.EvaluateJavaScript('window.__didEndMeasuring')) | |
| 37 | |
| 38 div_position_x = self._tab.EvaluateJavaScript( | |
| 39 'document.getElementById("drag_div").offsetLeft') | |
| 40 div_position_y = self._tab.EvaluateJavaScript( | |
| 41 'document.getElementById("drag_div").offsetTop') | |
| 42 | |
| 43 # 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.
| |
| 44 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
| |
| 45 msg="Moved element's left coordinate: %d, expected: %d" % | |
| 46 (div_position_x, div_width / 4)) | |
| 47 self.assertTrue(div_position_y == div_height / 4, | |
| 48 msg="Moved element's top coordinate: %d, expected: %d" % | |
| 49 (div_position_y, div_height / 4)) | |
| OLD | NEW |