Chromium Code Reviews| Index: chrome/browser/ui/tabs/tab_audio_indicator_unittest.cc |
| diff --git a/chrome/browser/ui/tabs/tab_audio_indicator_unittest.cc b/chrome/browser/ui/tabs/tab_audio_indicator_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..404083f33f6be573298c26284cf5a3d107348e51 |
| --- /dev/null |
| +++ b/chrome/browser/ui/tabs/tab_audio_indicator_unittest.cc |
| @@ -0,0 +1,64 @@ |
| +// Copyright (c) 2013 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/tabs/tab_audio_indicator.h" |
| + |
| +#include "base/message_loop.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/base/animation/linear_animation.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/rect.h" |
| + |
| +class TabAudioIndicatorTest : public TabAudioIndicator::Delegate, |
| + public testing::Test { |
| + protected: |
| + TabAudioIndicatorTest() : schedule_paint_count_(0) {} |
| + |
| + virtual void ScheduleAudioIndicatorPaint() OVERRIDE { |
| + ++schedule_paint_count_; |
| + } |
| + |
| + int schedule_paint_count_; |
| + MessageLoopForUI message_loop_; // Needed for ui::LinearAnimation. |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(TabAudioIndicatorTest); |
| +}; |
| + |
| +TEST_F(TabAudioIndicatorTest, AnimationState) { |
| + // Start animating. |
| + TabAudioIndicator indicator(this); |
| + indicator.SetIsPlayingAudio(true); |
| + EXPECT_EQ(TabAudioIndicator::STATE_ANIMATING, indicator.state_); |
| + EXPECT_TRUE(indicator.IsAnimating()); |
| + |
| + // Once the audio stops the indicator should switch to ending animation. |
| + indicator.SetIsPlayingAudio(false); |
| + EXPECT_EQ(TabAudioIndicator::STATE_ANIMATION_ENDING, indicator.state_); |
| + EXPECT_TRUE(indicator.IsAnimating()); |
| + |
| + // Once the ending animation is complete animation should stop. |
| + indicator.animation_->End(); |
| + EXPECT_EQ(TabAudioIndicator::STATE_NOT_ANIMATING, indicator.state_); |
| + EXPECT_FALSE(indicator.IsAnimating()); |
| +} |
| + |
| +TEST_F(TabAudioIndicatorTest, Paint) { |
| + TabAudioIndicator indicator(this); |
| + indicator.SetIsPlayingAudio(true); |
| + |
| + gfx::Rect rect(0, 0, 16, 16); |
| + gfx::Canvas canvas(rect.size(), ui::SCALE_FACTOR_100P, true); |
| + indicator.Paint(&canvas, rect); |
|
cpu_(ooo_6.6-7.5)
2013/03/11 02:40:27
what are we testing here?
sail
2013/03/11 23:16:13
Just exercising the code to make sure nothing leak
|
| +} |
| + |
| +TEST_F(TabAudioIndicatorTest, SchedulePaint) { |
| + TabAudioIndicator indicator(this); |
| + indicator.SetIsPlayingAudio(true); |
| + |
| + indicator.animation_->SetCurrentValue(1.0); |
| + schedule_paint_count_ = 0; |
| + indicator.AnimationProgressed(NULL); |
| + EXPECT_EQ(1, schedule_paint_count_); |
| +} |