| OLD | NEW |
| 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 "ppapi/tests/test_ime_input_event.h" | 5 #include "ppapi/tests/test_ime_input_event.h" |
| 6 | 6 |
| 7 #include "ppapi/c/dev/ppb_ime_input_event_dev.h" | |
| 8 #include "ppapi/c/dev/ppb_testing_dev.h" | 7 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 9 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/c/ppb_ime_input_event.h" |
| 10 #include "ppapi/c/ppb_input_event.h" | 10 #include "ppapi/c/ppb_input_event.h" |
| 11 #include "ppapi/cpp/dev/ime_input_event_dev.h" | 11 #include "ppapi/cpp/ime_input_event.h" |
| 12 #include "ppapi/cpp/input_event.h" | 12 #include "ppapi/cpp/input_event.h" |
| 13 #include "ppapi/cpp/module.h" | 13 #include "ppapi/cpp/module.h" |
| 14 #include "ppapi/tests/test_utils.h" | 14 #include "ppapi/tests/test_utils.h" |
| 15 #include "ppapi/tests/testing_instance.h" | 15 #include "ppapi/tests/testing_instance.h" |
| 16 | 16 |
| 17 REGISTER_TEST_CASE(ImeInputEvent); | 17 REGISTER_TEST_CASE(ImeInputEvent); |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Japanese Kanji letters meaning "a string" ('mo' 'ji' 'retsu' in Kanji) | 21 // Japanese Kanji letters meaning "a string" ('mo' 'ji' 'retsu' in Kanji) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 RUN_TEST(ImeUnawareCancel, filter); | 56 RUN_TEST(ImeUnawareCancel, filter); |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool TestImeInputEvent::Init() { | 59 bool TestImeInputEvent::Init() { |
| 60 input_event_interface_ = static_cast<const PPB_InputEvent*>( | 60 input_event_interface_ = static_cast<const PPB_InputEvent*>( |
| 61 pp::Module::Get()->GetBrowserInterface(PPB_INPUT_EVENT_INTERFACE)); | 61 pp::Module::Get()->GetBrowserInterface(PPB_INPUT_EVENT_INTERFACE)); |
| 62 keyboard_input_event_interface_ = | 62 keyboard_input_event_interface_ = |
| 63 static_cast<const PPB_KeyboardInputEvent*>( | 63 static_cast<const PPB_KeyboardInputEvent*>( |
| 64 pp::Module::Get()->GetBrowserInterface( | 64 pp::Module::Get()->GetBrowserInterface( |
| 65 PPB_KEYBOARD_INPUT_EVENT_INTERFACE)); | 65 PPB_KEYBOARD_INPUT_EVENT_INTERFACE)); |
| 66 ime_input_event_interface_ = static_cast<const PPB_IMEInputEvent_Dev*>( | 66 ime_input_event_interface_ = static_cast<const PPB_IMEInputEvent*>( |
| 67 pp::Module::Get()->GetBrowserInterface( | 67 pp::Module::Get()->GetBrowserInterface( |
| 68 PPB_IME_INPUT_EVENT_DEV_INTERFACE)); | 68 PPB_IME_INPUT_EVENT_INTERFACE)); |
| 69 | 69 |
| 70 bool success = | 70 bool success = |
| 71 input_event_interface_ && | 71 input_event_interface_ && |
| 72 keyboard_input_event_interface_ && | 72 keyboard_input_event_interface_ && |
| 73 ime_input_event_interface_ && | 73 ime_input_event_interface_ && |
| 74 CheckTestingInterface(); | 74 CheckTestingInterface(); |
| 75 | 75 |
| 76 // Set up a listener for our message that signals that all input events have | 76 // Set up a listener for our message that signals that all input events have |
| 77 // been received. | 77 // been received. |
| 78 // Note the following code is dependent on some features of test_case.html. | 78 // Note the following code is dependent on some features of test_case.html. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 testing_interface_->QuitMessageLoop(instance_->pp_instance()); | 129 testing_interface_->QuitMessageLoop(instance_->pp_instance()); |
| 130 received_finish_message_ = true; | 130 received_finish_message_ = true; |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 void TestImeInputEvent::DidChangeView(const pp::View& view) { | 134 void TestImeInputEvent::DidChangeView(const pp::View& view) { |
| 135 view_rect_ = view.GetRect(); | 135 view_rect_ = view.GetRect(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 pp::InputEvent TestImeInputEvent::CreateImeCompositionStartEvent() { | 138 pp::InputEvent TestImeInputEvent::CreateImeCompositionStartEvent() { |
| 139 return pp::IMEInputEvent_Dev( | 139 return pp::IMEInputEvent( |
| 140 instance_, | 140 instance_, |
| 141 PP_INPUTEVENT_TYPE_IME_COMPOSITION_START, | 141 PP_INPUTEVENT_TYPE_IME_COMPOSITION_START, |
| 142 100, // time_stamp | 142 100, // time_stamp |
| 143 pp::Var(""), | 143 pp::Var(""), |
| 144 std::vector<uint32_t>(), | 144 std::vector<uint32_t>(), |
| 145 -1, // target_segment | 145 -1, // target_segment |
| 146 std::make_pair(0U, 0U) // selection | 146 std::make_pair(0U, 0U) // selection |
| 147 ); | 147 ); |
| 148 } | 148 } |
| 149 | 149 |
| 150 pp::InputEvent TestImeInputEvent::CreateImeCompositionUpdateEvent( | 150 pp::InputEvent TestImeInputEvent::CreateImeCompositionUpdateEvent( |
| 151 const std::string& text, | 151 const std::string& text, |
| 152 const std::vector<uint32_t>& segments, | 152 const std::vector<uint32_t>& segments, |
| 153 int32_t target_segment, | 153 int32_t target_segment, |
| 154 const std::pair<uint32_t, uint32_t>& selection) { | 154 const std::pair<uint32_t, uint32_t>& selection) { |
| 155 return pp::IMEInputEvent_Dev( | 155 return pp::IMEInputEvent( |
| 156 instance_, | 156 instance_, |
| 157 PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE, | 157 PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE, |
| 158 100, // time_stamp | 158 100, // time_stamp |
| 159 text, | 159 text, |
| 160 segments, | 160 segments, |
| 161 target_segment, | 161 target_segment, |
| 162 selection | 162 selection |
| 163 ); | 163 ); |
| 164 } | 164 } |
| 165 | 165 |
| 166 pp::InputEvent TestImeInputEvent::CreateImeCompositionEndEvent( | 166 pp::InputEvent TestImeInputEvent::CreateImeCompositionEndEvent( |
| 167 const std::string& text) { | 167 const std::string& text) { |
| 168 return pp::IMEInputEvent_Dev( | 168 return pp::IMEInputEvent( |
| 169 instance_, | 169 instance_, |
| 170 PP_INPUTEVENT_TYPE_IME_COMPOSITION_END, | 170 PP_INPUTEVENT_TYPE_IME_COMPOSITION_END, |
| 171 100, // time_stamp | 171 100, // time_stamp |
| 172 pp::Var(text), | 172 pp::Var(text), |
| 173 std::vector<uint32_t>(), | 173 std::vector<uint32_t>(), |
| 174 -1, // target_segment | 174 -1, // target_segment |
| 175 std::make_pair(0U, 0U) // selection | 175 std::make_pair(0U, 0U) // selection |
| 176 ); | 176 ); |
| 177 } | 177 } |
| 178 | 178 |
| 179 pp::InputEvent TestImeInputEvent::CreateImeTextEvent(const std::string& text) { | 179 pp::InputEvent TestImeInputEvent::CreateImeTextEvent(const std::string& text) { |
| 180 return pp::IMEInputEvent_Dev( | 180 return pp::IMEInputEvent( |
| 181 instance_, | 181 instance_, |
| 182 PP_INPUTEVENT_TYPE_IME_TEXT, | 182 PP_INPUTEVENT_TYPE_IME_TEXT, |
| 183 100, // time_stamp | 183 100, // time_stamp |
| 184 pp::Var(text), | 184 pp::Var(text), |
| 185 std::vector<uint32_t>(), | 185 std::vector<uint32_t>(), |
| 186 -1, // target_segment | 186 -1, // target_segment |
| 187 std::make_pair(0U, 0U) // selection | 187 std::make_pair(0U, 0U) // selection |
| 188 ); | 188 ); |
| 189 } | 189 } |
| 190 | 190 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // For COMPOSITION_END and TEXT, GetText() has meaning. | 253 // For COMPOSITION_END and TEXT, GetText() has meaning. |
| 254 return pp::Var(pp::PASS_REF, | 254 return pp::Var(pp::PASS_REF, |
| 255 ime_input_event_interface_->GetText(received)) == | 255 ime_input_event_interface_->GetText(received)) == |
| 256 pp::Var(pp::PASS_REF, | 256 pp::Var(pp::PASS_REF, |
| 257 ime_input_event_interface_->GetText(expected)); | 257 ime_input_event_interface_->GetText(expected)); |
| 258 | 258 |
| 259 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE: | 259 case PP_INPUTEVENT_TYPE_IME_COMPOSITION_UPDATE: |
| 260 // For COMPOSITION_UPDATE, all fields must be checked. | 260 // For COMPOSITION_UPDATE, all fields must be checked. |
| 261 { | 261 { |
| 262 uint32_t received_segment_number = | 262 uint32_t received_segment_number = |
| 263 ime_input_event_interface_->GetSegmentNumber(received); | 263 ime_input_event_interface_->GetSegmentCount(received); |
| 264 uint32_t expected_segment_number = | 264 uint32_t expected_segment_number = |
| 265 ime_input_event_interface_->GetSegmentNumber(expected); | 265 ime_input_event_interface_->GetSegmentCount(expected); |
| 266 if (received_segment_number != expected_segment_number) | 266 if (received_segment_number != expected_segment_number) |
| 267 return false; | 267 return false; |
| 268 | 268 |
| 269 // The "<=" is not a bug. i-th segment is represented as the pair of | 269 // The "<=" is not a bug. i-th segment is represented as the pair of |
| 270 // i-th and (i+1)-th offsets in Pepper IME API. | 270 // i-th and (i+1)-th offsets in Pepper IME API. |
| 271 for (uint32_t i = 0; i <= received_segment_number; ++i) { | 271 for (uint32_t i = 0; i <= received_segment_number; ++i) { |
| 272 if (ime_input_event_interface_->GetSegmentOffset(received, i) != | 272 if (ime_input_event_interface_->GetSegmentOffset(received, i) != |
| 273 ime_input_event_interface_->GetSegmentOffset(expected, i)) | 273 ime_input_event_interface_->GetSegmentOffset(expected, i)) |
| 274 return false; | 274 return false; |
| 275 } | 275 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 expected_events_.clear(); | 416 expected_events_.clear(); |
| 417 | 417 |
| 418 // Test for IME-unaware plugins. Cancel won't issue any events. | 418 // Test for IME-unaware plugins. Cancel won't issue any events. |
| 419 ASSERT_TRUE(SimulateInputEvent(update_event)); | 419 ASSERT_TRUE(SimulateInputEvent(update_event)); |
| 420 ASSERT_TRUE(SimulateInputEvent(CreateImeCompositionEndEvent(std::string()))); | 420 ASSERT_TRUE(SimulateInputEvent(CreateImeCompositionEndEvent(std::string()))); |
| 421 | 421 |
| 422 ASSERT_TRUE(expected_events_.empty()); | 422 ASSERT_TRUE(expected_events_.empty()); |
| 423 PASS(); | 423 PASS(); |
| 424 } | 424 } |
| 425 | 425 |
| OLD | NEW |