OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 : m_baseURL("http://www.test.com/") | 204 : m_baseURL("http://www.test.com/") |
205 { | 205 { |
206 } | 206 } |
207 | 207 |
208 virtual void TearDown() | 208 virtual void TearDown() |
209 { | 209 { |
210 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 210 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
211 } | 211 } |
212 | 212 |
213 protected: | 213 protected: |
| 214 void registerMockedHttpURLLoad(const std::string& fileName) |
| 215 { |
| 216 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); |
| 217 } |
| 218 |
214 void testAutoResize(const WebSize& minAutoResize, const WebSize& maxAutoResi
ze, | 219 void testAutoResize(const WebSize& minAutoResize, const WebSize& maxAutoResi
ze, |
215 const std::string& pageWidth, const std::string& pageHei
ght, | 220 const std::string& pageWidth, const std::string& pageHei
ght, |
216 int expectedWidth, int expectedHeight, | 221 int expectedWidth, int expectedHeight, |
217 HorizontalScrollbarState expectedHorizontalState, Vertic
alScrollbarState expectedVerticalState); | 222 HorizontalScrollbarState expectedHorizontalState, Vertic
alScrollbarState expectedVerticalState); |
218 | 223 |
219 void testTextInputType(WebTextInputType expectedType, const std::string& htm
lFile); | 224 void testTextInputType(WebTextInputType expectedType, const std::string& htm
lFile); |
220 void testInputMode(const WebString& expectedInputMode, const std::string& ht
mlFile); | 225 void testInputMode(const WebString& expectedInputMode, const std::string& ht
mlFile); |
| 226 void testSelectionRootBounds(const char* htmlFile, float pageScaleFactor); |
221 | 227 |
222 std::string m_baseURL; | 228 std::string m_baseURL; |
223 FrameTestHelpers::WebViewHelper m_webViewHelper; | 229 FrameTestHelpers::WebViewHelper m_webViewHelper; |
224 }; | 230 }; |
225 | 231 |
226 TEST_F(WebViewTest, SetBaseBackgroundColor) | 232 TEST_F(WebViewTest, SetBaseBackgroundColor) |
227 { | 233 { |
228 const WebColor kWhite = 0xFFFFFFFF; | 234 const WebColor kWhite = 0xFFFFFFFF; |
229 const WebColor kBlue = 0xFF0000FF; | 235 const WebColor kBlue = 0xFF0000FF; |
230 const WebColor kDarkCyan = 0xFF227788; | 236 const WebColor kDarkCyan = 0xFF227788; |
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 document->didClearTouchEventHandlers(document); | 1652 document->didClearTouchEventHandlers(document); |
1647 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1653 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1648 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1654 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1649 | 1655 |
1650 // Now removing the handler in the parent document results in a no-handlers
call. | 1656 // Now removing the handler in the parent document results in a no-handlers
call. |
1651 document->didRemoveTouchEventHandler(childFrame); | 1657 document->didRemoveTouchEventHandler(childFrame); |
1652 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); | 1658 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(false)); |
1653 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 1659 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
1654 } | 1660 } |
1655 | 1661 |
| 1662 static WebRect ExpectedRootBounds(WebCore::Document* document, float scaleFactor
) |
| 1663 { |
| 1664 WebCore::Element* element = document->getElementById("root"); |
| 1665 if (!element) |
| 1666 element = document->getElementById("target"); |
| 1667 if (element->hasTagName(WebCore::HTMLNames::iframeTag)) |
| 1668 return ExpectedRootBounds(toHTMLIFrameElement(element)->contentDocument(
), scaleFactor); |
| 1669 |
| 1670 WebCore::IntRect boundingBox = element->pixelSnappedBoundingBox(); |
| 1671 boundingBox = document->frame()->view()->contentsToWindow(boundingBox); |
| 1672 boundingBox.scale(scaleFactor); |
| 1673 return boundingBox; |
| 1674 } |
| 1675 |
| 1676 void WebViewTest::testSelectionRootBounds(const char* htmlFile, float pageScaleF
actor) |
| 1677 { |
| 1678 std::string url = m_baseURL + htmlFile; |
| 1679 |
| 1680 WebView* webView = m_webViewHelper.initializeAndLoad(url, true); |
| 1681 webView->resize(WebSize(640, 480)); |
| 1682 webView->setPageScaleFactor(pageScaleFactor, WebPoint(0, 0)); |
| 1683 webView->layout(); |
| 1684 runPendingTasks(); |
| 1685 |
| 1686 WebFrameImpl* frame = toWebFrameImpl(webView->mainFrame()); |
| 1687 EXPECT_TRUE(frame->frame()->document()->isHTMLDocument()); |
| 1688 WebCore::HTMLDocument* document = WebCore::toHTMLDocument(frame->frame()->do
cument()); |
| 1689 |
| 1690 WebRect expectedRootBounds = ExpectedRootBounds(document, webView->pageScale
Factor()); |
| 1691 WebRect actualRootBounds; |
| 1692 webView->getSelectionRootBounds(actualRootBounds); |
| 1693 ASSERT_EQ(expectedRootBounds, actualRootBounds); |
| 1694 |
| 1695 WebRect anchor, focus; |
| 1696 webView->selectionBounds(anchor, focus); |
| 1697 WebCore::IntRect expectedIntRect = expectedRootBounds; |
| 1698 ASSERT_TRUE(expectedIntRect.contains(anchor)); |
| 1699 // The "overflow" tests have the focus boundary outside of the element box. |
| 1700 ASSERT_EQ(url.find("overflow") == std::string::npos, expectedIntRect.contain
s(focus)); |
| 1701 } |
| 1702 |
| 1703 TEST_F(WebViewTest, GetSelectionRootBounds) |
| 1704 { |
| 1705 // Register all the pages we will be using. |
| 1706 registerMockedHttpURLLoad("select_range_basic.html"); |
| 1707 registerMockedHttpURLLoad("select_range_div_editable.html"); |
| 1708 registerMockedHttpURLLoad("select_range_scroll.html"); |
| 1709 registerMockedHttpURLLoad("select_range_span_editable.html"); |
| 1710 registerMockedHttpURLLoad("select_range_input.html"); |
| 1711 registerMockedHttpURLLoad("select_range_input_overflow.html"); |
| 1712 registerMockedHttpURLLoad("select_range_textarea.html"); |
| 1713 registerMockedHttpURLLoad("select_range_textarea_overflow.html"); |
| 1714 registerMockedHttpURLLoad("select_range_iframe.html"); |
| 1715 registerMockedHttpURLLoad("select_range_iframe_div_editable.html"); |
| 1716 registerMockedHttpURLLoad("select_range_iframe_scroll.html"); |
| 1717 registerMockedHttpURLLoad("select_range_iframe_span_editable.html"); |
| 1718 registerMockedHttpURLLoad("select_range_iframe_input.html"); |
| 1719 registerMockedHttpURLLoad("select_range_iframe_input_overflow.html"); |
| 1720 registerMockedHttpURLLoad("select_range_iframe_textarea.html"); |
| 1721 registerMockedHttpURLLoad("select_range_iframe_textarea_overflow.html"); |
| 1722 |
| 1723 // Test with simple pages. |
| 1724 testSelectionRootBounds("select_range_basic.html", 1.0f); |
| 1725 testSelectionRootBounds("select_range_div_editable.html", 1.0f); |
| 1726 testSelectionRootBounds("select_range_scroll.html", 1.0f); |
| 1727 testSelectionRootBounds("select_range_span_editable.html", 1.0f); |
| 1728 testSelectionRootBounds("select_range_input.html", 1.0f); |
| 1729 testSelectionRootBounds("select_range_input_overflow.html", 1.0f); |
| 1730 testSelectionRootBounds("select_range_textarea.html", 1.0f); |
| 1731 testSelectionRootBounds("select_range_textarea_overflow.html", 1.0f); |
| 1732 |
| 1733 // Test with the same pages as above in iframes. |
| 1734 testSelectionRootBounds("select_range_iframe.html", 1.0f); |
| 1735 testSelectionRootBounds("select_range_iframe_div_editable.html", 1.0f); |
| 1736 testSelectionRootBounds("select_range_iframe_scroll.html", 1.0f); |
| 1737 testSelectionRootBounds("select_range_iframe_span_editable.html", 1.0f); |
| 1738 testSelectionRootBounds("select_range_iframe_input.html", 1.0f); |
| 1739 testSelectionRootBounds("select_range_iframe_input_overflow.html", 1.0f); |
| 1740 testSelectionRootBounds("select_range_iframe_textarea.html", 1.0f); |
| 1741 testSelectionRootBounds("select_range_iframe_textarea_overflow.html", 1.0f); |
| 1742 |
| 1743 // Basic page with scale factor. |
| 1744 testSelectionRootBounds("select_range_basic.html", 0.0f); |
| 1745 testSelectionRootBounds("select_range_basic.html", 0.1f); |
| 1746 testSelectionRootBounds("select_range_basic.html", 1.5f); |
| 1747 testSelectionRootBounds("select_range_basic.html", 2.0f); |
| 1748 } |
| 1749 |
1656 } // namespace | 1750 } // namespace |
OLD | NEW |