diff options
author | samuong <samuong@chromium.org> | 2015-01-13 23:03:55 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-14 07:04:48 +0000 |
commit | 089c3ddeec583fd9e11564727a9695b70657e681 (patch) | |
tree | 8424dae97a40f57ca1d0ee1da4089056a54366a6 | |
parent | 41d8d3c2026d46f860694dc0fc51e61543be8adf (diff) | |
download | chromium_src-089c3ddeec583fd9e11564727a9695b70657e681.zip chromium_src-089c3ddeec583fd9e11564727a9695b70657e681.tar.gz chromium_src-089c3ddeec583fd9e11564727a9695b70657e681.tar.bz2 |
[chromedriver] Use center of first ClientRect when moving mouse to an element.
Previously we used the center of the bounding box, but this can cause problems if the center of the bounding box is outside the element.
This CL also changes the behavior of the GetElementLocationOnceScrolledIntoView command in the same way.
BUG=
Review URL: https://codereview.chromium.org/848483002
Cr-Commit-Position: refs/heads/master@{#311423}
-rw-r--r-- | chrome/test/chromedriver/element_commands.cc | 2 | ||||
-rw-r--r-- | chrome/test/chromedriver/element_util.cc | 15 | ||||
-rw-r--r-- | chrome/test/chromedriver/element_util.h | 1 | ||||
-rwxr-xr-x | chrome/test/chromedriver/test/run_py_tests.py | 23 | ||||
-rw-r--r-- | chrome/test/chromedriver/window_commands.cc | 17 | ||||
-rw-r--r-- | chrome/test/data/chromedriver/multiline.html | 13 |
6 files changed, 54 insertions, 17 deletions
diff --git a/chrome/test/chromedriver/element_commands.cc b/chrome/test/chromedriver/element_commands.cc index f690734..3eb07a2 100644 --- a/chrome/test/chromedriver/element_commands.cc +++ b/chrome/test/chromedriver/element_commands.cc @@ -445,7 +445,7 @@ Status ExecuteGetElementLocationOnceScrolledIntoView( scoped_ptr<base::Value>* value) { WebPoint location; Status status = ScrollElementIntoView( - session, web_view, element_id, &location); + session, web_view, element_id, nullptr, &location); if (status.IsError()) return status; value->reset(CreateValueFrom(location)); diff --git a/chrome/test/chromedriver/element_util.cc b/chrome/test/chromedriver/element_util.cc index 9f02b49..e8714d3 100644 --- a/chrome/test/chromedriver/element_util.cc +++ b/chrome/test/chromedriver/element_util.cc @@ -577,14 +577,21 @@ Status ScrollElementIntoView( Session* session, WebView* web_view, const std::string& id, + const WebPoint* offset, WebPoint* location) { - WebSize size; - Status status = GetElementSize(session, web_view, id, &size); + WebRect region; + Status status = GetElementRegion(session, web_view, id, ®ion); if (status.IsError()) return status; - return ScrollElementRegionIntoView( - session, web_view, id, WebRect(WebPoint(0, 0), size), + status = ScrollElementRegionIntoView(session, web_view, id, region, false /* center */, std::string(), location); + if (status.IsError()) + return status; + if (offset) + location->Offset(offset->x, offset->y); + else + location->Offset(region.size.width / 2, region.size.height / 2); + return Status(kOk); } Status ScrollElementRegionIntoView( diff --git a/chrome/test/chromedriver/element_util.h b/chrome/test/chromedriver/element_util.h index 0fbd766..142fd64 100644 --- a/chrome/test/chromedriver/element_util.h +++ b/chrome/test/chromedriver/element_util.h @@ -131,6 +131,7 @@ Status ScrollElementIntoView( Session* session, WebView* web_view, const std::string& element_id, + const WebPoint* offset, WebPoint* location); // |element_id| refers to the element which is to be scrolled into view. diff --git a/chrome/test/chromedriver/test/run_py_tests.py b/chrome/test/chromedriver/test/run_py_tests.py index 5af9a6a..29f2237 100755 --- a/chrome/test/chromedriver/test/run_py_tests.py +++ b/chrome/test/chromedriver/test/run_py_tests.py @@ -571,6 +571,29 @@ class ChromeDriverTest(ChromeDriverBaseTest): self._driver.MouseMoveTo(div, 10, 10) self.assertEquals(1, len(self._driver.FindElements('tag name', 'br'))) + def testMoveToElementAndClick(self): + self._driver.Load(self.GetHttpUrlForFile('/chromedriver/multiline.html')) + + # Check that link element spans two lines and that the first ClientRect is + # above the second. + link = self._driver.FindElements('tag name', 'a')[0] + client_rects = self._driver.ExecuteScript( + 'return arguments[0].getClientRects();', link) + self.assertEquals(2, len(client_rects)) + self.assertTrue(client_rects[0]['bottom'] < client_rects[1]['top']) + + # Check that the center of the link's bounding ClientRect is outside the + # element. + bounding_client_rect = self._driver.ExecuteScript( + 'return arguments[0].getBoundingClientRect();', link) + center = bounding_client_rect['left'] + bounding_client_rect['width'] / 2 + self.assertTrue(client_rects[1]['right'] < center) + self.assertTrue(center < client_rects[0]['left']) + + self._driver.MouseMoveTo(link) + self._driver.MouseClick() + self.assertTrue(self._driver.GetCurrentUrl().endswith('#top')) + def testMouseClick(self): div = self._driver.ExecuteScript( 'document.body.innerHTML = "<div>old</div>";' diff --git a/chrome/test/chromedriver/window_commands.cc b/chrome/test/chromedriver/window_commands.cc index 8a62f89..9a3c405 100644 --- a/chrome/test/chromedriver/window_commands.cc +++ b/chrome/test/chromedriver/window_commands.cc @@ -470,22 +470,15 @@ Status ExecuteMouseMoveTo( WebPoint location; if (has_element) { - Status status = ScrollElementIntoView( - session, web_view, element_id, &location); + WebPoint offset(x_offset, y_offset); + Status status = ScrollElementIntoView(session, web_view, element_id, + has_offset ? &offset : nullptr, &location); if (status.IsError()) return status; } else { location = session->mouse_position; - } - - if (has_offset) { - location.Offset(x_offset, y_offset); - } else { - WebSize size; - Status status = GetElementSize(session, web_view, element_id, &size); - if (status.IsError()) - return status; - location.Offset(size.width / 2, size.height / 2); + if (has_offset) + location.Offset(x_offset, y_offset); } std::list<MouseEvent> events; diff --git a/chrome/test/data/chromedriver/multiline.html b/chrome/test/data/chromedriver/multiline.html new file mode 100644 index 0000000..c7bf5ff --- /dev/null +++ b/chrome/test/data/chromedriver/multiline.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>A multi-line link</title> + </head> + <body> + <p style="max-width: 11em"> + This test page contains <a href="#top">a link</a> that spans two lines. + The center of the bounding box of the link is not inside the link element. + </p> + </body> +</html> |