| OLD | NEW | 
|    1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2008 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/scoped_ptr.h" |    5 #include "base/scoped_ptr.h" | 
|    6 #include "chrome/common/render_messages.h" |    6 #include "chrome/common/render_messages.h" | 
|    7 #include "chrome/renderer/mock_render_process.h" |    7 #include "chrome/renderer/mock_render_process.h" | 
|    8 #include "chrome/renderer/mock_render_thread.h" |    8 #include "chrome/renderer/mock_render_thread.h" | 
|    9 #include "chrome/renderer/render_view.h" |    9 #include "chrome/renderer/render_view.h" | 
|   10 #include "testing/gtest/include/gtest/gtest.h" |   10 #include "testing/gtest/include/gtest/gtest.h" | 
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  123       ViewHostMsg_UpdateState::ID)); |  123       ViewHostMsg_UpdateState::ID)); | 
|  124   render_thread_.sink().ClearMessages(); |  124   render_thread_.sink().ClearMessages(); | 
|  125  |  125  | 
|  126   // Change the value of the input. We should have gotten an update state |  126   // Change the value of the input. We should have gotten an update state | 
|  127   // notification. We need to spin the message loop to catch this update. |  127   // notification. We need to spin the message loop to catch this update. | 
|  128   ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); |  128   ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); | 
|  129   ProcessPendingMessages(); |  129   ProcessPendingMessages(); | 
|  130   EXPECT_TRUE(render_thread_.sink().GetUniqueMessageMatching( |  130   EXPECT_TRUE(render_thread_.sink().GetUniqueMessageMatching( | 
|  131       ViewHostMsg_UpdateState::ID)); |  131       ViewHostMsg_UpdateState::ID)); | 
|  132 } |  132 } | 
 |  133  | 
 |  134 // Test that our IME backend sends a notification message when the input focus | 
 |  135 // changes. | 
 |  136 TEST_F(RenderViewTest, OnImeStateChanged) { | 
 |  137   // Enable our IME backend code. | 
 |  138   view_->OnImeSetInputMode(true); | 
 |  139  | 
 |  140   // Load an HTML page consisting of two input fields. | 
 |  141   view_->set_delay_seconds_for_form_state_sync(0); | 
 |  142   LoadHTML("<html>" | 
 |  143            "<head>" | 
 |  144            "</head>" | 
 |  145            "<body>" | 
 |  146            "<input id=\"test1\" type=\"text\"></input>" | 
 |  147            "<input id=\"test2\" type=\"password\"></input>" | 
 |  148            "</body>" | 
 |  149            "</html>"); | 
 |  150   render_thread_.sink().ClearMessages(); | 
 |  151  | 
 |  152   const int kRepeatCount = 10; | 
 |  153   for (int i = 0; i < kRepeatCount; i++) { | 
 |  154     // Move the input focus to the first <input> element, where we should | 
 |  155     // activate IMEs. | 
 |  156     ExecuteJavaScript("document.getElementById('test1').focus();"); | 
 |  157     ProcessPendingMessages(); | 
 |  158     render_thread_.sink().ClearMessages(); | 
 |  159  | 
 |  160     // Update the IME status and verify if our IME backend sends an IPC message | 
 |  161     // to activate IMEs. | 
 |  162     view_->UpdateIME(); | 
 |  163     const IPC::Message* msg = render_thread_.sink().GetMessageAt(0); | 
 |  164     EXPECT_TRUE(msg != NULL); | 
 |  165     EXPECT_EQ(ViewHostMsg_ImeUpdateStatus::ID, msg->type()); | 
 |  166     ViewHostMsg_ImeUpdateStatus::Param params; | 
 |  167     ViewHostMsg_ImeUpdateStatus::Read(msg, ¶ms); | 
 |  168     EXPECT_EQ(params.a, IME_COMPLETE_COMPOSITION); | 
 |  169     EXPECT_TRUE(params.b.x() > 0 && params.b.y() > 0); | 
 |  170  | 
 |  171     // Move the input focus to the second <input> element, where we should | 
 |  172     // de-activate IMEs. | 
 |  173     ExecuteJavaScript("document.getElementById('test2').focus();"); | 
 |  174     ProcessPendingMessages(); | 
 |  175     render_thread_.sink().ClearMessages(); | 
 |  176  | 
 |  177     // Update the IME status and verify if our IME backend sends an IPC message | 
 |  178     // to de-activate IMEs. | 
 |  179     view_->UpdateIME(); | 
 |  180     msg = render_thread_.sink().GetMessageAt(0); | 
 |  181     EXPECT_TRUE(msg != NULL); | 
 |  182     EXPECT_EQ(ViewHostMsg_ImeUpdateStatus::ID, msg->type()); | 
 |  183     ViewHostMsg_ImeUpdateStatus::Read(msg, ¶ms); | 
 |  184     EXPECT_EQ(params.a, IME_DISABLE); | 
 |  185   } | 
 |  186 } | 
 |  187  | 
| OLD | NEW |