Commit d43280fb authored by nduca@chromium.org's avatar nduca@chromium.org

Escape selectors before evaluating them

R=tonyg
CC=eseidel

Review URL: https://codereview.chromium.org/100283003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238358 0039d316-1c4b-4281-b951-d872f2087c98
parent 9baedd49
......@@ -8,6 +8,9 @@ from telemetry.core import util
from telemetry.core import exceptions
from telemetry.page.actions import page_action
def _EscapeSelector(selector):
return selector.replace('\'', '\\\'')
class ClickElementAction(page_action.PageAction):
def __init__(self, attributes=None):
super(ClickElementAction, self).__init__(attributes)
......@@ -15,7 +18,8 @@ class ClickElementAction(page_action.PageAction):
def RunAction(self, page, tab, previous_action):
def DoClick():
if hasattr(self, 'selector'):
code = 'document.querySelector(\'' + self.selector + '\').click();'
code = ('document.querySelector(\'' + _EscapeSelector(self.selector) +
'\').click();')
try:
tab.ExecuteJavaScript(code)
except exceptions.EvaluateException:
......
......@@ -27,6 +27,25 @@ class ClickElementActionTest(tab_test_case.TabTestCase):
self._tab.EvaluateJavaScript('document.location.pathname;'),
'/blank.html')
def testClickWithSingleQuoteSelectorWaitForNavigation(self):
self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
self._tab.Navigate(
self._browser.http_server.UrlOf('page_with_link.html'))
self._tab.WaitForDocumentReadyStateToBeComplete()
self.assertEquals(
self._tab.EvaluateJavaScript('document.location.pathname;'),
'/page_with_link.html')
data = {'selector': 'a[id=\'clickme\']'}
i = click_element.ClickElementAction(data)
data = {'condition': 'href_change'}
j = wait.WaitAction(data)
j.RunAction(None, self._tab, i)
self.assertEquals(
self._tab.EvaluateJavaScript('document.location.pathname;'),
'/blank.html')
def testClickWithTextWaitForRefChange(self):
self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
self._tab.Navigate(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment