| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); | 240 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void testAutoResize(const WebSize& minAutoResize, const WebSize& maxAutoResi
ze, | 243 void testAutoResize(const WebSize& minAutoResize, const WebSize& maxAutoResi
ze, |
| 244 const std::string& pageWidth, const std::string& pageHei
ght, | 244 const std::string& pageWidth, const std::string& pageHei
ght, |
| 245 int expectedWidth, int expectedHeight, | 245 int expectedWidth, int expectedHeight, |
| 246 HorizontalScrollbarState expectedHorizontalState, Vertic
alScrollbarState expectedVerticalState); | 246 HorizontalScrollbarState expectedHorizontalState, Vertic
alScrollbarState expectedVerticalState); |
| 247 | 247 |
| 248 void testTextInputType(WebTextInputType expectedType, const std::string& htm
lFile); | 248 void testTextInputType(WebTextInputType expectedType, const std::string& htm
lFile); |
| 249 void testInputMode(const WebString& expectedInputMode, const std::string& ht
mlFile); | 249 void testInputMode(const WebString& expectedInputMode, const std::string& ht
mlFile); |
| 250 bool tapElement(WebInputEvent::Type, const RawPtr<Element>&); | 250 bool tapElement(WebInputEvent::Type, Element*); |
| 251 bool tapElementById(WebInputEvent::Type, const WebString& id); | 251 bool tapElementById(WebInputEvent::Type, const WebString& id); |
| 252 | 252 |
| 253 std::string m_baseURL; | 253 std::string m_baseURL; |
| 254 FrameTestHelpers::WebViewHelper m_webViewHelper; | 254 FrameTestHelpers::WebViewHelper m_webViewHelper; |
| 255 }; | 255 }; |
| 256 | 256 |
| 257 TEST_F(WebViewTest, SaveImageAt) | 257 TEST_F(WebViewTest, SaveImageAt) |
| 258 { | 258 { |
| 259 SaveImageFromDataURLWebViewClient client; | 259 SaveImageFromDataURLWebViewClient client; |
| 260 | 260 |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 webView->setInitialFocus(false); | 979 webView->setInitialFocus(false); |
| 980 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); | 980 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); |
| 981 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().height); | 981 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().height); |
| 982 | 982 |
| 983 // Set up a composition from existing text that needs to be committed. | 983 // Set up a composition from existing text that needs to be committed. |
| 984 Vector<CompositionUnderline> emptyUnderlines; | 984 Vector<CompositionUnderline> emptyUnderlines; |
| 985 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); | 985 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webView->mainFrame()); |
| 986 frame->frame()->inputMethodController().setCompositionFromExistingText(empty
Underlines, 3, 3); | 986 frame->frame()->inputMethodController().setCompositionFromExistingText(empty
Underlines, 3, 3); |
| 987 | 987 |
| 988 // Scroll the input field out of the viewport. | 988 // Scroll the input field out of the viewport. |
| 989 RawPtr<Element> element = static_cast<RawPtr<Element>>(webView->mainFrame()-
>document().getElementById("btn")); | 989 Element* element = static_cast<Element*>(webView->mainFrame()->document().ge
tElementById("btn")); |
| 990 element->scrollIntoView(); | 990 element->scrollIntoView(); |
| 991 float offsetHeight = webView->mainFrame()->scrollOffset().height; | 991 float offsetHeight = webView->mainFrame()->scrollOffset().height; |
| 992 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); | 992 EXPECT_EQ(0, webView->mainFrame()->scrollOffset().width); |
| 993 EXPECT_LT(0, offsetHeight); | 993 EXPECT_LT(0, offsetHeight); |
| 994 | 994 |
| 995 WebTextInputInfo info = webView->textInputInfo(); | 995 WebTextInputInfo info = webView->textInputInfo(); |
| 996 EXPECT_EQ("hello", std::string(info.value.utf8().data())); | 996 EXPECT_EQ("hello", std::string(info.value.utf8().data())); |
| 997 | 997 |
| 998 // Verify that the input field is not scrolled back into the viewport. | 998 // Verify that the input field is not scrolled back into the viewport. |
| 999 webView->confirmComposition(WebWidget::DoNotKeepSelection); | 999 webView->confirmComposition(WebWidget::DoNotKeepSelection); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 // Make the page scale and scroll with the given paremeters. | 1314 // Make the page scale and scroll with the given paremeters. |
| 1315 webViewImpl->setPageScaleFactor(2.0f); | 1315 webViewImpl->setPageScaleFactor(2.0f); |
| 1316 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); | 1316 webViewImpl->mainFrame()->setScrollOffset(WebSize(94, 111)); |
| 1317 webViewImpl->setVisualViewportOffset(WebFloatPoint(12, 20)); | 1317 webViewImpl->setVisualViewportOffset(WebFloatPoint(12, 20)); |
| 1318 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 1318 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 1319 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); | 1319 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); |
| 1320 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); | 1320 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); |
| 1321 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); | 1321 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); |
| 1322 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); | 1322 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); |
| 1323 | 1323 |
| 1324 RawPtr<Element> element = static_cast<RawPtr<Element>>(webViewImpl->mainFram
e()->document().body()); | 1324 Element* element = static_cast<Element*>(webViewImpl->mainFrame()->document(
).body()); |
| 1325 webViewImpl->enterFullScreenForElement(element.get()); | 1325 webViewImpl->enterFullScreenForElement(element); |
| 1326 webViewImpl->didEnterFullScreen(); | 1326 webViewImpl->didEnterFullScreen(); |
| 1327 | 1327 |
| 1328 // Page scale factor must be 1.0 during fullscreen for elements to be sized | 1328 // Page scale factor must be 1.0 during fullscreen for elements to be sized |
| 1329 // properly. | 1329 // properly. |
| 1330 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); | 1330 EXPECT_EQ(1.0f, webViewImpl->pageScaleFactor()); |
| 1331 | 1331 |
| 1332 // Make sure fullscreen nesting doesn't disrupt scroll/scale saving. | 1332 // Make sure fullscreen nesting doesn't disrupt scroll/scale saving. |
| 1333 RawPtr<Element> otherElement = static_cast<RawPtr<Element>>(webViewImpl->mai
nFrame()->document().head()); | 1333 Element* otherElement = static_cast<Element*>(webViewImpl->mainFrame()->docu
ment().head()); |
| 1334 webViewImpl->enterFullScreenForElement(otherElement.get()); | 1334 webViewImpl->enterFullScreenForElement(otherElement); |
| 1335 | 1335 |
| 1336 // Confirm that exiting fullscreen restores the parameters. | 1336 // Confirm that exiting fullscreen restores the parameters. |
| 1337 webViewImpl->didExitFullScreen(); | 1337 webViewImpl->didExitFullScreen(); |
| 1338 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); | 1338 EXPECT_EQ(2.0f, webViewImpl->pageScaleFactor()); |
| 1339 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); | 1339 EXPECT_EQ(94, webViewImpl->mainFrame()->scrollOffset().width); |
| 1340 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); | 1340 EXPECT_EQ(111, webViewImpl->mainFrame()->scrollOffset().height); |
| 1341 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); | 1341 EXPECT_EQ(12, webViewImpl->visualViewportOffset().x); |
| 1342 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); | 1342 EXPECT_EQ(20, webViewImpl->visualViewportOffset().y); |
| 1343 | 1343 |
| 1344 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | 1344 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 void setContentDetectionResult(const WebContentDetectionResult& result) { m_
contentDetectionResult = result; } | 1458 void setContentDetectionResult(const WebContentDetectionResult& result) { m_
contentDetectionResult = result; } |
| 1459 | 1459 |
| 1460 private: | 1460 private: |
| 1461 bool m_contentDetectionRequested; | 1461 bool m_contentDetectionRequested; |
| 1462 bool m_pendingIntentsCancelled; | 1462 bool m_pendingIntentsCancelled; |
| 1463 WebURL m_scheduledIntentURL; | 1463 WebURL m_scheduledIntentURL; |
| 1464 bool m_wasInMainFrame; | 1464 bool m_wasInMainFrame; |
| 1465 WebContentDetectionResult m_contentDetectionResult; | 1465 WebContentDetectionResult m_contentDetectionResult; |
| 1466 }; | 1466 }; |
| 1467 | 1467 |
| 1468 bool WebViewTest::tapElement(WebInputEvent::Type type, const RawPtr<Element>& el
ement) | 1468 bool WebViewTest::tapElement(WebInputEvent::Type type, Element* element) |
| 1469 { | 1469 { |
| 1470 if (!element || !element->layoutObject()) | 1470 if (!element || !element->layoutObject()) |
| 1471 return false; | 1471 return false; |
| 1472 | 1472 |
| 1473 DCHECK(m_webViewHelper.webView()); | 1473 DCHECK(m_webViewHelper.webView()); |
| 1474 element->scrollIntoViewIfNeeded(); | 1474 element->scrollIntoViewIfNeeded(); |
| 1475 | 1475 |
| 1476 // TODO(bokan): Technically incorrect, event positions should be in viewport
space. crbug.com/371902. | 1476 // TODO(bokan): Technically incorrect, event positions should be in viewport
space. crbug.com/371902. |
| 1477 IntPoint center = m_webViewHelper.webViewImpl()->mainFrameImpl()->frameView(
)->contentsToScreen( | 1477 IntPoint center = m_webViewHelper.webViewImpl()->mainFrameImpl()->frameView(
)->contentsToScreen( |
| 1478 element->layoutObject()->absoluteBoundingBoxRect()).center(); | 1478 element->layoutObject()->absoluteBoundingBoxRect()).center(); |
| 1479 | 1479 |
| 1480 WebGestureEvent event; | 1480 WebGestureEvent event; |
| 1481 event.type = type; | 1481 event.type = type; |
| 1482 event.sourceDevice = WebGestureDeviceTouchscreen; | 1482 event.sourceDevice = WebGestureDeviceTouchscreen; |
| 1483 event.x = center.x(); | 1483 event.x = center.x(); |
| 1484 event.y = center.y(); | 1484 event.y = center.y(); |
| 1485 | 1485 |
| 1486 m_webViewHelper.webView()->handleInputEvent(event); | 1486 m_webViewHelper.webView()->handleInputEvent(event); |
| 1487 runPendingTasks(); | 1487 runPendingTasks(); |
| 1488 return true; | 1488 return true; |
| 1489 } | 1489 } |
| 1490 | 1490 |
| 1491 bool WebViewTest::tapElementById(WebInputEvent::Type type, const WebString& id) | 1491 bool WebViewTest::tapElementById(WebInputEvent::Type type, const WebString& id) |
| 1492 { | 1492 { |
| 1493 DCHECK(m_webViewHelper.webView()); | 1493 DCHECK(m_webViewHelper.webView()); |
| 1494 RawPtr<Element> element = static_cast<RawPtr<Element>>(m_webViewHelper.webVi
ew()->mainFrame()->document().getElementById(id)); | 1494 Element* element = static_cast<Element*>(m_webViewHelper.webView()->mainFram
e()->document().getElementById(id)); |
| 1495 return tapElement(type, element); | 1495 return tapElement(type, element); |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 TEST_F(WebViewTest, DetectContentAroundPosition) | 1498 TEST_F(WebViewTest, DetectContentAroundPosition) |
| 1499 { | 1499 { |
| 1500 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_listeners.html")); | 1500 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c
_str()), WebString::fromUTF8("content_listeners.html")); |
| 1501 | 1501 |
| 1502 ContentDetectorClient client; | 1502 ContentDetectorClient client; |
| 1503 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_li
steners.html", true, 0, &client); | 1503 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_li
steners.html", true, 0, &client); |
| 1504 webView->resize(WebSize(500, 300)); | 1504 webView->resize(WebSize(500, 300)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_li
steners_iframe.html", true, 0, &client); | 1556 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "content_li
steners_iframe.html", true, 0, &client); |
| 1557 webView->resize(WebSize(500, 300)); | 1557 webView->resize(WebSize(500, 300)); |
| 1558 webView->updateAllLifecyclePhases(); | 1558 webView->updateAllLifecyclePhases(); |
| 1559 runPendingTasks(); | 1559 runPendingTasks(); |
| 1560 | 1560 |
| 1561 WebString noListener = WebString::fromUTF8("noListener"); | 1561 WebString noListener = WebString::fromUTF8("noListener"); |
| 1562 WebString frameName = WebString::fromUTF8("innerFrame"); | 1562 WebString frameName = WebString::fromUTF8("innerFrame"); |
| 1563 | 1563 |
| 1564 WebURL intentURL = toKURL(m_baseURL); | 1564 WebURL intentURL = toKURL(m_baseURL); |
| 1565 client.setContentDetectionResult(WebContentDetectionResult(WebRange(), WebSt
ring(), intentURL)); | 1565 client.setContentDetectionResult(WebContentDetectionResult(WebRange(), WebSt
ring(), intentURL)); |
| 1566 RawPtr<Element> element = static_cast<RawPtr<Element>>(webView->findFrameByN
ame(frameName)->document().getElementById(noListener)); | 1566 Element* element = static_cast<Element*>(webView->findFrameByName(frameName)
->document().getElementById(noListener)); |
| 1567 EXPECT_TRUE(tapElement(WebInputEvent::GestureTap, element)); | 1567 EXPECT_TRUE(tapElement(WebInputEvent::GestureTap, element)); |
| 1568 EXPECT_TRUE(client.scheduledIntentURL() == intentURL); | 1568 EXPECT_TRUE(client.scheduledIntentURL() == intentURL); |
| 1569 EXPECT_FALSE(client.wasInMainFrame()); | 1569 EXPECT_FALSE(client.wasInMainFrame()); |
| 1570 | 1570 |
| 1571 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. | 1571 m_webViewHelper.reset(); // Explicitly reset to break dependency on locally
scoped client. |
| 1572 } | 1572 } |
| 1573 | 1573 |
| 1574 TEST_F(WebViewTest, ClientTapHandling) | 1574 TEST_F(WebViewTest, ClientTapHandling) |
| 1575 { | 1575 { |
| 1576 TapHandlingWebViewClient client; | 1576 TapHandlingWebViewClient client; |
| (...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3291 frame->setAutofillClient(&client); | 3291 frame->setAutofillClient(&client); |
| 3292 webView->setInitialFocus(false); | 3292 webView->setInitialFocus(false); |
| 3293 | 3293 |
| 3294 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel
lo").c_str()))); | 3294 EXPECT_TRUE(webView->confirmComposition(WebString::fromUTF8(std::string("hel
lo").c_str()))); |
| 3295 EXPECT_EQ(1, client.textChangesFromUserGesture()); | 3295 EXPECT_EQ(1, client.textChangesFromUserGesture()); |
| 3296 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); | 3296 EXPECT_FALSE(UserGestureIndicator::processingUserGesture()); |
| 3297 frame->setAutofillClient(0); | 3297 frame->setAutofillClient(0); |
| 3298 } | 3298 } |
| 3299 | 3299 |
| 3300 } // namespace blink | 3300 } // namespace blink |
| OLD | NEW |