Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(957)

Unified Diff: chrome/browser/ui/views/tabs/media_indicator_button_unittest.cc

Issue 1653113002: Fix favicon disappearing on pinned tabs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix copyright; fix variable names Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/tabs/media_indicator_button.cc ('k') | chrome/browser/ui/views/tabs/tab.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/tabs/media_indicator_button_unittest.cc
diff --git a/chrome/browser/ui/views/tabs/media_indicator_button_unittest.cc b/chrome/browser/ui/views/tabs/media_indicator_button_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..92b1be20485eee7f292c90952f57bc39205e93a8
--- /dev/null
+++ b/chrome/browser/ui/views/tabs/media_indicator_button_unittest.cc
@@ -0,0 +1,107 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/tabs/media_indicator_button.h"
+
+#include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h"
+#include "chrome/browser/ui/views/tabs/tab.h"
+#include "chrome/browser/ui/views/tabs/tab_strip.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/views/test/views_test_base.h"
+
+class MediaIndicatorButtonTest : public views::ViewsTestBase {
+ public:
+ MediaIndicatorButtonTest()
+ : controller_(nullptr),
+ tab_strip_(nullptr) {
+ }
+
+ ~MediaIndicatorButtonTest() override {}
+
+ void SetUp() override {
+ views::ViewsTestBase::SetUp();
+
+ controller_ = new FakeBaseTabStripController;
+ tab_strip_ = new TabStrip(controller_);
+ controller_->set_tab_strip(tab_strip_);
+ // Do this to force TabStrip to create the buttons.
Peter Kasting 2016/02/03 22:36:39 Nit: How about "The tab strip must be added to the
enne (OOO) 2016/02/03 22:46:46 Sure.
+ parent_.AddChildView(tab_strip_);
+ parent_.set_owned_by_client();
+
+ widget_.reset(new views::Widget);
+ views::Widget::InitParams init_params =
+ CreateParams(views::Widget::InitParams::TYPE_POPUP);
+ init_params.ownership =
+ views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ init_params.bounds = gfx::Rect(0, 0, 400, 400);
+ widget_->Init(init_params);
+ widget_->SetContentsView(&parent_);
+ }
+
+ void TearDown() override {
+ widget_.reset();
Peter Kasting 2016/02/03 22:36:39 Either omit this or comment as to why it has to ex
enne (OOO) 2016/02/03 22:46:46 Left a comment.
+ views::ViewsTestBase::TearDown();
+ }
+
+ protected:
+ bool ShowingCloseButton(Tab* tab) const { return tab->showing_close_button_; }
+ bool ShowingIcon(Tab* tab) const { return tab->showing_icon_; }
+ bool ShowingMediaIndicator(Tab* tab) const {
Peter Kasting 2016/02/03 22:36:39 Nit: Inline accessors like this should normally be
enne (OOO) 2016/02/03 22:46:46 The coding style says this is optional, but sure.
+ return tab->showing_media_indicator_;
+ }
+ void StopAnimation(Tab* tab) {
Peter Kasting 2016/02/03 22:36:39 Nit: Blank line above
enne (OOO) 2016/02/03 22:46:46 Sure.
+ ASSERT_TRUE(tab->media_indicator_button_->fade_animation_);
+ tab->media_indicator_button_->fade_animation_->Stop();
+ }
+
+ // Owned by TabStrip.
+ FakeBaseTabStripController* controller_;
+ // Owns |tab_strip_|.
+ views::View parent_;
+ TabStrip* tab_strip_;
+ scoped_ptr<views::Widget> widget_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MediaIndicatorButtonTest);
+};
+
+// This test verifies that the tab has its icon state updated when the media
+// animation fade-out finishes.
+TEST_F(MediaIndicatorButtonTest, ButtonUpdateOnAudioStateAnimation) {
+ controller_->AddPinnedTab(0, false);
+ controller_->AddTab(1, true);
+ Tab* media_tab = tab_strip_->tab_at(0);
+
+ // Pinned inactive tab only has an icon.
+ EXPECT_TRUE(ShowingIcon(media_tab));
+ EXPECT_FALSE(ShowingMediaIndicator(media_tab));
+ EXPECT_FALSE(ShowingCloseButton(media_tab));
+
+ TabRendererData start_media;
+ start_media.media_state = TAB_MEDIA_STATE_AUDIO_PLAYING;
+ media_tab->SetData(start_media);
+
+ // When audio starts, pinned inactive tab shows indicator.
+ EXPECT_FALSE(ShowingIcon(media_tab));
+ EXPECT_TRUE(ShowingMediaIndicator(media_tab));
+ EXPECT_FALSE(ShowingCloseButton(media_tab));
+
+ TabRendererData stop_media;
+ stop_media.media_state = TAB_MEDIA_STATE_NONE;
+ media_tab->SetData(stop_media);
+
+ // When audio ends, pinned inactive tab fades out indicator.
+ EXPECT_FALSE(ShowingIcon(media_tab));
+ EXPECT_TRUE(ShowingMediaIndicator(media_tab));
+ EXPECT_FALSE(ShowingCloseButton(media_tab));
+
+ // Rather than flakily waiting some unknown number of seconds for the fade
+ // out animation to stop, reach out and stop the fade animation directly,
+ // to make sure that it updates the tab appropriately when it's done.
+ StopAnimation(media_tab);
+
+ EXPECT_TRUE(ShowingIcon(media_tab));
+ EXPECT_FALSE(ShowingMediaIndicator(media_tab));
+ EXPECT_FALSE(ShowingCloseButton(media_tab));
+}
« no previous file with comments | « chrome/browser/ui/views/tabs/media_indicator_button.cc ('k') | chrome/browser/ui/views/tabs/tab.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698