Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: telemetry/telemetry/internal/actions/action_runner_unittest.py

Issue 2421433003: Add ScrollPageToElement to action_runner. (Closed)
Patch Set: Add ScrollPageToElement to action_runner. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 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 import mock 4 import mock
5 import unittest 5 import unittest
6 6
7 from telemetry.core import exceptions 7 from telemetry.core import exceptions
8 from telemetry import decorators 8 from telemetry import decorators
9 from telemetry.internal.actions import action_runner as action_runner_module 9 from telemetry.internal.actions import action_runner as action_runner_module
10 from telemetry.internal.actions import page_action 10 from telemetry.internal.actions import page_action
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 253
254 action_runner.ExecuteJavaScript('valueSettableByTest = 3;') 254 action_runner.ExecuteJavaScript('valueSettableByTest = 3;')
255 action_runner.TapElement( 255 action_runner.TapElement(
256 element_function='document.body.firstElementChild') 256 element_function='document.body.firstElementChild')
257 self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest')) 257 self.assertEqual(3, action_runner.EvaluateJavaScript('valueToTest'))
258 258
259 def WillFail(): 259 def WillFail():
260 action_runner.TapElement('#notfound') 260 action_runner.TapElement('#notfound')
261 self.assertRaises(exceptions.EvaluateException, WillFail) 261 self.assertRaises(exceptions.EvaluateException, WillFail)
262 262
263
264 def testScrollToElement(self):
265 if not page_action.IsGestureSourceTypeSupported(
nednguyen 2016/10/14 18:05:59 I think we don't need this. When I patch your CL &
rnephew (Reviews Here) 2016/10/14 18:08:56 Done.
266 self._tab, 'touch'):
267 return
268
269 self.Navigate('page_with_swipeables.html')
270 action_runner = action_runner_module.ActionRunner(self._tab,
271 skip_waits=True)
272
273 off_screen_element = 'document.querySelectorAll("#off-screen")[0]'
274 top_bottom_element = 'document.querySelector("#top-bottom")'
275 viewport_comparator_js_template = '''
276 (function(elem) {
277 var rect = elem.getBoundingClientRect();
278
279 if (rect.bottom < 0) {
280 // The bottom of the element is above the viewport.
281 return -1;
282 }
283 if (rect.top - window.innerHeight > 0) {
284 // rect.top provides the pixel offset of the element from the
285 // top of the page. Because that exceeds the viewport's height,
286 // we know that the element is below the viewport.
287 return 1;
288 }
289 return 0;
290 })(
291 '''
292 viewport_comparator_off_screen_js = (
293 viewport_comparator_js_template + '%s);' % off_screen_element)
294 viewport_comparator_top_bottom_js = (
295 viewport_comparator_js_template + '%s);' % top_bottom_element)
296
297 self.assertEqual(
298 action_runner.EvaluateJavaScript(viewport_comparator_off_screen_js), 1)
299 action_runner.ScrollPageToElement(selector='#off-screen',
300 speed_in_pixels_per_second=5000)
301 self.assertEqual(
302 action_runner.EvaluateJavaScript(viewport_comparator_off_screen_js), 0)
303
304 self.assertEqual(
305 action_runner.EvaluateJavaScript(viewport_comparator_top_bottom_js), -1)
306 action_runner.ScrollPageToElement(selector='#top-bottom',
307 speed_in_pixels_per_second=5000)
308 self.assertEqual(
309 action_runner.EvaluateJavaScript(viewport_comparator_top_bottom_js), 0)
310
311
263 @decorators.Disabled('android', # crbug.com/437065. 312 @decorators.Disabled('android', # crbug.com/437065.
264 'chromeos') # crbug.com/483212. 313 'chromeos') # crbug.com/483212.
265 def testScroll(self): 314 def testScroll(self):
266 if not page_action.IsGestureSourceTypeSupported( 315 if not page_action.IsGestureSourceTypeSupported(
267 self._tab, 'touch'): 316 self._tab, 'touch'):
268 return 317 return
269 318
270 self.Navigate('page_with_swipeables.html') 319 self.Navigate('page_with_swipeables.html')
271 action_runner = action_runner_module.ActionRunner(self._tab, 320 action_runner = action_runner_module.ActionRunner(self._tab,
272 skip_waits=True) 321 skip_waits=True)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 with self.assertRaises(FooException): 408 with self.assertRaises(FooException):
360 with action_runner_module.Interaction( 409 with action_runner_module.Interaction(
361 self.mock_action_runner, label='ABC', flags=[]): 410 self.mock_action_runner, label='ABC', flags=[]):
362 raise FooException() 411 raise FooException()
363 412
364 # Test that the end console.timeEnd(...) isn't called because exception was 413 # Test that the end console.timeEnd(...) isn't called because exception was
365 # raised. 414 # raised.
366 expected_calls = [ 415 expected_calls = [
367 mock.call.ExecuteJavaScript('console.time("Interaction.ABC");')] 416 mock.call.ExecuteJavaScript('console.time("Interaction.ABC");')]
368 self.assertEqual(expected_calls, self.mock_action_runner.mock_calls) 417 self.assertEqual(expected_calls, self.mock_action_runner.mock_calls)
OLDNEW
« no previous file with comments | « telemetry/telemetry/internal/actions/action_runner.py ('k') | telemetry/telemetry/internal/actions/scroll_to_element.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698