Home | History | Annotate | Download | only in output
      1 // Copyright 2014 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 <string>
      6 
      7 #include "cc/output/begin_frame_args.h"
      8 #include "cc/test/begin_frame_args_test.h"
      9 #include "testing/gtest/include/gtest/gtest-spi.h"
     10 #include "testing/gtest/include/gtest/gtest.h"
     11 #include "ui/gfx/frame_time.h"
     12 
     13 namespace cc {
     14 namespace {
     15 
     16 TEST(BeginFrameArgsTest, Helpers) {
     17   // Quick create methods work
     18   BeginFrameArgs args0 = CreateBeginFrameArgsForTesting();
     19   EXPECT_TRUE(args0.IsValid()) << args0;
     20 
     21   BeginFrameArgs args1 = CreateBeginFrameArgsForTesting(0, 0, -1);
     22   EXPECT_FALSE(args1.IsValid()) << args1;
     23 
     24   BeginFrameArgs args2 = CreateBeginFrameArgsForTesting(1, 2, 3);
     25   EXPECT_TRUE(args2.IsValid()) << args2;
     26   EXPECT_EQ(1, args2.frame_time.ToInternalValue());
     27   EXPECT_EQ(2, args2.deadline.ToInternalValue());
     28   EXPECT_EQ(3, args2.interval.ToInternalValue());
     29 
     30   BeginFrameArgs args3 = CreateExpiredBeginFrameArgsForTesting();
     31   EXPECT_TRUE(args3.IsValid()) << args3;
     32   EXPECT_GT(gfx::FrameTime::Now(), args3.deadline);
     33 
     34   // operator==
     35   EXPECT_EQ(CreateBeginFrameArgsForTesting(4, 5, 6),
     36             CreateBeginFrameArgsForTesting(4, 5, 6));
     37 
     38   EXPECT_NONFATAL_FAILURE(EXPECT_EQ(CreateBeginFrameArgsForTesting(4, 5, 6),
     39                                     CreateBeginFrameArgsForTesting(7, 8, 9)),
     40                           "");
     41 
     42   // operator<<
     43   std::stringstream out1;
     44   out1 << args1;
     45   EXPECT_EQ("BeginFrameArgs(0, 0, -1us)", out1.str());
     46   std::stringstream out2;
     47   out2 << args2;
     48   EXPECT_EQ("BeginFrameArgs(1, 2, 3us)", out2.str());
     49 
     50   // PrintTo
     51   EXPECT_EQ(std::string("BeginFrameArgs(0, 0, -1us)"),
     52             ::testing::PrintToString(args1));
     53   EXPECT_EQ(std::string("BeginFrameArgs(1, 2, 3us)"),
     54             ::testing::PrintToString(args2));
     55 }
     56 
     57 TEST(BeginFrameArgsTest, Create) {
     58   // BeginFrames are not valid by default
     59   BeginFrameArgs args1;
     60   EXPECT_FALSE(args1.IsValid()) << args1;
     61 
     62   BeginFrameArgs args2 =
     63       BeginFrameArgs::Create(base::TimeTicks::FromInternalValue(1),
     64                              base::TimeTicks::FromInternalValue(2),
     65                              base::TimeDelta::FromInternalValue(3));
     66   EXPECT_TRUE(args2.IsValid()) << args2;
     67   EXPECT_EQ(1, args2.frame_time.ToInternalValue()) << args2;
     68   EXPECT_EQ(2, args2.deadline.ToInternalValue()) << args2;
     69   EXPECT_EQ(3, args2.interval.ToInternalValue()) << args2;
     70 
     71   base::TimeTicks now = base::TimeTicks::FromInternalValue(1);
     72   EXPECT_EQ(CreateBeginFrameArgsForTesting(1, 0, 16666),
     73             BeginFrameArgs::CreateForSynchronousCompositor(now));
     74 }
     75 
     76 }  // namespace
     77 }  // namespace cc
     78