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 "gpu/command_buffer/service/gpu_service_test.h" 6 7 #include "gpu/command_buffer/service/test_helper.h" 8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "ui/gl/gl_context_stub_with_extensions.h" 10 #include "ui/gl/gl_implementation.h" 11 #include "ui/gl/gl_mock.h" 12 #include "ui/gl/gl_surface.h" 13 14 namespace gpu { 15 namespace gles2 { 16 GpuServiceTest()17GpuServiceTest::GpuServiceTest() : ran_setup_(false), ran_teardown_(false) { 18 } 19 ~GpuServiceTest()20GpuServiceTest::~GpuServiceTest() { 21 DCHECK(ran_teardown_); 22 } 23 SetUpWithGLVersion(const char * gl_version,const char * gl_extensions)24void GpuServiceTest::SetUpWithGLVersion(const char* gl_version, 25 const char* gl_extensions) { 26 testing::Test::SetUp(); 27 28 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); 29 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); 30 gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>()); 31 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); 32 33 context_ = new gfx::GLContextStubWithExtensions; 34 context_->AddExtensionsString(gl_extensions); 35 context_->SetGLVersionString(gl_version); 36 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_); 37 ran_setup_ = true; 38 } 39 SetUp()40void GpuServiceTest::SetUp() { 41 SetUpWithGLVersion("2.0", NULL); 42 } 43 TearDown()44void GpuServiceTest::TearDown() { 45 DCHECK(ran_setup_); 46 ::gfx::MockGLInterface::SetGLInterface(NULL); 47 gl_.reset(); 48 gfx::ClearGLBindings(); 49 ran_teardown_ = true; 50 51 testing::Test::TearDown(); 52 } 53 54 } // namespace gles2 55 } // namespace gpu 56