Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
|
sky
2016/02/03 22:02:13
nit: no (c)
enne (OOO)
2016/02/03 22:13:18
Done. Thanks!
| |
| 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 // Do this to force TabStrip to create the buttons. | |
| 29 parent_.AddChildView(tab_strip_); | |
| 30 parent_.set_owned_by_client(); | |
| 31 | |
| 32 widget_.reset(new views::Widget); | |
| 33 views::Widget::InitParams init_params = | |
| 34 CreateParams(views::Widget::InitParams::TYPE_POPUP); | |
| 35 init_params.ownership = | |
| 36 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 37 init_params.bounds = gfx::Rect(0, 0, 400, 400); | |
| 38 widget_->Init(init_params); | |
| 39 widget_->SetContentsView(&parent_); | |
| 40 } | |
| 41 | |
| 42 void TearDown() override { | |
| 43 widget_.reset(); | |
| 44 views::ViewsTestBase::TearDown(); | |
| 45 } | |
| 46 | |
| 47 protected: | |
| 48 bool ShowingCloseButton(Tab* tab) const { return tab->showing_close_button_; } | |
| 49 bool ShowingIcon(Tab* tab) const { return tab->showing_icon_; } | |
| 50 bool ShowingMediaIndicator(Tab* tab) const { | |
| 51 return tab->showing_media_indicator_; | |
| 52 } | |
| 53 void StopAnimation(Tab* tab) { | |
| 54 ASSERT_TRUE(tab->media_indicator_button_->fade_animation_); | |
| 55 tab->media_indicator_button_->fade_animation_->Stop(); | |
| 56 } | |
| 57 | |
| 58 // Owned by TabStrip. | |
| 59 FakeBaseTabStripController* controller_; | |
| 60 // Owns |tab_strip_|. | |
| 61 views::View parent_; | |
| 62 TabStrip* tab_strip_; | |
| 63 scoped_ptr<views::Widget> widget_; | |
| 64 | |
| 65 private: | |
| 66 DISALLOW_COPY_AND_ASSIGN(MediaIndicatorButtonTest); | |
| 67 }; | |
| 68 | |
| 69 // This test verifies that the tab has its icon state updated when the media | |
| 70 // animation fade-out finishes. | |
| 71 TEST_F(MediaIndicatorButtonTest, ButtonUpdateOnAudioStateAnimation) { | |
| 72 controller_->AddPinnedTab(0, false); | |
| 73 controller_->AddTab(1, true); | |
| 74 Tab* media_tab = tab_strip_->tab_at(0); | |
| 75 | |
| 76 // Pinned inactive tab only has an icon. | |
| 77 EXPECT_TRUE(ShowingIcon(media_tab)); | |
| 78 EXPECT_FALSE(ShowingMediaIndicator(media_tab)); | |
| 79 EXPECT_FALSE(ShowingCloseButton(media_tab)); | |
| 80 | |
| 81 TabRendererData start_media; | |
| 82 start_media.media_state = TAB_MEDIA_STATE_AUDIO_PLAYING; | |
| 83 media_tab->SetData(start_media); | |
| 84 | |
| 85 // When audio starts, pinned inactive tab shows indicator. | |
| 86 EXPECT_FALSE(ShowingIcon(media_tab)); | |
| 87 EXPECT_TRUE(ShowingMediaIndicator(media_tab)); | |
| 88 EXPECT_FALSE(ShowingCloseButton(media_tab)); | |
| 89 | |
| 90 TabRendererData stop_media; | |
| 91 start_media.media_state = TAB_MEDIA_STATE_NONE; | |
| 92 media_tab->SetData(start_media); | |
| 93 | |
| 94 // When audio ends, pinned inactive tab fades out indicator. | |
| 95 EXPECT_FALSE(ShowingIcon(media_tab)); | |
| 96 EXPECT_TRUE(ShowingMediaIndicator(media_tab)); | |
| 97 EXPECT_FALSE(ShowingCloseButton(media_tab)); | |
| 98 | |
| 99 // Rather than flakily waiting some unknown number of seconds for the fade | |
| 100 // out animation to stop, reach out and stop the fade animation directly, | |
| 101 // to make sure that it updates the tab appropriately when it's done. | |
| 102 StopAnimation(media_tab); | |
| 103 | |
| 104 EXPECT_TRUE(ShowingIcon(media_tab)); | |
| 105 EXPECT_FALSE(ShowingMediaIndicator(media_tab)); | |
| 106 EXPECT_FALSE(ShowingCloseButton(media_tab)); | |
| 107 } | |
| OLD | NEW |