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 3# found in the LICENSE file. 4 5from telemetry.internal.actions import page_action 6from telemetry.page import action_runner as action_runner_module 7from telemetry.testing import tab_test_case 8 9 10class PinchActionTest(tab_test_case.TabTestCase): 11 def setUp(self): 12 super(PinchActionTest, self).setUp() 13 14 def testPinchByApiCalledWithCorrectArguments(self): 15 self.Navigate('blank.html') 16 if not page_action.IsGestureSourceTypeSupported(self._tab, 'touch'): 17 return 18 19 action_runner = action_runner_module.ActionRunner(self._tab) 20 action_runner.ExecuteJavaScript(''' 21 chrome.gpuBenchmarking.pinchBy = function( 22 scaleFactor, anchorLeft, anchorTop, callback, speed) { 23 window.__test_scaleFactor = scaleFactor; 24 window.__test_anchorLeft = anchorLeft; 25 window.__test_anchorTop = anchorTop; 26 window.__test_callback = callback; 27 window.__test_speed = speed; 28 window.__pinchActionDone = true; 29 };''') 30 action_runner.PinchPage(scale_factor=2) 31 self.assertEqual( 32 2, action_runner.EvaluateJavaScript('window.__test_scaleFactor')) 33 self.assertTrue( 34 action_runner.EvaluateJavaScript('!isNaN(window.__test_anchorLeft)')) 35 self.assertTrue( 36 action_runner.EvaluateJavaScript('!isNaN(window.__test_anchorTop)')) 37 self.assertTrue( 38 action_runner.EvaluateJavaScript('!!window.__test_callback')) 39 self.assertEqual( 40 800, action_runner.EvaluateJavaScript('window.__test_speed')) 41