# Copyright 2014 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.

from telemetry.internal.actions import page_action


class ClickElementAction(page_action.ElementPageAction):

  def RunAction(self, tab):
    code = '''
        function(element, errorMsg) {
          if (!element) {
            throw Error('Cannot find element: ' + errorMsg);
          }
          element.click();
        }'''
    # Click handler that plays media or requests fullscreen may not take
    # effects without user_gesture set to True.
    self.EvaluateCallback(tab, code)

# Copyright 2014 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.

from telemetry.internal.actions import page_action


class ClickElementAction(page_action.ElementPageAction):

  def RunAction(self, tab):
    code = '''
        function(element, errorMsg) {
          if (!element) {
            throw Error('Cannot find element: ' + errorMsg);
          }
          element.click();
        }'''
    # Click handler that plays media or requests fullscreen may not take
    # effects without user_gesture set to True.
    self.EvaluateCallback(tab, code, user_gesture=True)

Fix a regression where the user_gesture bit isn't set for ClickElement.
Fix a regression where the user_gesture bit isn't set for ClickElement.

The regrssion was introduced in
https://chromium-review.googlesource.com/c/catapult/+/1335627

Once this rolls into Chromium, I'll add a chromium side test to prevent
it from regress again in the future.

Bug: chromium:885912
TEST=manual
R=58bdb6276c01e3ed53e660bf706aa902204feb0d@chromium.org,kbr@chromium.org

Change-Id: Ic1c7e83a3e7d7318baa81531925dab07db9450ca
Reviewed-on: https://chromium-review.googlesource.com/c/1476957
Reviewed-by: Caleb Rouleau <58bdb6276c01e3ed53e660bf706aa902204feb0d@chromium.org>
Commit-Queue: Zhenyao Mo <655bdf1d95ff956cd68886dd9e86ee5e987c9dbb@chromium.org>
