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

Side by Side Diff: content/renderer/render_view_browsertest.cc

Issue 80583002: [FYI] All-in-one OnCandidateWindow{Show,Update,Hide} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 6
7 #include "base/memory/shared_memory.h" 7 #include "base/memory/shared_memory.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 public: 119 public:
120 RenderViewImplTest() { 120 RenderViewImplTest() {
121 // Attach a pseudo keyboard device to this object. 121 // Attach a pseudo keyboard device to this object.
122 mock_keyboard_.reset(new MockKeyboard()); 122 mock_keyboard_.reset(new MockKeyboard());
123 } 123 }
124 124
125 virtual ~RenderViewImplTest() {} 125 virtual ~RenderViewImplTest() {}
126 126
127 virtual void SetUp() OVERRIDE { 127 virtual void SetUp() OVERRIDE {
128 RenderViewTest::SetUp(); 128 RenderViewTest::SetUp();
129 // This test depends on Blink flag InputModeAttribute, which is enabled 129 // Enable Blink's experimental and test only features so that test code
130 // under only test. Content browser test doesn't enable the feature so we 130 // does not have to bother enabling each feature.
131 // need enable it manually. 131 WebRuntimeFeatures::enableExperimentalFeatures(true);
132 // TODO(yoichio): Remove this if InputMode feature is enabled by default. 132 WebRuntimeFeatures::enableTestOnlyFeatures(true);
133 WebRuntimeFeatures::enableInputModeAttribute(true);
134 } 133 }
135 134
136 RenderViewImpl* view() { 135 RenderViewImpl* view() {
137 return static_cast<RenderViewImpl*>(view_); 136 return static_cast<RenderViewImpl*>(view_);
138 } 137 }
139 138
140 // Sends IPC messages that emulates a key-press event. 139 // Sends IPC messages that emulates a key-press event.
141 int SendKeyEvent(MockKeyboard::Layout layout, 140 int SendKeyEvent(MockKeyboard::Layout layout,
142 int key_code, 141 int key_code,
143 MockKeyboard::Modifiers modifiers, 142 MockKeyboard::Modifiers modifiers,
(...skipping 1929 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 view()->OnNavigate(params); 2072 view()->OnNavigate(params);
2074 2073
2075 // An error occurred. 2074 // An error occurred.
2076 view()->didFailProvisionalLoad(web_frame, error); 2075 view()->didFailProvisionalLoad(web_frame, error);
2077 ProcessPendingMessages(); 2076 ProcessPendingMessages();
2078 const int kMaxOutputCharacters = 22; 2077 const int kMaxOutputCharacters = 22;
2079 EXPECT_EQ("A suffusion of yellow.", 2078 EXPECT_EQ("A suffusion of yellow.",
2080 UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters))); 2079 UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters)));
2081 } 2080 }
2082 2081
2082 // Tests if IME API's candidatewindow* events sent from browser are handled
2083 // in renderer.
2084 TEST_F(RenderViewImplTest, SendCandidateWindowEvents) {
2085 // Sends an HTML with an <input> element and scripts to the renderer.
2086 // The script handles all 3 of candidatewindow* events for an
2087 // InputMethodContext object and once it received 'show', 'update', 'hide'
2088 // should appear in the result div.
2089 LoadHTML("<input id='test'>"
2090 "<div id='result'>Result: </div>"
2091 "<script>"
2092 "window.onload = function() {"
2093 " var result = document.getElementById('result');"
2094 " var test = document.getElementById('test');"
2095 " test.focus();"
2096 " var context = test.inputMethodContext;"
2097 " if (context) {"
2098 " context.oncandidatewindowshow = function() {"
2099 " result.innerText += 'show'; };"
2100 " context.oncandidatewindowupdate = function(){"
2101 " result.innerText += 'update'; };"
2102 " context.oncandidatewindowhide = function(){"
2103 " result.innerText += 'hide'; };"
2104 " }"
2105 "};"
2106 "</script>");
2107
2108 // Fire candidatewindow events.
2109 view()->OnCandidateWindowShow();
2110 view()->OnCandidateWindowUpdate();
2111 view()->OnCandidateWindowHide();
2112
2113 // Retrieve the content and check if it is expected.
2114 const int kMaxOutputCharacters = 50;
2115 std::string output = UTF16ToUTF8(
2116 GetMainFrame()->contentAsText(kMaxOutputCharacters));
2117 EXPECT_EQ(output, "\nResult:showupdatehide");
2118 }
2119
2083 } // namespace content 2120 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698