| 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::registerMockedURLFromBaseURL; |
| 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_imeRequestCount(0) {} | 28 ImeRequestTrackingWebViewClient() : m_virtualKeyboardRequestCount(0) {} |
| 29 | 29 |
| 30 // WebWidgetClient methods | 30 // WebWidgetClient methods |
| 31 void showImeIfNeeded() override { ++m_imeRequestCount; } | 31 void showVirtualKeyboard() override { ++m_virtualKeyboardRequestCount; } |
| 32 | 32 |
| 33 // Local methds | 33 // Local methds |
| 34 void reset() { m_imeRequestCount = 0; } | 34 void reset() { m_virtualKeyboardRequestCount = 0; } |
| 35 | 35 |
| 36 int imeRequestCount() { return m_imeRequestCount; } | 36 int virtualKeyboardRequestCount() { return m_virtualKeyboardRequestCount; } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 int m_imeRequestCount; | 39 int m_virtualKeyboardRequestCount; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class ImeOnFocusTest : public ::testing::Test { | 42 class ImeOnFocusTest : public ::testing::Test { |
| 43 public: | 43 public: |
| 44 ImeOnFocusTest() : m_baseURL("http://www.test.com/") {} | 44 ImeOnFocusTest() : m_baseURL("http://www.test.com/") {} |
| 45 | 45 |
| 46 void TearDown() override { | 46 void TearDown() override { |
| 47 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 47 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
| 48 WebCache::clear(); | 48 WebCache::clear(); |
| 49 } | 49 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 | 78 |
| 79 webView->handleInputEvent(webGestureEvent); | 79 webView->handleInputEvent(webGestureEvent); |
| 80 runPendingTasks(); | 80 runPendingTasks(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void ImeOnFocusTest::focus(const AtomicString& element) { | 83 void ImeOnFocusTest::focus(const AtomicString& element) { |
| 84 m_document->body()->getElementById(element)->focus(); | 84 m_document->body()->getElementById(element)->focus(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ImeOnFocusTest::runImeOnFocusTest(std::string fileName, | 87 void ImeOnFocusTest::runImeOnFocusTest(std::string fileName, |
| 88 int expectedImeRequestCount, | 88 int expectedVirtualKeyboardRequestCount, |
| 89 IntPoint tapPoint, | 89 IntPoint tapPoint, |
| 90 const AtomicString& focusElement, | 90 const AtomicString& focusElement, |
| 91 std::string frame) { | 91 std::string frame) { |
| 92 ImeRequestTrackingWebViewClient client; | 92 ImeRequestTrackingWebViewClient client; |
| 93 registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), | 93 registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), |
| 94 WebString::fromUTF8(fileName)); | 94 WebString::fromUTF8(fileName)); |
| 95 WebViewImpl* webView = m_webViewHelper.initialize(true, 0, &client); | 95 WebViewImpl* webView = m_webViewHelper.initialize(true, 0, &client); |
| 96 webView->resize(WebSize(800, 1200)); | 96 webView->resize(WebSize(800, 1200)); |
| 97 loadFrame(webView->mainFrame(), m_baseURL + fileName); | 97 loadFrame(webView->mainFrame(), m_baseURL + fileName); |
| 98 m_document = | 98 m_document = |
| 99 m_webViewHelper.webView()->mainFrameImpl()->document().unwrap<Document>(); | 99 m_webViewHelper.webView()->mainFrameImpl()->document().unwrap<Document>(); |
| 100 | 100 |
| 101 if (!focusElement.isNull()) | 101 if (!focusElement.isNull()) |
| 102 focus(focusElement); | 102 focus(focusElement); |
| 103 EXPECT_EQ(0, client.imeRequestCount()); | 103 EXPECT_EQ(0, client.virtualKeyboardRequestCount()); |
| 104 | 104 |
| 105 if (tapPoint.x() >= 0 && tapPoint.y() >= 0) | 105 if (tapPoint.x() >= 0 && tapPoint.y() >= 0) |
| 106 sendGestureTap(webView, tapPoint); | 106 sendGestureTap(webView, tapPoint); |
| 107 | 107 |
| 108 if (!frame.empty()) { | 108 if (!frame.empty()) { |
| 109 registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), | 109 registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), |
| 110 WebString::fromUTF8(frame)); | 110 WebString::fromUTF8(frame)); |
| 111 WebFrame* childFrame = webView->mainFrame()->firstChild(); | 111 WebFrame* childFrame = webView->mainFrame()->firstChild(); |
| 112 loadFrame(childFrame, m_baseURL + frame); | 112 loadFrame(childFrame, m_baseURL + frame); |
| 113 } | 113 } |
| 114 | 114 |
| 115 if (!focusElement.isNull()) | 115 if (!focusElement.isNull()) |
| 116 focus(focusElement); | 116 focus(focusElement); |
| 117 EXPECT_EQ(expectedImeRequestCount, client.imeRequestCount()); | 117 EXPECT_EQ(expectedVirtualKeyboardRequestCount, |
| 118 client.virtualKeyboardRequestCount()); |
| 118 | 119 |
| 119 m_webViewHelper.reset(); | 120 m_webViewHelper.reset(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 TEST_F(ImeOnFocusTest, OnLoad) { | 123 TEST_F(ImeOnFocusTest, OnLoad) { |
| 123 runImeOnFocusTest("ime-on-focus-on-load.html", 0); | 124 runImeOnFocusTest("ime-on-focus-on-load.html", 0); |
| 124 } | 125 } |
| 125 | 126 |
| 126 TEST_F(ImeOnFocusTest, OnAutofocus) { | 127 TEST_F(ImeOnFocusTest, OnAutofocus) { |
| 127 runImeOnFocusTest("ime-on-focus-on-autofocus.html", 0); | 128 runImeOnFocusTest("ime-on-focus-on-autofocus.html", 0); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 140 runImeOnFocusTest("ime-on-focus-after-navigation-within-page.html", 1, | 141 runImeOnFocusTest("ime-on-focus-after-navigation-within-page.html", 1, |
| 141 IntPoint(50, 50), "input"); | 142 IntPoint(50, 50), "input"); |
| 142 } | 143 } |
| 143 | 144 |
| 144 TEST_F(ImeOnFocusTest, AfterFrameLoadOnGesture) { | 145 TEST_F(ImeOnFocusTest, AfterFrameLoadOnGesture) { |
| 145 runImeOnFocusTest("ime-on-focus-after-frame-load-on-gesture.html", 1, | 146 runImeOnFocusTest("ime-on-focus-after-frame-load-on-gesture.html", 1, |
| 146 IntPoint(50, 50), "input", "frame.html"); | 147 IntPoint(50, 50), "input", "frame.html"); |
| 147 } | 148 } |
| 148 | 149 |
| 149 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |