| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/ime/candidate_view.h" | 5 #include "ash/ime/candidate_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/events/test/event_generator.h" | 10 #include "ui/events/test/event_generator.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 "candidate2", | 23 "candidate2", |
| 24 "candidate3", | 24 "candidate3", |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 class CandidateViewTest : public views::ViewsTestBase, | 29 class CandidateViewTest : public views::ViewsTestBase, |
| 30 public views::ButtonListener { | 30 public views::ButtonListener { |
| 31 public: | 31 public: |
| 32 CandidateViewTest() : widget_(NULL), last_pressed_(NULL) {} | 32 CandidateViewTest() : widget_(NULL), last_pressed_(NULL) {} |
| 33 virtual ~CandidateViewTest() {} | 33 ~CandidateViewTest() override {} |
| 34 | 34 |
| 35 virtual void SetUp() override { | 35 void SetUp() override { |
| 36 views::ViewsTestBase::SetUp(); | 36 views::ViewsTestBase::SetUp(); |
| 37 | 37 |
| 38 views::Widget::InitParams init_params(CreateParams( | 38 views::Widget::InitParams init_params(CreateParams( |
| 39 views::Widget::InitParams::TYPE_WINDOW)); | 39 views::Widget::InitParams::TYPE_WINDOW)); |
| 40 | 40 |
| 41 init_params.delegate = new views::WidgetDelegateView(); | 41 init_params.delegate = new views::WidgetDelegateView(); |
| 42 | 42 |
| 43 container_ = init_params.delegate->GetContentsView(); | 43 container_ = init_params.delegate->GetContentsView(); |
| 44 container_->SetLayoutManager( | 44 container_->SetLayoutManager( |
| 45 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 45 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 46 for (size_t i = 0; i < arraysize(kDummyCandidates); ++i) { | 46 for (size_t i = 0; i < arraysize(kDummyCandidates); ++i) { |
| 47 CandidateView* candidate = new CandidateView( | 47 CandidateView* candidate = new CandidateView( |
| 48 this, ui::CandidateWindow::VERTICAL); | 48 this, ui::CandidateWindow::VERTICAL); |
| 49 ui::CandidateWindow::Entry entry; | 49 ui::CandidateWindow::Entry entry; |
| 50 entry.value = base::UTF8ToUTF16(kDummyCandidates[i]); | 50 entry.value = base::UTF8ToUTF16(kDummyCandidates[i]); |
| 51 candidate->SetEntry(entry); | 51 candidate->SetEntry(entry); |
| 52 container_->AddChildView(candidate); | 52 container_->AddChildView(candidate); |
| 53 } | 53 } |
| 54 | 54 |
| 55 widget_ = new views::Widget(); | 55 widget_ = new views::Widget(); |
| 56 widget_->Init(init_params); | 56 widget_->Init(init_params); |
| 57 widget_->Show(); | 57 widget_->Show(); |
| 58 | 58 |
| 59 aura::Window* native_window = widget_->GetNativeWindow(); | 59 aura::Window* native_window = widget_->GetNativeWindow(); |
| 60 event_generator_.reset(new ui::test::EventGenerator( | 60 event_generator_.reset(new ui::test::EventGenerator( |
| 61 native_window->GetRootWindow(), native_window)); | 61 native_window->GetRootWindow(), native_window)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void TearDown() override { | 64 void TearDown() override { |
| 65 widget_->Close(); | 65 widget_->Close(); |
| 66 | 66 |
| 67 views::ViewsTestBase::TearDown(); | 67 views::ViewsTestBase::TearDown(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 protected: | 70 protected: |
| 71 CandidateView* GetCandidateAt(int index) { | 71 CandidateView* GetCandidateAt(int index) { |
| 72 return static_cast<CandidateView*>(container_->child_at(index)); | 72 return static_cast<CandidateView*>(container_->child_at(index)); |
| 73 } | 73 } |
| 74 | 74 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 DCHECK(last_pressed_ == NULL); | 95 DCHECK(last_pressed_ == NULL); |
| 96 last_pressed_ = NULL; | 96 last_pressed_ = NULL; |
| 97 return -1; | 97 return -1; |
| 98 } | 98 } |
| 99 | 99 |
| 100 ui::test::EventGenerator* event_generator() { return event_generator_.get(); } | 100 ui::test::EventGenerator* event_generator() { return event_generator_.get(); } |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 virtual void ButtonPressed(views::Button* sender, | 103 void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| 104 const ui::Event& event) override { | |
| 105 last_pressed_ = sender; | 104 last_pressed_ = sender; |
| 106 } | 105 } |
| 107 | 106 |
| 108 views::Widget* widget_; | 107 views::Widget* widget_; |
| 109 views::View* container_; | 108 views::View* container_; |
| 110 scoped_ptr<ui::test::EventGenerator> event_generator_; | 109 scoped_ptr<ui::test::EventGenerator> event_generator_; |
| 111 views::View* last_pressed_; | 110 views::View* last_pressed_; |
| 112 | 111 |
| 113 DISALLOW_COPY_AND_ASSIGN(CandidateViewTest); | 112 DISALLOW_COPY_AND_ASSIGN(CandidateViewTest); |
| 114 }; | 113 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 GetCandidateAt(1)->GetBoundsInScreen().CenterPoint()); | 173 GetCandidateAt(1)->GetBoundsInScreen().CenterPoint()); |
| 175 EXPECT_EQ(1, GetHighlightedIndex(&highlighted_count)); | 174 EXPECT_EQ(1, GetHighlightedIndex(&highlighted_count)); |
| 176 EXPECT_EQ(1, highlighted_count); | 175 EXPECT_EQ(1, highlighted_count); |
| 177 | 176 |
| 178 event_generator()->ReleaseLeftButton(); | 177 event_generator()->ReleaseLeftButton(); |
| 179 EXPECT_EQ(1, GetLastPressedIndexAndReset()); | 178 EXPECT_EQ(1, GetLastPressedIndexAndReset()); |
| 180 } | 179 } |
| 181 | 180 |
| 182 } // namespace ime | 181 } // namespace ime |
| 183 } // namespace ash | 182 } // namespace ash |
| OLD | NEW |