Modified: trunk/Source/WebKit/chromium/ChangeLog (125580 => 125581)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-08-14 17:51:48 UTC (rev 125580)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-08-14 17:55:03 UTC (rev 125581)
@@ -1,3 +1,30 @@
+2012-08-14 Iain Merrick <[email protected]>
+
+ [chromium] Add a test to WebFrameTest for selectRange and visiblePositionForWindowPoint.
+ https://bugs.webkit.org/show_bug.cgi?id=93108
+
+ Reviewed by Adam Barth.
+
+ Adds a new test WebFrameTest.SelectRange. This tests WebFrameImpl::selectRange,
+ and also serves to test WebFrameImpl::visiblePositionForWindowPoint as it is
+ used by selectRange.
+
+ The test uses sample files that contain selected text on load. The test uses
+ WebViewImpl::selectionBounds to get the coordinates, deselects all, then
+ calls WebFrameImpl::selectRange to attempt to reselect the same text.
+
+ Four cases are tested:
+ - the basic case
+ - the case where the selected text is offscreen due to a scroll
+ - the case where the selected text is in an iframe
+ - the case where the selected text is in an editable element
+
+ * tests/WebFrameTest.cpp:
+ * tests/data/select_range_basic.html: Added.
+ * tests/data/select_range_editable.html: Added.
+ * tests/data/select_range_iframe.html: Added.
+ * tests/data/select_range_scroll.html: Added.
+
2012-08-14 Joshua Bell <[email protected]>
IndexedDB: Pass cursor continue results back in callback
Modified: trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp (125580 => 125581)
--- trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp 2012-08-14 17:51:48 UTC (rev 125580)
+++ trunk/Source/WebKit/chromium/tests/WebFrameTest.cpp 2012-08-14 17:55:03 UTC (rev 125581)
@@ -958,4 +958,94 @@
webView->close();
}
+static WebView* selectRangeTestCreateWebView(const std::string& url)
+{
+ WebView* webView = FrameTestHelpers::createWebViewAndLoad(url, true);
+ webView->settings()->setDefaultFontSize(12);
+ webView->resize(WebSize(640, 480));
+ return webView;
+}
+
+static WebPoint topLeft(const WebRect& rect)
+{
+ return WebPoint(rect.x, rect.y);
+}
+
+static WebPoint bottomRightMinusOne(const WebRect& rect)
+{
+ // FIXME: If we don't subtract 1 from the x- and y-coordinates of the
+ // selection bounds, selectRange() will select the *next* element. That's
+ // strictly correct, as hit-testing checks the pixel to the lower-right of
+ // the input coordinate, but it's a wart on the API.
+ return WebPoint(rect.x + rect.width - 1, rect.y + rect.height - 1);
+}
+
+static std::string selectionAsString(WebFrame* frame)
+{
+ return std::string(frame->selectionAsText().utf8().data());
+}
+
+TEST_F(WebFrameTest, SelectRange)
+{
+ WebView* webView;
+ WebFrame* frame;
+ WebRect startWebRect;
+ WebRect endWebRect;
+
+ registerMockedHttpURLLoad("select_range_basic.html");
+ registerMockedHttpURLLoad("select_range_scroll.html");
+ registerMockedHttpURLLoad("select_range_iframe.html");
+ registerMockedHttpURLLoad("select_range_editable.html");
+
+ webView = selectRangeTestCreateWebView(m_baseURL + "select_range_basic.html");
+ frame = webView->mainFrame();
+ EXPECT_EQ("Some test text for testing.", selectionAsString(frame));
+ webView->selectionBounds(startWebRect, endWebRect);
+ frame->executeCommand(WebString::fromUTF8("Unselect"));
+ EXPECT_EQ("", selectionAsString(frame));
+ frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
+ EXPECT_EQ("Some test text for testing.", selectionAsString(frame));
+ webView->close();
+
+ webView = selectRangeTestCreateWebView(m_baseURL + "select_range_scroll.html");
+ frame = webView->mainFrame();
+ EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame));
+ webView->selectionBounds(startWebRect, endWebRect);
+ frame->executeCommand(WebString::fromUTF8("Unselect"));
+ EXPECT_EQ("", selectionAsString(frame));
+ frame->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
+ EXPECT_EQ("Some offscreen test text for testing.", selectionAsString(frame));
+ webView->close();
+
+ webView = selectRangeTestCreateWebView(m_baseURL + "select_range_iframe.html");
+ frame = webView->mainFrame();
+ WebFrame* subframe = frame->findChildByExpression(WebString::fromUTF8("/html/body/iframe"));
+ EXPECT_EQ("Some test text for testing.", selectionAsString(subframe));
+ webView->selectionBounds(startWebRect, endWebRect);
+ subframe->executeCommand(WebString::fromUTF8("Unselect"));
+ EXPECT_EQ("", selectionAsString(subframe));
+ subframe->selectRange(topLeft(startWebRect), bottomRightMinusOne(endWebRect));
+ EXPECT_EQ("Some test text for testing.", selectionAsString(subframe));
+ webView->close();
+
+ // Select the middle of an editable element, then try to extend the selection to the top of the document.
+ // The selection range should be clipped to the bounds of the editable element.
+ webView = selectRangeTestCreateWebView(m_baseURL + "select_range_editable.html");
+ frame = webView->mainFrame();
+ EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
+ webView->selectionBounds(startWebRect, endWebRect);
+ frame->selectRange(WebPoint(0, 0), bottomRightMinusOne(endWebRect));
+ EXPECT_EQ("16-char header. This text is initially selected.", selectionAsString(frame));
+ webView->close();
+
+ // As above, but extending the selection to the bottom of the document.
+ webView = selectRangeTestCreateWebView(m_baseURL + "select_range_editable.html");
+ frame = webView->mainFrame();
+ EXPECT_EQ("This text is initially selected.", selectionAsString(frame));
+ webView->selectionBounds(startWebRect, endWebRect);
+ frame->selectRange(topLeft(startWebRect), WebPoint(640, 480));
+ EXPECT_EQ("This text is initially selected. 16-char footer.", selectionAsString(frame));
+ webView->close();
+}
+
} // namespace
Added: trunk/Source/WebKit/chromium/tests/data/select_range_basic.html (0 => 125581)
--- trunk/Source/WebKit/chromium/tests/data/select_range_basic.html (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/select_range_basic.html 2012-08-14 17:55:03 UTC (rev 125581)
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<body>
+Some extra text.
+<span id='target'>Some test text for testing.</span>
+Some extra text.
+<script>
+ function select() {
+ var range = document.createRange();
+ range.selectNode(document.getElementById('target'));
+ window.getSelection().addRange(range);
+ }
+ window._onload_ = select;
+</script>
+</body>
+</html>
+
Added: trunk/Source/WebKit/chromium/tests/data/select_range_editable.html (0 => 125581)
--- trunk/Source/WebKit/chromium/tests/data/select_range_editable.html (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/select_range_editable.html 2012-08-14 17:55:03 UTC (rev 125581)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<body>
+This text won't be selected because it isn't editable.
+<span id='target' contenteditable="true">16-char header. This text is initially selected. 16-char footer.</span>
+This text won't be selected because it isn't editable.
+<script>
+ function select() {
+ var text = document.getElementById('target').firstChild;
+ var range = document.createRange();
+ range.setStart(text, 16);
+ range.setEnd(text, 48);
+ window.getSelection().addRange(range);
+ }
+ window._onload_ = select;
+</script>
+</body>
+</html>
+
Added: trunk/Source/WebKit/chromium/tests/data/select_range_iframe.html (0 => 125581)
--- trunk/Source/WebKit/chromium/tests/data/select_range_iframe.html (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/select_range_iframe.html 2012-08-14 17:55:03 UTC (rev 125581)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<body>
+This is a test case for selecting a range within an iframe.
+<iframe width=400 height=200 id="iframe" src=""
+<script>
+ document.getElementById('iframe').contentWindow.focus();
+</script>
+</body>
+</html>
+
Added: trunk/Source/WebKit/chromium/tests/data/select_range_scroll.html (0 => 125581)
--- trunk/Source/WebKit/chromium/tests/data/select_range_scroll.html (rev 0)
+++ trunk/Source/WebKit/chromium/tests/data/select_range_scroll.html 2012-08-14 17:55:03 UTC (rev 125581)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div style='height:3000px'>
+ <span id="target">Some offscreen test text for testing.</span>
+</div>
+<script>
+ var range = document.createRange();
+ range.selectNode(document.getElementById('target'));
+ window.getSelection().addRange(range);
+ window.scrollBy(0,500);
+</script>
+</body>
+</html>
+