OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/app_list/views/speech_view.h" |
| 6 |
| 7 #include "ui/app_list/test/app_list_test_view_delegate.h" |
| 8 #include "ui/views/controls/button/image_button.h" |
| 9 #include "ui/views/test/widget_test.h" |
| 10 |
| 11 namespace app_list { |
| 12 namespace test { |
| 13 |
| 14 class SpeechViewTest : public views::test::WidgetTest, |
| 15 public AppListTestViewDelegate { |
| 16 public: |
| 17 SpeechViewTest() {} |
| 18 virtual ~SpeechViewTest() {} |
| 19 |
| 20 // Overridden from testing::Test: |
| 21 virtual void SetUp() OVERRIDE { |
| 22 views::test::WidgetTest::SetUp(); |
| 23 widget_ = CreateTopLevelPlatformWidget(); |
| 24 widget_->SetBounds(gfx::Rect(0, 0, 300, 200)); |
| 25 view_ = new SpeechView(&view_delegate_); |
| 26 widget_->GetContentsView()->AddChildView(view_); |
| 27 view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds()); |
| 28 } |
| 29 |
| 30 virtual void TearDown() OVERRIDE { |
| 31 widget_->CloseNow(); |
| 32 views::test::WidgetTest::TearDown(); |
| 33 } |
| 34 |
| 35 protected: |
| 36 SpeechView* view() { return view_; } |
| 37 views::Widget* widget() { return widget_; } |
| 38 |
| 39 int GetToggleSpeechRecognitionCountAndReset() { |
| 40 return view_delegate_.GetToggleSpeechRecognitionCountAndReset(); |
| 41 } |
| 42 |
| 43 private: |
| 44 AppListTestViewDelegate view_delegate_; |
| 45 views::Widget* widget_; |
| 46 SpeechView* view_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(SpeechViewTest); |
| 49 }; |
| 50 |
| 51 // Tests that clicking within the circular hit-test mask of MicButton invokes |
| 52 // SpeechView::ToggleSpeechRecognition() and clicking outside of the |
| 53 // hit-test mask does not. |
| 54 TEST_F(SpeechViewTest, ClickMicButton) { |
| 55 EXPECT_EQ(0, GetToggleSpeechRecognitionCountAndReset()); |
| 56 gfx::Rect screen_bounds(view()->mic_button()->GetBoundsInScreen()); |
| 57 |
| 58 // Simulate a mouse click in the center of the MicButton. |
| 59 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, |
| 60 screen_bounds.CenterPoint(), |
| 61 screen_bounds.CenterPoint(), |
| 62 ui::EF_LEFT_MOUSE_BUTTON, |
| 63 0); |
| 64 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, |
| 65 screen_bounds.CenterPoint(), |
| 66 screen_bounds.CenterPoint(), |
| 67 ui::EF_LEFT_MOUSE_BUTTON, |
| 68 0); |
| 69 widget()->OnMouseEvent(&press); |
| 70 widget()->OnMouseEvent(&release); |
| 71 EXPECT_EQ(1, GetToggleSpeechRecognitionCountAndReset()); |
| 72 |
| 73 // Simulate a mouse click in the bottom right-hand corner of the |
| 74 // MicButton's view bounds (which would fall outside of its |
| 75 // circular hit-test mask). |
| 76 gfx::Point bottom_right(screen_bounds.right() - 1, |
| 77 screen_bounds.bottom() - 2); |
| 78 press = ui::MouseEvent(ui::ET_MOUSE_PRESSED, |
| 79 bottom_right, |
| 80 bottom_right, |
| 81 ui::EF_LEFT_MOUSE_BUTTON, |
| 82 0); |
| 83 release = ui::MouseEvent(ui::ET_MOUSE_RELEASED, |
| 84 bottom_right, |
| 85 bottom_right, |
| 86 ui::EF_LEFT_MOUSE_BUTTON, |
| 87 0); |
| 88 widget()->OnMouseEvent(&press); |
| 89 widget()->OnMouseEvent(&release); |
| 90 EXPECT_EQ(0, GetToggleSpeechRecognitionCountAndReset()); |
| 91 } |
| 92 |
| 93 } // namespace test |
| 94 } // namespace app_list |
OLD | NEW |