summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 20:21:37 +0000
committerkkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 20:21:37 +0000
commit731f69273e5ae9929d588ddd5ac7bd456beb2ffb (patch)
tree553efd0c3366ff3a4c1a4b117af5ab9e924e9648
parent7601f5371f4ae7f7598cc3b485450e032fa0f5e9 (diff)
downloadchromium_src-731f69273e5ae9929d588ddd5ac7bd456beb2ffb.zip
chromium_src-731f69273e5ae9929d588ddd5ac7bd456beb2ffb.tar.gz
chromium_src-731f69273e5ae9929d588ddd5ac7bd456beb2ffb.tar.bz2
In chromedriver, set the cursor at the end of text inputs when first focusing
them. BUG=89720,89723 TEST=none Review URL: http://codereview.chromium.org/7471018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93463 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/test/webdriver/session.cc8
-rw-r--r--chrome/test/webdriver/test/chromedriver_tests.py17
-rw-r--r--chrome/test/webdriver/test/keyboard.html6
3 files changed, 30 insertions, 1 deletions
diff --git a/chrome/test/webdriver/session.cc b/chrome/test/webdriver/session.cc
index 6f331eb..7d73b34 100644
--- a/chrome/test/webdriver/session.cc
+++ b/chrome/test/webdriver/session.cc
@@ -171,7 +171,9 @@ Error* Session::SendKeys(const WebElementId& element, const string16& keys) {
// because this may cause us to lose the current cursor position in the
// element.
// Secondly, we focus the target element.
- // Thirdly, we check if the new active element is the target element. If not,
+ // Thirdly, if the target element is newly focused and is a text input, we
+ // set the cursor position at the end.
+ // Fourthly, we check if the new active element is the target element. If not,
// we throw an error.
// Additional notes:
// - |document.activeElement| is the currently focused element, or body if
@@ -188,6 +190,10 @@ Error* Session::SendKeys(const WebElementId& element, const string16& keys) {
"if (elem != prevActiveElem && prevActiveElem)"
" prevActiveElem.blur();"
"elem.focus();"
+ "if (elem != prevActiveElem && elem.value && elem.value.length &&"
+ " elem.setSelectionRange) {"
+ " elem.setSelectionRange(elem.value.length, elem.value.length);"
+ "}"
"if (elem != doc.activeElement)"
" throw new Error('Failed to send keys because cannot focus element.');";
Value* unscoped_result = NULL;
diff --git a/chrome/test/webdriver/test/chromedriver_tests.py b/chrome/test/webdriver/test/chromedriver_tests.py
index be0a8b1..f26e2e7 100644
--- a/chrome/test/webdriver/test/chromedriver_tests.py
+++ b/chrome/test/webdriver/test/chromedriver_tests.py
@@ -480,6 +480,23 @@ class TypingTest(ChromeDriverTest):
body.send_keys(' there')
self.assertEquals('hi there', body.text)
+ def testAppendsToTextInput(self):
+ self._driver.get(GetTestDataUrl() + '/keyboard.html')
+ text_elem = self._driver.find_element_by_name('input')
+ text_elem.send_keys(' text')
+ self.assertEquals('more text', text_elem.get_attribute('value'))
+ area_elem = self._driver.find_element_by_name('area')
+ area_elem.send_keys(' text')
+ self.assertEquals('more text', area_elem.get_attribute('value'))
+
+ def testTextAreaKeepsCursorPosition(self):
+ self._driver.get(GetTestDataUrl() + '/keyboard.html')
+ area_elem = self._driver.find_element_by_name('area')
+ area_elem.send_keys(' text')
+ area_elem.send_keys(Keys.LEFT * 9)
+ area_elem.send_keys('much ')
+ self.assertEquals('much more text', area_elem.get_attribute('value'))
+
class UrlBaseTest(unittest.TestCase):
"""Tests that the server can be configured for a different URL base."""
diff --git a/chrome/test/webdriver/test/keyboard.html b/chrome/test/webdriver/test/keyboard.html
new file mode 100644
index 0000000..aa264fd
--- /dev/null
+++ b/chrome/test/webdriver/test/keyboard.html
@@ -0,0 +1,6 @@
+<html>
+ <body>
+ <input name='input' type='text' value='more'></input>
+ <textarea name='area'>more</textarea>
+ </body>
+</html>