OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 "chrome/browser/ui/views/tabs/media_indicator_button.h" | |
6 | |
7 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h" | |
8 #include "chrome/browser/ui/views/tabs/tab.h" | |
9 #include "chrome/browser/ui/views/tabs/tab_strip.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 #include "ui/views/test/views_test_base.h" | |
12 | |
13 class MediaIndicatorButtonTest : public views::ViewsTestBase { | |
14 public: | |
15 MediaIndicatorButtonTest() | |
16 : controller_(nullptr), | |
17 tab_strip_(nullptr) { | |
18 } | |
19 | |
20 ~MediaIndicatorButtonTest() override {} | |
21 | |
22 void SetUp() override { | |
23 views::ViewsTestBase::SetUp(); | |
24 | |
25 controller_ = new FakeBaseTabStripController; | |
26 tab_strip_ = new TabStrip(controller_); | |
27 controller_->set_tab_strip(tab_strip_); | |
28 // The tab strip must be added to the view hierarchy for it to create the | |
29 // buttons. | |
30 parent_.AddChildView(tab_strip_); | |
31 parent_.set_owned_by_client(); | |
32 | |
33 widget_.reset(new views::Widget); | |
34 views::Widget::InitParams init_params = | |
35 CreateParams(views::Widget::InitParams::TYPE_POPUP); | |
36 init_params.ownership = | |
37 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
38 init_params.bounds = gfx::Rect(0, 0, 400, 400); | |
39 widget_->Init(init_params); | |
40 widget_->SetContentsView(&parent_); | |
41 } | |
42 | |
43 void TearDown() override { | |
44 // All windows need to be closed before tear down. | |
45 widget_.reset(); | |
46 | |
47 views::ViewsTestBase::TearDown(); | |
48 } | |
49 | |
50 protected: | |
51 bool showing_close_button(Tab* tab) const { | |
52 return tab->showing_close_button_; | |
53 } | |
54 bool showing_icon(Tab* tab) const { return tab->showing_icon_; } | |
55 bool showing_media_indicator(Tab* tab) const { | |
56 return tab->showing_media_indicator_; | |
57 } | |
58 | |
59 void StopAnimation(Tab* tab) { | |
60 ASSERT_TRUE(tab->media_indicator_button_->fade_animation_); | |
61 tab->media_indicator_button_->fade_animation_->Stop(); | |
62 } | |
63 | |
64 // Owned by TabStrip. | |
65 FakeBaseTabStripController* controller_; | |
66 // Owns |tab_strip_|. | |
67 views::View parent_; | |
68 TabStrip* tab_strip_; | |
69 scoped_ptr<views::Widget> widget_; | |
70 | |
71 private: | |
72 DISALLOW_COPY_AND_ASSIGN(MediaIndicatorButtonTest); | |
73 }; | |
74 | |
75 // This test verifies that the tab has its icon state updated when the media | |
76 // animation fade-out finishes. | |
77 TEST_F(MediaIndicatorButtonTest, ButtonUpdateOnAudioStateAnimation) { | |
78 controller_->AddPinnedTab(0, false); | |
79 controller_->AddTab(1, true); | |
80 Tab* media_tab = tab_strip_->tab_at(0); | |
81 | |
82 // Pinned inactive tab only has an icon. | |
83 EXPECT_TRUE(showing_icon(media_tab)); | |
84 EXPECT_FALSE(showing_media_indicator(media_tab)); | |
85 EXPECT_FALSE(showing_close_button(media_tab)); | |
86 | |
87 TabRendererData start_media; | |
88 start_media.media_state = TAB_MEDIA_STATE_AUDIO_PLAYING; | |
89 media_tab->SetData(start_media); | |
90 | |
91 // When audio starts, pinned inactive tab shows indicator. | |
92 EXPECT_FALSE(showing_icon(media_tab)); | |
93 EXPECT_TRUE(showing_media_indicator(media_tab)); | |
94 EXPECT_FALSE(showing_close_button(media_tab)); | |
95 | |
96 TabRendererData stop_media; | |
97 stop_media.media_state = TAB_MEDIA_STATE_NONE; | |
98 media_tab->SetData(stop_media); | |
99 | |
100 // When audio ends, pinned inactive tab fades out indicator. | |
101 EXPECT_FALSE(showing_icon(media_tab)); | |
102 EXPECT_TRUE(showing_media_indicator(media_tab)); | |
103 EXPECT_FALSE(showing_close_button(media_tab)); | |
104 | |
105 // Rather than flakily waiting some unknown number of seconds for the fade | |
106 // out animation to stop, reach out and stop the fade animation directly, | |
107 // to make sure that it updates the tab appropriately when it's done. | |
108 StopAnimation(media_tab); | |
109 | |
110 EXPECT_TRUE(showing_icon(media_tab)); | |
111 EXPECT_FALSE(showing_media_indicator(media_tab)); | |
112 EXPECT_FALSE(showing_close_button(media_tab)); | |
113 } | |
OLD | NEW |