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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: telemetry/telemetry/internal/actions/action_runner_unittest.py
diff --git a/telemetry/telemetry/internal/actions/action_runner_unittest.py b/telemetry/telemetry/internal/actions/action_runner_unittest.py
index 8e89bce7663a0cd33bf1edd15d7470368460e49b..bc7ac7e5cc4c3adddfe6c55c0af5bc44d1fb6a2f 100644
--- a/telemetry/telemetry/internal/actions/action_runner_unittest.py
+++ b/telemetry/telemetry/internal/actions/action_runner_unittest.py
@@ -260,6 +260,55 @@ class ActionRunnerTest(tab_test_case.TabTestCase):
action_runner.TapElement('#notfound')
self.assertRaises(exceptions.EvaluateException, WillFail)
+
+ def testScrollToElement(self):
+ 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.
+ self._tab, 'touch'):
+ return
+
+ self.Navigate('page_with_swipeables.html')
+ action_runner = action_runner_module.ActionRunner(self._tab,
+ skip_waits=True)
+
+ off_screen_element = 'document.querySelectorAll("#off-screen")[0]'
+ top_bottom_element = 'document.querySelector("#top-bottom")'
+ viewport_comparator_js_template = '''
+ (function(elem) {
+ var rect = elem.getBoundingClientRect();
+
+ if (rect.bottom < 0) {
+ // The bottom of the element is above the viewport.
+ return -1;
+ }
+ if (rect.top - window.innerHeight > 0) {
+ // rect.top provides the pixel offset of the element from the
+ // top of the page. Because that exceeds the viewport's height,
+ // we know that the element is below the viewport.
+ return 1;
+ }
+ return 0;
+ })(
+ '''
+ viewport_comparator_off_screen_js = (
+ viewport_comparator_js_template + '%s);' % off_screen_element)
+ viewport_comparator_top_bottom_js = (
+ viewport_comparator_js_template + '%s);' % top_bottom_element)
+
+ self.assertEqual(
+ action_runner.EvaluateJavaScript(viewport_comparator_off_screen_js), 1)
+ action_runner.ScrollPageToElement(selector='#off-screen',
+ speed_in_pixels_per_second=5000)
+ self.assertEqual(
+ action_runner.EvaluateJavaScript(viewport_comparator_off_screen_js), 0)
+
+ self.assertEqual(
+ action_runner.EvaluateJavaScript(viewport_comparator_top_bottom_js), -1)
+ action_runner.ScrollPageToElement(selector='#top-bottom',
+ speed_in_pixels_per_second=5000)
+ self.assertEqual(
+ action_runner.EvaluateJavaScript(viewport_comparator_top_bottom_js), 0)
+
+
@decorators.Disabled('android', # crbug.com/437065.
'chromeos') # crbug.com/483212.
def testScroll(self):
« 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