| 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..f17c0d7a5eb8a37aeafd9af12e8a62624b3029fa
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/tabs/tab_audio_indicator_unittest.cc
|
| @@ -0,0 +1,67 @@
|
| +// 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);
|
| +
|
| + // Nothing to test here. Just exercise the paint code to verify that nothing
|
| + // leaks or crashes.
|
| + indicator.Paint(&canvas, rect);
|
| +}
|
| +
|
| +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_);
|
| +}
|
|
|