OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "base/bind.h" |
| 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/gl/gl_context_stub_with_extensions.h" |
| 9 #include "ui/gl/gl_implementation.h" |
| 10 #include "ui/gl/gl_mock.h" |
| 11 #include "ui/gl/gl_surface.h" |
| 12 #include "ui/gl/gpu_preference.h" |
| 13 #include "ui/gl/gpu_timing.h" |
| 14 |
| 15 namespace gfx { |
| 16 |
| 17 class GPUTimingTest : public testing::Test { |
| 18 public: |
| 19 void SetUp() override { |
| 20 setup_ = false; |
| 21 fake_cpu_time_ = 0; |
| 22 } |
| 23 |
| 24 void TearDown() override { |
| 25 context_ = nullptr; |
| 26 } |
| 27 |
| 28 void SetupGLContext(const char* gl_version, const char* gl_extensions) { |
| 29 ASSERT_FALSE(setup_) << "Cannot setup GL context twice."; |
| 30 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); |
| 31 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); |
| 32 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); |
| 33 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
| 34 |
| 35 context_ = new gfx::GLContextStubWithExtensions; |
| 36 context_->AddExtensionsString(gl_extensions); |
| 37 context_->SetGLVersionString(gl_version); |
| 38 |
| 39 setup_ = true; |
| 40 } |
| 41 |
| 42 scoped_refptr<GPUTimingClient> CreateGPUTimingClient() { |
| 43 if (!setup_) { |
| 44 SetupGLContext("2.0", ""); |
| 45 } |
| 46 return context_->CreateGPUTimingClient(); |
| 47 } |
| 48 |
| 49 void SetFakeCPUTime(int64_t fake_cpu_time) { |
| 50 fake_cpu_time_ = fake_cpu_time; |
| 51 } |
| 52 |
| 53 protected: |
| 54 static int64_t GetFakeCPUTime() { |
| 55 return fake_cpu_time_; |
| 56 } |
| 57 |
| 58 private: |
| 59 static int64_t fake_cpu_time_; |
| 60 |
| 61 bool setup_ = false; |
| 62 scoped_ptr< ::testing::StrictMock< ::gfx::MockGLInterface> > gl_; |
| 63 scoped_refptr<gfx::GLContextStubWithExtensions> context_; |
| 64 }; |
| 65 |
| 66 int64_t GPUTimingTest::fake_cpu_time_ = 0; |
| 67 |
| 68 TEST_F(GPUTimingTest, FakeTimerTest) { |
| 69 // Tests that we can properly set fake cpu times. |
| 70 SetFakeCPUTime(123); |
| 71 |
| 72 scoped_refptr<GPUTimingClient> gpu_timing_client = CreateGPUTimingClient(); |
| 73 gpu_timing_client->SetCpuTimeForTesting(base::Bind(&GetFakeCPUTime)); |
| 74 EXPECT_EQ(123, gpu_timing_client->GetCurrentCPUTime()); |
| 75 |
| 76 base::Callback<int64_t(void)> empty; |
| 77 gpu_timing_client->SetCpuTimeForTesting(empty); |
| 78 EXPECT_NE(123, gpu_timing_client->GetCurrentCPUTime()); |
| 79 } |
| 80 |
| 81 } // namespace gpu |
OLD | NEW |