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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
(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 // 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.
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();
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.
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 {
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.
51 return tab->showing_media_indicator_;
52 }
53 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.
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 stop_media.media_state = TAB_MEDIA_STATE_NONE;
92 media_tab->SetData(stop_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 }
OLDNEW
« 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