1// Copyright (c) 2011 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/gtk/tabs/tab_renderer_gtk.h" 6 7#include "testing/gtest/include/gtest/gtest.h" 8 9namespace { 10 11typedef TabRendererGtk::LoadingAnimation LoadingAnimation; 12 13const int kTestLoadingAnimationFrameCount = 10; 14const int kTestWaitingAnimationFrameCount = 40; 15const int kTestWaitingToLoadingFrameCountRatio = 4; 16 17const LoadingAnimation::Data kMockAnimationData = 18 LoadingAnimation::Data(kTestLoadingAnimationFrameCount, 19 kTestWaitingAnimationFrameCount, 20 kTestWaitingToLoadingFrameCountRatio); 21 22TEST(LoadingAnimationTest, InitialState) { 23 LoadingAnimation loading_animation(kMockAnimationData); 24 EXPECT_EQ(TabRendererGtk::ANIMATION_NONE, 25 loading_animation.animation_state()); 26 EXPECT_EQ(0, loading_animation.animation_frame()); 27} 28 29TEST(LoadingAnimationTest, AdvanceWaitingFrames) { 30 LoadingAnimation loading_animation(kMockAnimationData); 31 loading_animation.ValidateLoadingAnimation(TabRendererGtk::ANIMATION_WAITING); 32 EXPECT_EQ(TabRendererGtk::ANIMATION_WAITING, 33 loading_animation.animation_state()); 34 EXPECT_EQ(1, loading_animation.animation_frame()); 35 loading_animation.ValidateLoadingAnimation(TabRendererGtk::ANIMATION_WAITING); 36 EXPECT_EQ(TabRendererGtk::ANIMATION_WAITING, 37 loading_animation.animation_state()); 38 EXPECT_EQ(2, loading_animation.animation_frame()); 39 40 for (int i = 2; i < kTestWaitingAnimationFrameCount - 1; ++i) { 41 loading_animation.ValidateLoadingAnimation( 42 TabRendererGtk::ANIMATION_WAITING); 43 } 44 EXPECT_EQ(TabRendererGtk::ANIMATION_WAITING, 45 loading_animation.animation_state()); 46 EXPECT_EQ(kTestWaitingAnimationFrameCount - 1, 47 loading_animation.animation_frame()); 48 49 loading_animation.ValidateLoadingAnimation(TabRendererGtk::ANIMATION_WAITING); 50 EXPECT_EQ(TabRendererGtk::ANIMATION_WAITING, 51 loading_animation.animation_state()); 52 EXPECT_EQ(0, loading_animation.animation_frame()) << 53 "The animation frame should have wrapped around to 0."; 54} 55 56TEST(LoadingAnimationTest, AdvanceFromWaitingToLoading) { 57 LoadingAnimation loading_animation(kMockAnimationData); 58 for (int i = 0; i < 2 * kTestWaitingToLoadingFrameCountRatio; ++i) { 59 loading_animation.ValidateLoadingAnimation( 60 TabRendererGtk::ANIMATION_WAITING); 61 } 62 EXPECT_EQ(TabRendererGtk::ANIMATION_WAITING, 63 loading_animation.animation_state()); 64 EXPECT_EQ(2 * kTestWaitingToLoadingFrameCountRatio, 65 loading_animation.animation_frame()); 66 67 loading_animation.ValidateLoadingAnimation(TabRendererGtk::ANIMATION_LOADING); 68 EXPECT_EQ(TabRendererGtk::ANIMATION_LOADING, 69 loading_animation.animation_state()); 70 EXPECT_EQ(kTestLoadingAnimationFrameCount - 1, 71 loading_animation.animation_frame()); 72} 73 74} // namespace 75