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

Side by Side Diff: ui/aura/mus/input_method_mus_unittest.cc

Issue 2685183005: Makes ~InputMethodMus ack any in flight events (Closed)
Patch Set: null Created 3 years, 10 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
« no previous file with comments | « ui/aura/mus/input_method_mus.cc ('k') | ui/aura/mus/os_exchange_data_provider_mus_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/aura/mus/input_method_mus.h"
6
7 #include "services/ui/public/interfaces/ime/ime.mojom.h"
8 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/window.h"
10 #include "ui/base/ime/input_method_delegate.h"
11
12 namespace aura {
13 namespace {
14
15 // Empty implementation of InputMethodDelegate.
16 class TestInputMethodDelegate : public ui::internal::InputMethodDelegate {
17 public:
18 TestInputMethodDelegate() {}
19 ~TestInputMethodDelegate() override {}
20
21 // ui::internal::InputMethodDelegate:
22 ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override {
23 return ui::EventDispatchDetails();
24 }
25
26 private:
27 DISALLOW_COPY_AND_ASSIGN(TestInputMethodDelegate);
28 };
29
30 using ProcessKeyEventCallback = base::Callback<void(bool)>;
31 using ProcessKeyEventCallbacks = std::vector<ProcessKeyEventCallback>;
32 using EventResultCallback = base::Callback<void(ui::mojom::EventResult)>;
33
34 // InputMethod implementation that queues up the callbacks supplied to
35 // ProcessKeyEvent().
36 class TestInputMethod : public ui::mojom::InputMethod {
37 public:
38 TestInputMethod() {}
39 ~TestInputMethod() override {}
40
41 ProcessKeyEventCallbacks* process_key_event_callbacks() {
42 return &process_key_event_callbacks_;
43 }
44
45 // ui::ime::InputMethod:
46 void OnTextInputTypeChanged(ui::TextInputType text_input_type) override {}
47 void OnCaretBoundsChanged(const gfx::Rect& caret_bounds) override {}
48 void ProcessKeyEvent(std::unique_ptr<ui::Event> key_event,
49 const ProcessKeyEventCallback& callback) override {
50 process_key_event_callbacks_.push_back(callback);
51 }
52 void CancelComposition() override {}
53
54 private:
55 ProcessKeyEventCallbacks process_key_event_callbacks_;
56
57 DISALLOW_COPY_AND_ASSIGN(TestInputMethod);
58 };
59
60 } // namespace
61
62 using InputMethodMusTest = test::AuraTestBaseMus;
63
64 class InputMethodMusTestApi {
65 public:
66 static void SetInputMethod(InputMethodMus* input_method_mus,
67 ui::mojom::InputMethod* input_method) {
68 input_method_mus->input_method_ = input_method;
69 }
70 static void CallSendKeyEventToInputMethod(
71 InputMethodMus* input_method_mus,
72 const ui::KeyEvent& event,
73 std::unique_ptr<EventResultCallback> ack_callback) {
74 input_method_mus->SendKeyEventToInputMethod(event, std::move(ack_callback));
75 }
76
77 private:
78 DISALLOW_IMPLICIT_CONSTRUCTORS(InputMethodMusTestApi);
79 };
80
81 namespace {
82
83 // Used in closure supplied to processing the event.
84 void RunFunctionWithEventResult(bool* was_run, ui::mojom::EventResult result) {
85 *was_run = true;
86 }
87
88 } // namespace
89
90 TEST_F(InputMethodMusTest, PendingCallbackRunFromDestruction) {
91 aura::Window window(nullptr);
92 window.Init(ui::LAYER_NOT_DRAWN);
93 bool was_event_result_callback_run = false;
94 // Create an InputMethodMus and foward an event to it.
95 {
96 TestInputMethodDelegate input_method_delegate;
97 InputMethodMus input_method_mus(&input_method_delegate, &window);
98 TestInputMethod test_input_method;
99 InputMethodMusTestApi::SetInputMethod(&input_method_mus,
100 &test_input_method);
101 std::unique_ptr<EventResultCallback> callback =
102 base::MakeUnique<EventResultCallback>(base::Bind(
103 &RunFunctionWithEventResult, &was_event_result_callback_run));
104 InputMethodMusTestApi::CallSendKeyEventToInputMethod(
105 &input_method_mus, ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0),
106 std::move(callback));
107 // Add a null callback as well, to make sure null is deal with.
108 InputMethodMusTestApi::CallSendKeyEventToInputMethod(
109 &input_method_mus, ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, 0),
110 nullptr);
111 // The event should have been queued.
112 EXPECT_EQ(2u, test_input_method.process_key_event_callbacks()->size());
113 // Callback should not have been run yet.
114 EXPECT_FALSE(was_event_result_callback_run);
115 }
116
117 // When the destructor is run the callback should be run.
118 EXPECT_TRUE(was_event_result_callback_run);
119 }
120
121 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/input_method_mus.cc ('k') | ui/aura/mus/os_exchange_data_provider_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698