OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/arc/ime/arc_ime_bridge.h" | 10 #include "components/arc/ime/arc_ime_bridge.h" |
11 #include "components/arc/test/fake_arc_bridge_service.h" | 11 #include "components/arc/test/fake_arc_bridge_service.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/base/ime/composition_text.h" | 13 #include "ui/base/ime/composition_text.h" |
| 14 #include "ui/base/ime/dummy_input_method.h" |
14 | 15 |
15 namespace arc { | 16 namespace arc { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 class FakeArcImeIpcHost : public ArcImeIpcHost { | 20 class FakeArcImeIpcHost : public ArcImeIpcHost { |
20 public: | 21 public: |
21 void SendSetCompositionText(const ui::CompositionText& composition) override { | 22 void SendSetCompositionText(const ui::CompositionText& composition) override { |
22 } | 23 } |
23 void SendConfirmCompositionText() override { | 24 void SendConfirmCompositionText() override { |
24 } | 25 } |
25 void SendInsertText(const base::string16& text) override { | 26 void SendInsertText(const base::string16& text) override { |
26 } | 27 } |
27 }; | 28 }; |
28 | 29 |
| 30 class FakeInputMethod : public ui::DummyInputMethod { |
| 31 public: |
| 32 FakeInputMethod() : client_(nullptr), count_show_ime_if_needed_(0) {} |
| 33 |
| 34 void SetFocusedTextInputClient(ui::TextInputClient* client) override { |
| 35 client_ = client; |
| 36 } |
| 37 |
| 38 ui::TextInputClient* GetTextInputClient() const override { |
| 39 return client_; |
| 40 } |
| 41 |
| 42 void ShowImeIfNeeded() override { |
| 43 count_show_ime_if_needed_++; |
| 44 } |
| 45 |
| 46 int count_show_ime_if_needed() const { |
| 47 return count_show_ime_if_needed_; |
| 48 } |
| 49 |
| 50 private: |
| 51 ui::TextInputClient* client_; |
| 52 int count_show_ime_if_needed_; |
| 53 }; |
| 54 |
29 } // namespace | 55 } // namespace |
30 | 56 |
31 class ArcImeBridgeTest : public testing::Test { | 57 class ArcImeBridgeTest : public testing::Test { |
32 public: | 58 public: |
33 ArcImeBridgeTest() {} | 59 ArcImeBridgeTest() {} |
34 | 60 |
35 protected: | 61 protected: |
36 scoped_ptr<FakeArcBridgeService> fake_arc_bridge_service_; | 62 scoped_ptr<FakeArcBridgeService> fake_arc_bridge_service_; |
| 63 scoped_ptr<FakeInputMethod> fake_input_method_; |
37 scoped_ptr<ArcImeBridge> instance_; | 64 scoped_ptr<ArcImeBridge> instance_; |
38 | 65 |
39 private: | 66 private: |
40 void SetUp() override { | 67 void SetUp() override { |
41 fake_arc_bridge_service_.reset(new FakeArcBridgeService); | 68 fake_arc_bridge_service_.reset(new FakeArcBridgeService); |
42 instance_.reset(new ArcImeBridge(fake_arc_bridge_service_.get())); | 69 instance_.reset(new ArcImeBridge(fake_arc_bridge_service_.get())); |
43 instance_->SetIpcHostForTesting(make_scoped_ptr(new FakeArcImeIpcHost)); | 70 instance_->SetIpcHostForTesting(make_scoped_ptr(new FakeArcImeIpcHost)); |
| 71 |
| 72 fake_input_method_.reset(new FakeInputMethod); |
| 73 instance_->SetInputMethodForTesting(fake_input_method_.get()); |
44 } | 74 } |
45 | 75 |
46 void TearDown() override { | 76 void TearDown() override { |
47 instance_.reset(); | 77 instance_.reset(); |
48 fake_arc_bridge_service_.reset(); | 78 fake_arc_bridge_service_.reset(); |
49 } | 79 } |
50 }; | 80 }; |
51 | 81 |
52 TEST_F(ArcImeBridgeTest, HasCompositionText) { | 82 TEST_F(ArcImeBridgeTest, HasCompositionText) { |
53 ui::CompositionText composition; | 83 ui::CompositionText composition; |
(...skipping 15 matching lines...) Expand all Loading... |
69 EXPECT_TRUE(instance_->HasCompositionText()); | 99 EXPECT_TRUE(instance_->HasCompositionText()); |
70 instance_->InsertText(base::UTF8ToUTF16("another text")); | 100 instance_->InsertText(base::UTF8ToUTF16("another text")); |
71 EXPECT_FALSE(instance_->HasCompositionText()); | 101 EXPECT_FALSE(instance_->HasCompositionText()); |
72 | 102 |
73 instance_->SetCompositionText(composition); | 103 instance_->SetCompositionText(composition); |
74 EXPECT_TRUE(instance_->HasCompositionText()); | 104 EXPECT_TRUE(instance_->HasCompositionText()); |
75 instance_->SetCompositionText(ui::CompositionText()); | 105 instance_->SetCompositionText(ui::CompositionText()); |
76 EXPECT_FALSE(instance_->HasCompositionText()); | 106 EXPECT_FALSE(instance_->HasCompositionText()); |
77 } | 107 } |
78 | 108 |
| 109 TEST_F(ArcImeBridgeTest, ShowImeIfNeeded) { |
| 110 fake_input_method_->SetFocusedTextInputClient(instance_.get()); |
| 111 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); |
| 112 ASSERT_EQ(0, fake_input_method_->count_show_ime_if_needed()); |
| 113 |
| 114 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); |
| 115 EXPECT_EQ(1, fake_input_method_->count_show_ime_if_needed()); |
| 116 |
| 117 // The type is not changing, hence no call. |
| 118 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_TEXT); |
| 119 EXPECT_EQ(1, fake_input_method_->count_show_ime_if_needed()); |
| 120 |
| 121 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_SEARCH); |
| 122 EXPECT_EQ(2, fake_input_method_->count_show_ime_if_needed()); |
| 123 |
| 124 // Change to NONE should not trigger the showing event. |
| 125 instance_->OnTextInputTypeChanged(ui::TEXT_INPUT_TYPE_NONE); |
| 126 EXPECT_EQ(2, fake_input_method_->count_show_ime_if_needed()); |
| 127 } |
| 128 |
79 } // namespace arc | 129 } // namespace arc |
OLD | NEW |