• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
9 namespace {
10 
11 typedef TabRendererGtk::LoadingAnimation LoadingAnimation;
12 
13 const int kTestLoadingAnimationFrameCount = 10;
14 const int kTestWaitingAnimationFrameCount = 40;
15 const int kTestWaitingToLoadingFrameCountRatio = 4;
16 
17 const LoadingAnimation::Data kMockAnimationData =
18     LoadingAnimation::Data(kTestLoadingAnimationFrameCount,
19                            kTestWaitingAnimationFrameCount,
20                            kTestWaitingToLoadingFrameCountRatio);
21 
TEST(LoadingAnimationTest,InitialState)22 TEST(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 
TEST(LoadingAnimationTest,AdvanceWaitingFrames)29 TEST(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 
TEST(LoadingAnimationTest,AdvanceFromWaitingToLoading)56 TEST(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