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