Make castv2 performance test work.
[chromium-blink-merge.git] / ui / app_list / views / speech_view_unittest.cc
blobde190fb92d07528315f067b42d145f8445d97612
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/events/event_utils.h"
9 #include "ui/views/controls/button/image_button.h"
10 #include "ui/views/test/widget_test.h"
12 namespace app_list {
13 namespace test {
15 class SpeechViewTest : public views::test::WidgetTest,
16 public AppListTestViewDelegate {
17 public:
18 SpeechViewTest() {}
19 ~SpeechViewTest() override {}
21 // Overridden from testing::Test:
22 void SetUp() override {
23 views::test::WidgetTest::SetUp();
24 widget_ = CreateTopLevelPlatformWidget();
25 widget_->SetBounds(gfx::Rect(0, 0, 300, 200));
26 view_ = new SpeechView(&view_delegate_);
27 widget_->GetContentsView()->AddChildView(view_);
28 view_->SetBoundsRect(widget_->GetContentsView()->GetLocalBounds());
31 void TearDown() override {
32 widget_->CloseNow();
33 views::test::WidgetTest::TearDown();
36 protected:
37 SpeechView* view() { return view_; }
38 views::Widget* widget() { return widget_; }
40 int GetToggleSpeechRecognitionCountAndReset() {
41 return view_delegate_.GetToggleSpeechRecognitionCountAndReset();
44 private:
45 AppListTestViewDelegate view_delegate_;
46 views::Widget* widget_;
47 SpeechView* view_;
49 DISALLOW_COPY_AND_ASSIGN(SpeechViewTest);
52 // Tests that clicking within the circular hit-test mask of MicButton invokes
53 // SpeechView::ToggleSpeechRecognition() and clicking outside of the
54 // hit-test mask does not.
55 TEST_F(SpeechViewTest, ClickMicButton) {
56 EXPECT_EQ(0, GetToggleSpeechRecognitionCountAndReset());
57 gfx::Rect screen_bounds(view()->mic_button()->GetBoundsInScreen());
59 // Simulate a mouse click in the center of the MicButton.
60 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(),
61 screen_bounds.CenterPoint(), ui::EventTimeForNow(),
62 ui::EF_LEFT_MOUSE_BUTTON, 0);
63 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, screen_bounds.CenterPoint(),
64 screen_bounds.CenterPoint(), ui::EventTimeForNow(),
65 ui::EF_LEFT_MOUSE_BUTTON, 0);
66 widget()->OnMouseEvent(&press);
67 widget()->OnMouseEvent(&release);
68 EXPECT_EQ(1, GetToggleSpeechRecognitionCountAndReset());
70 // Simulate a mouse click in the bottom right-hand corner of the
71 // MicButton's view bounds (which would fall outside of its
72 // circular hit-test mask).
73 gfx::Point bottom_right(screen_bounds.right() - 1,
74 screen_bounds.bottom() - 2);
75 press = ui::MouseEvent(ui::ET_MOUSE_PRESSED, bottom_right, bottom_right,
76 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
77 release = ui::MouseEvent(ui::ET_MOUSE_RELEASED, bottom_right, bottom_right,
78 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
79 widget()->OnMouseEvent(&press);
80 widget()->OnMouseEvent(&release);
81 EXPECT_EQ(0, GetToggleSpeechRecognitionCountAndReset());
84 } // namespace test
85 } // namespace app_list