OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 8 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
9 #include "chrome/browser/chromeos/input_method/mode_indicator_controller.h" | 9 #include "chrome/browser/chromeos/input_method/mode_indicator_controller.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace input_method { | 24 namespace input_method { |
25 | 25 |
26 class ScopedModeIndicatorObserverForTesting : | 26 class ScopedModeIndicatorObserverForTesting : |
27 public ModeIndicatorObserverInterface { | 27 public ModeIndicatorObserverInterface { |
28 public: | 28 public: |
29 ScopedModeIndicatorObserverForTesting() | 29 ScopedModeIndicatorObserverForTesting() |
30 : max_widget_list_size_(0) { | 30 : max_widget_list_size_(0) { |
31 ModeIndicatorController::SetModeIndicatorObserverForTesting(this); | 31 ModeIndicatorController::SetModeIndicatorObserverForTesting(this); |
32 } | 32 } |
33 | 33 |
34 virtual ~ScopedModeIndicatorObserverForTesting() { | 34 ~ScopedModeIndicatorObserverForTesting() override { |
35 for (size_t i = 0; i < widget_list_.size(); ++i) { | 35 for (size_t i = 0; i < widget_list_.size(); ++i) { |
36 widget_list_[i]->RemoveObserver(this); | 36 widget_list_[i]->RemoveObserver(this); |
37 } | 37 } |
38 ModeIndicatorController::SetModeIndicatorObserverForTesting(NULL); | 38 ModeIndicatorController::SetModeIndicatorObserverForTesting(NULL); |
39 } | 39 } |
40 | 40 |
41 gfx::Rect last_bounds() const { | 41 gfx::Rect last_bounds() const { |
42 return last_bounds_; | 42 return last_bounds_; |
43 } | 43 } |
44 | 44 |
45 bool is_displayed() const { | 45 bool is_displayed() const { |
46 return is_displayed_; | 46 return is_displayed_; |
47 } | 47 } |
48 | 48 |
49 const std::vector<views::Widget*>& widget_list() const { | 49 const std::vector<views::Widget*>& widget_list() const { |
50 return widget_list_; | 50 return widget_list_; |
51 } | 51 } |
52 | 52 |
53 size_t widget_list_size() const { | 53 size_t widget_list_size() const { |
54 return widget_list_.size(); | 54 return widget_list_.size(); |
55 } | 55 } |
56 | 56 |
57 size_t max_widget_list_size() const { | 57 size_t max_widget_list_size() const { |
58 return max_widget_list_size_; | 58 return max_widget_list_size_; |
59 } | 59 } |
60 | 60 |
61 // ModeIndicatorObserverInterface override: | 61 // ModeIndicatorObserverInterface override: |
62 virtual void AddModeIndicatorWidget(views::Widget* widget) override { | 62 void AddModeIndicatorWidget(views::Widget* widget) override { |
63 widget_list_.push_back(widget); | 63 widget_list_.push_back(widget); |
64 max_widget_list_size_ = | 64 max_widget_list_size_ = |
65 std::max(max_widget_list_size_, widget_list_.size()); | 65 std::max(max_widget_list_size_, widget_list_.size()); |
66 widget->AddObserver(this); | 66 widget->AddObserver(this); |
67 } | 67 } |
68 | 68 |
69 // views::WidgetObserver override: | 69 // views::WidgetObserver override: |
70 virtual void OnWidgetDestroying(views::Widget* widget) override { | 70 void OnWidgetDestroying(views::Widget* widget) override { |
71 std::vector<views::Widget*>::iterator it = | 71 std::vector<views::Widget*>::iterator it = |
72 std::find(widget_list_.begin(), widget_list_.end(), widget); | 72 std::find(widget_list_.begin(), widget_list_.end(), widget); |
73 if (it != widget_list_.end()) | 73 if (it != widget_list_.end()) |
74 widget_list_.erase(it); | 74 widget_list_.erase(it); |
75 } | 75 } |
76 | 76 |
77 // views::WidgetObserver override: | 77 // views::WidgetObserver override: |
78 virtual void OnWidgetVisibilityChanged(views::Widget* widget, | 78 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override { |
79 bool visible) override { | |
80 last_bounds_ = widget->GetWindowBoundsInScreen(); | 79 last_bounds_ = widget->GetWindowBoundsInScreen(); |
81 is_displayed_ |= visible; | 80 is_displayed_ |= visible; |
82 } | 81 } |
83 | 82 |
84 private: | 83 private: |
85 bool is_displayed_; | 84 bool is_displayed_; |
86 gfx::Rect last_bounds_; | 85 gfx::Rect last_bounds_; |
87 size_t max_widget_list_size_; | 86 size_t max_widget_list_size_; |
88 std::vector<views::Widget*> widget_list_; | 87 std::vector<views::Widget*> widget_list_; |
89 }; | 88 }; |
90 | 89 |
91 class ModeIndicatorBrowserTest : public InProcessBrowserTest { | 90 class ModeIndicatorBrowserTest : public InProcessBrowserTest { |
92 public: | 91 public: |
93 ModeIndicatorBrowserTest() | 92 ModeIndicatorBrowserTest() |
94 : InProcessBrowserTest() {} | 93 : InProcessBrowserTest() {} |
95 virtual ~ModeIndicatorBrowserTest() {} | 94 ~ModeIndicatorBrowserTest() override {} |
96 | 95 |
97 virtual void SetUpInProcessBrowserTestFixture() override { | 96 void SetUpInProcessBrowserTestFixture() override { |
98 ui::SetUpInputMethodFactoryForTesting(); | 97 ui::SetUpInputMethodFactoryForTesting(); |
99 } | 98 } |
100 | 99 |
101 void InitializeIMF() { | 100 void InitializeIMF() { |
102 InputMethodManager::Get() | 101 InputMethodManager::Get() |
103 ->GetInputMethodUtil() | 102 ->GetInputMethodUtil() |
104 ->InitXkbInputMethodsForTesting(); | 103 ->InitXkbInputMethodsForTesting(); |
105 } | 104 } |
106 | 105 |
107 private: | 106 private: |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // When a new mode indicator is displayed, the previous one should be | 215 // When a new mode indicator is displayed, the previous one should be |
217 // closed. | 216 // closed. |
218 content::RunAllPendingInMessageLoop(); | 217 content::RunAllPendingInMessageLoop(); |
219 EXPECT_EQ(1UL, observer.widget_list_size()); | 218 EXPECT_EQ(1UL, observer.widget_list_size()); |
220 const views::Widget* widget2 = observer.widget_list()[0]; | 219 const views::Widget* widget2 = observer.widget_list()[0]; |
221 EXPECT_NE(widget1, widget2); | 220 EXPECT_NE(widget1, widget2); |
222 } | 221 } |
223 } | 222 } |
224 } // namespace input_method | 223 } // namespace input_method |
225 } // namespace chromeos | 224 } // namespace chromeos |
OLD | NEW |