| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/Document.h" | 5 #include "core/dom/Document.h" |
| 6 #include "core/dom/Element.h" | 6 #include "core/dom/Element.h" |
| 7 #include "core/dom/Node.h" | 7 #include "core/dom/Node.h" |
| 8 #include "core/html/HTMLElement.h" | 8 #include "core/html/HTMLElement.h" |
| 9 #include "platform/testing/URLTestHelpers.h" | 9 #include "platform/testing/URLTestHelpers.h" |
| 10 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
| 11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 12 #include "public/platform/WebURLLoaderMockFactory.h" | 12 #include "public/platform/WebURLLoaderMockFactory.h" |
| 13 #include "public/web/WebCache.h" | 13 #include "public/web/WebCache.h" |
| 14 #include "public/web/WebDocument.h" | 14 #include "public/web/WebDocument.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "web/WebLocalFrameImpl.h" | 16 #include "web/WebLocalFrameImpl.h" |
| 17 #include "web/tests/FrameTestHelpers.h" | 17 #include "web/tests/FrameTestHelpers.h" |
| 18 | 18 |
| 19 using blink::FrameTestHelpers::loadFrame; | 19 using blink::FrameTestHelpers::loadFrame; |
| 20 using blink::testing::runPendingTasks; | 20 using blink::testing::runPendingTasks; |
| 21 using blink::URLTestHelpers::registerMockedURLFromBaseURL; | 21 using blink::URLTestHelpers::registerMockedURLLoadFromBase; |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 class ImeRequestTrackingWebViewClient | 25 class ImeRequestTrackingWebViewClient |
| 26 : public FrameTestHelpers::TestWebViewClient { | 26 : public FrameTestHelpers::TestWebViewClient { |
| 27 public: | 27 public: |
| 28 ImeRequestTrackingWebViewClient() : m_virtualKeyboardRequestCount(0) {} | 28 ImeRequestTrackingWebViewClient() : m_virtualKeyboardRequestCount(0) {} |
| 29 | 29 |
| 30 // WebWidgetClient methods | 30 // WebWidgetClient methods |
| 31 void showVirtualKeyboardOnElementFocus() override { | 31 void showVirtualKeyboardOnElementFocus() override { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 void ImeOnFocusTest::focus(const AtomicString& element) { | 85 void ImeOnFocusTest::focus(const AtomicString& element) { |
| 86 m_document->body()->getElementById(element)->focus(); | 86 m_document->body()->getElementById(element)->focus(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void ImeOnFocusTest::runImeOnFocusTest(std::string fileName, | 89 void ImeOnFocusTest::runImeOnFocusTest(std::string fileName, |
| 90 int expectedVirtualKeyboardRequestCount, | 90 int expectedVirtualKeyboardRequestCount, |
| 91 IntPoint tapPoint, | 91 IntPoint tapPoint, |
| 92 const AtomicString& focusElement, | 92 const AtomicString& focusElement, |
| 93 std::string frame) { | 93 std::string frame) { |
| 94 ImeRequestTrackingWebViewClient client; | 94 ImeRequestTrackingWebViewClient client; |
| 95 registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), | 95 registerMockedURLLoadFromBase(WebString::fromUTF8(m_baseURL), |
| 96 WebString::fromUTF8(fileName)); | 96 testing::webTestDataPath(), |
| 97 WebString::fromUTF8(fileName)); |
| 97 WebViewImpl* webView = m_webViewHelper.initialize(true, 0, &client); | 98 WebViewImpl* webView = m_webViewHelper.initialize(true, 0, &client); |
| 98 webView->resize(WebSize(800, 1200)); | 99 webView->resize(WebSize(800, 1200)); |
| 99 loadFrame(webView->mainFrame(), m_baseURL + fileName); | 100 loadFrame(webView->mainFrame(), m_baseURL + fileName); |
| 100 m_document = | 101 m_document = |
| 101 m_webViewHelper.webView()->mainFrameImpl()->document().unwrap<Document>(); | 102 m_webViewHelper.webView()->mainFrameImpl()->document().unwrap<Document>(); |
| 102 | 103 |
| 103 if (!focusElement.isNull()) | 104 if (!focusElement.isNull()) |
| 104 focus(focusElement); | 105 focus(focusElement); |
| 105 EXPECT_EQ(0, client.virtualKeyboardRequestCount()); | 106 EXPECT_EQ(0, client.virtualKeyboardRequestCount()); |
| 106 | 107 |
| 107 if (tapPoint.x() >= 0 && tapPoint.y() >= 0) | 108 if (tapPoint.x() >= 0 && tapPoint.y() >= 0) |
| 108 sendGestureTap(webView, tapPoint); | 109 sendGestureTap(webView, tapPoint); |
| 109 | 110 |
| 110 if (!frame.empty()) { | 111 if (!frame.empty()) { |
| 111 registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), | 112 registerMockedURLLoadFromBase(WebString::fromUTF8(m_baseURL), |
| 112 WebString::fromUTF8(frame)); | 113 testing::webTestDataPath(), |
| 114 WebString::fromUTF8(frame)); |
| 113 WebFrame* childFrame = webView->mainFrame()->firstChild(); | 115 WebFrame* childFrame = webView->mainFrame()->firstChild(); |
| 114 loadFrame(childFrame, m_baseURL + frame); | 116 loadFrame(childFrame, m_baseURL + frame); |
| 115 } | 117 } |
| 116 | 118 |
| 117 if (!focusElement.isNull()) | 119 if (!focusElement.isNull()) |
| 118 focus(focusElement); | 120 focus(focusElement); |
| 119 EXPECT_EQ(expectedVirtualKeyboardRequestCount, | 121 EXPECT_EQ(expectedVirtualKeyboardRequestCount, |
| 120 client.virtualKeyboardRequestCount()); | 122 client.virtualKeyboardRequestCount()); |
| 121 | 123 |
| 122 m_webViewHelper.reset(); | 124 m_webViewHelper.reset(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 143 runImeOnFocusTest("ime-on-focus-after-navigation-within-page.html", 1, | 145 runImeOnFocusTest("ime-on-focus-after-navigation-within-page.html", 1, |
| 144 IntPoint(50, 50), "input"); | 146 IntPoint(50, 50), "input"); |
| 145 } | 147 } |
| 146 | 148 |
| 147 TEST_F(ImeOnFocusTest, AfterFrameLoadOnGesture) { | 149 TEST_F(ImeOnFocusTest, AfterFrameLoadOnGesture) { |
| 148 runImeOnFocusTest("ime-on-focus-after-frame-load-on-gesture.html", 1, | 150 runImeOnFocusTest("ime-on-focus-after-frame-load-on-gesture.html", 1, |
| 149 IntPoint(50, 50), "input", "frame.html"); | 151 IntPoint(50, 50), "input", "frame.html"); |
| 150 } | 152 } |
| 151 | 153 |
| 152 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |