Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: Source/web/tests/ImeOnFocusTest.cpp

Issue 1174283002: Fix unit test style in Source/web/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove static Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/web/tests/FrameLoaderClientImplTest.cpp ('k') | Source/web/tests/KeyboardTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "config.h" 5 #include "config.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/dom/Node.h" 9 #include "core/dom/Node.h"
10 #include "core/html/HTMLElement.h" 10 #include "core/html/HTMLElement.h"
11 #include "platform/testing/URLTestHelpers.h" 11 #include "platform/testing/URLTestHelpers.h"
12 #include "platform/testing/UnitTestHelpers.h" 12 #include "platform/testing/UnitTestHelpers.h"
13 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
14 #include "public/platform/WebUnitTestSupport.h" 14 #include "public/platform/WebUnitTestSupport.h"
15 #include "public/web/WebDocument.h" 15 #include "public/web/WebDocument.h"
16 #include "web/WebLocalFrameImpl.h" 16 #include "web/WebLocalFrameImpl.h"
17 #include "web/tests/FrameTestHelpers.h" 17 #include "web/tests/FrameTestHelpers.h"
18
19 #include <gtest/gtest.h> 18 #include <gtest/gtest.h>
20 19
21 using namespace blink;
22 using blink::FrameTestHelpers::loadFrame; 20 using blink::FrameTestHelpers::loadFrame;
23 using blink::testing::runPendingTasks; 21 using blink::testing::runPendingTasks;
24 using URLTestHelpers::registerMockedURLFromBaseURL; 22 using blink::URLTestHelpers::registerMockedURLFromBaseURL;
25 23
26 namespace { 24 namespace blink {
27 25
28 class ImeRequestTrackingWebViewClient : public FrameTestHelpers::TestWebViewClie nt { 26 class ImeRequestTrackingWebViewClient : public FrameTestHelpers::TestWebViewClie nt {
29 public: 27 public:
30 ImeRequestTrackingWebViewClient() : 28 ImeRequestTrackingWebViewClient() :
31 m_imeRequestCount(0) 29 m_imeRequestCount(0)
32 { 30 {
33 } 31 }
34 32
35 // WebWidgetClient methods 33 // WebWidgetClient methods
36 virtual void showImeIfNeeded() override 34 void showImeIfNeeded() override
37 { 35 {
38 ++m_imeRequestCount; 36 ++m_imeRequestCount;
39 } 37 }
40 38
41 // Local methds 39 // Local methds
42 void reset() 40 void reset()
43 { 41 {
44 m_imeRequestCount = 0; 42 m_imeRequestCount = 0;
45 } 43 }
46 44
47 int imeRequestCount() 45 int imeRequestCount()
48 { 46 {
49 return m_imeRequestCount; 47 return m_imeRequestCount;
50 } 48 }
51 49
52 private: 50 private:
53 int m_imeRequestCount; 51 int m_imeRequestCount;
54 }; 52 };
55 53
56 class ImeOnFocusTest : public ::testing::Test { 54 class ImeOnFocusTest : public ::testing::Test {
57 public: 55 public:
58 ImeOnFocusTest() 56 ImeOnFocusTest()
59 : m_baseURL("http://www.test.com/") 57 : m_baseURL("http://www.test.com/")
60 { 58 {
61 } 59 }
62 60
63 virtual void TearDown() 61 void TearDown() override
64 { 62 {
65 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); 63 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
66 } 64 }
67 65
68 protected: 66 protected:
69 void sendGestureTap(WebView*, IntPoint); 67 void sendGestureTap(WebView*, IntPoint);
70 void focus(const WTF::AtomicString& element); 68 void focus(const AtomicString& element);
71 void runImeOnFocusTest(std::string fileName, int, IntPoint tapPoint = IntPoi nt(-1, -1), const WTF::AtomicString& focusElement = WTF::nullAtom, std::string f rame = ""); 69 void runImeOnFocusTest(std::string fileName, int, IntPoint tapPoint = IntPoi nt(-1, -1), const AtomicString& focusElement = nullAtom, std::string frame = "") ;
72 70
73 std::string m_baseURL; 71 std::string m_baseURL;
74 FrameTestHelpers::WebViewHelper m_webViewHelper; 72 FrameTestHelpers::WebViewHelper m_webViewHelper;
75 RefPtrWillBePersistent<Document> m_document; 73 RefPtrWillBePersistent<Document> m_document;
76 }; 74 };
77 75
78 void ImeOnFocusTest::sendGestureTap(WebView* webView, IntPoint clientPoint) 76 void ImeOnFocusTest::sendGestureTap(WebView* webView, IntPoint clientPoint)
79 { 77 {
80 WebGestureEvent webGestureEvent; 78 WebGestureEvent webGestureEvent;
81 webGestureEvent.type = WebInputEvent::GestureTap; 79 webGestureEvent.type = WebInputEvent::GestureTap;
82 webGestureEvent.x = clientPoint.x(); 80 webGestureEvent.x = clientPoint.x();
83 webGestureEvent.y = clientPoint.y(); 81 webGestureEvent.y = clientPoint.y();
84 webGestureEvent.globalX = clientPoint.x(); 82 webGestureEvent.globalX = clientPoint.x();
85 webGestureEvent.globalY = clientPoint.y(); 83 webGestureEvent.globalY = clientPoint.y();
86 webGestureEvent.data.tap.tapCount = 1; 84 webGestureEvent.data.tap.tapCount = 1;
87 webGestureEvent.data.tap.width = 10; 85 webGestureEvent.data.tap.width = 10;
88 webGestureEvent.data.tap.height = 10; 86 webGestureEvent.data.tap.height = 10;
89 87
90 webView->handleInputEvent(webGestureEvent); 88 webView->handleInputEvent(webGestureEvent);
91 runPendingTasks(); 89 runPendingTasks();
92 } 90 }
93 91
94 void ImeOnFocusTest::focus(const WTF::AtomicString& element) 92 void ImeOnFocusTest::focus(const AtomicString& element)
95 { 93 {
96 m_document->body()->getElementById(element)->focus(); 94 m_document->body()->getElementById(element)->focus();
97 } 95 }
98 96
99 void ImeOnFocusTest::runImeOnFocusTest(std::string fileName, int expectedImeRequ estCount, IntPoint tapPoint, const WTF::AtomicString& focusElement, std::string frame) 97 void ImeOnFocusTest::runImeOnFocusTest(std::string fileName, int expectedImeRequ estCount, IntPoint tapPoint, const AtomicString& focusElement, std::string frame )
100 { 98 {
101 ImeRequestTrackingWebViewClient client; 99 ImeRequestTrackingWebViewClient client;
102 registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::from UTF8(fileName)); 100 registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::from UTF8(fileName));
103 WebViewImpl* webView = m_webViewHelper.initialize(true, 0, &client); 101 WebViewImpl* webView = m_webViewHelper.initialize(true, 0, &client);
104 webView->resize(WebSize(800, 1200)); 102 webView->resize(WebSize(800, 1200));
105 loadFrame(webView->mainFrame(), m_baseURL + fileName); 103 loadFrame(webView->mainFrame(), m_baseURL + fileName);
106 m_document = m_webViewHelper.webViewImpl()->mainFrameImpl()->document().unwr ap<Document>(); 104 m_document = m_webViewHelper.webViewImpl()->mainFrameImpl()->document().unwr ap<Document>();
107 105
108 if (!focusElement.isNull()) 106 if (!focusElement.isNull())
109 focus(focusElement); 107 focus(focusElement);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 TEST_F(ImeOnFocusTest, AfterNavigationWithinPage) 146 TEST_F(ImeOnFocusTest, AfterNavigationWithinPage)
149 { 147 {
150 runImeOnFocusTest("ime-on-focus-after-navigation-within-page.html", 1, IntPo int(50, 50), "input"); 148 runImeOnFocusTest("ime-on-focus-after-navigation-within-page.html", 1, IntPo int(50, 50), "input");
151 } 149 }
152 150
153 TEST_F(ImeOnFocusTest, AfterFrameLoadOnGesture) 151 TEST_F(ImeOnFocusTest, AfterFrameLoadOnGesture)
154 { 152 {
155 runImeOnFocusTest("ime-on-focus-after-frame-load-on-gesture.html", 1, IntPoi nt(50, 50), "input", "frame.html"); 153 runImeOnFocusTest("ime-on-focus-after-frame-load-on-gesture.html", 1, IntPoi nt(50, 50), "input", "frame.html");
156 } 154 }
157 155
158 } 156 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/tests/FrameLoaderClientImplTest.cpp ('k') | Source/web/tests/KeyboardTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698