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.
5 #include "ui/app_list/views/speech_view.h"
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"
14 class SpeechViewTest
: public views::test::WidgetTest
,
15 public AppListTestViewDelegate
{
18 virtual ~SpeechViewTest() {}
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());
30 virtual void TearDown() OVERRIDE
{
32 views::test::WidgetTest::TearDown();
36 SpeechView
* view() { return view_
; }
37 views::Widget
* widget() { return widget_
; }
39 int GetToggleSpeechRecognitionCountAndReset() {
40 return view_delegate_
.GetToggleSpeechRecognitionCountAndReset();
44 AppListTestViewDelegate view_delegate_
;
45 views::Widget
* widget_
;
48 DISALLOW_COPY_AND_ASSIGN(SpeechViewTest
);
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());
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
,
64 ui::MouseEvent
release(ui::ET_MOUSE_RELEASED
,
65 screen_bounds
.CenterPoint(),
66 screen_bounds
.CenterPoint(),
67 ui::EF_LEFT_MOUSE_BUTTON
,
69 widget()->OnMouseEvent(&press
);
70 widget()->OnMouseEvent(&release
);
71 EXPECT_EQ(1, GetToggleSpeechRecognitionCountAndReset());
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
,
81 ui::EF_LEFT_MOUSE_BUTTON
,
83 release
= ui::MouseEvent(ui::ET_MOUSE_RELEASED
,
86 ui::EF_LEFT_MOUSE_BUTTON
,
88 widget()->OnMouseEvent(&press
);
89 widget()->OnMouseEvent(&release
);
90 EXPECT_EQ(0, GetToggleSpeechRecognitionCountAndReset());
94 } // namespace app_list