| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "content/browser/aura/image_transport_factory.h" | 6 #include "content/browser/aura/image_transport_factory.h" |
| 7 #include "content/public/browser/gpu_data_manager.h" |
| 7 #include "content/test/content_browser_test.h" | 8 #include "content/test/content_browser_test.h" |
| 8 #include "gpu/GLES2/gl2extchromium.h" | 9 #include "gpu/GLES2/gl2extchromium.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 11 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
| 11 #include "ui/compositor/compositor.h" | 12 #include "ui/compositor/compositor.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 class ImageTransportFactoryBrowserTest : public ContentBrowserTest { | 17 class ImageTransportFactoryBrowserTest : public ContentBrowserTest { |
| 17 public: | 18 public: |
| 18 ImageTransportFactoryBrowserTest() {} | 19 ImageTransportFactoryBrowserTest() {} |
| 19 | 20 |
| 20 virtual void SetUp() OVERRIDE { | 21 virtual void SetUp() OVERRIDE { |
| 21 UseRealGLContexts(); | 22 UseRealGLContexts(); |
| 22 ContentBrowserTest::SetUp(); | 23 ContentBrowserTest::SetUp(); |
| 23 } | 24 } |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 class MockImageTransportFactoryObserver : public ImageTransportFactoryObserver { | 27 class MockImageTransportFactoryObserver : public ImageTransportFactoryObserver { |
| 27 public: | 28 public: |
| 28 MOCK_METHOD0(OnLostResources, void()); | 29 MOCK_METHOD0(OnLostResources, void()); |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 // Checks that upon context loss, the observer is called and the created | 32 // Checks that upon context loss, the observer is called and the created |
| 32 // resources are reset. | 33 // resources are reset. |
| 33 IN_PROC_BROWSER_TEST_F(ImageTransportFactoryBrowserTest, TestLostContext) { | 34 IN_PROC_BROWSER_TEST_F(ImageTransportFactoryBrowserTest, TestLostContext) { |
| 35 // This test doesn't make sense in software compositing mode. |
| 36 if (!GpuDataManager::GetInstance()->CanUseGpuBrowserCompositor()) |
| 37 return; |
| 38 |
| 34 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 39 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 35 scoped_refptr<ui::Texture> texture = factory->CreateTransportClient(1.f); | 40 scoped_refptr<ui::Texture> texture = factory->CreateTransportClient(1.f); |
| 41 ASSERT_TRUE(texture.get()); |
| 36 | 42 |
| 37 MockImageTransportFactoryObserver observer; | 43 MockImageTransportFactoryObserver observer; |
| 38 factory->AddObserver(&observer); | 44 factory->AddObserver(&observer); |
| 39 | 45 |
| 40 base::RunLoop run_loop; | 46 base::RunLoop run_loop; |
| 41 EXPECT_CALL(observer, OnLostResources()) | 47 EXPECT_CALL(observer, OnLostResources()) |
| 42 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 48 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 43 | 49 |
| 44 WebKit::WebGraphicsContext3D* context = texture->HostContext3D(); | 50 WebKit::WebGraphicsContext3D* context = texture->HostContext3D(); |
| 45 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 51 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
| 46 GL_INNOCENT_CONTEXT_RESET_ARB); | 52 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 47 | 53 |
| 48 run_loop.Run(); | 54 run_loop.Run(); |
| 49 EXPECT_FALSE(texture->HostContext3D()); | 55 EXPECT_FALSE(texture->HostContext3D()); |
| 50 EXPECT_EQ(0u, texture->PrepareTexture()); | 56 EXPECT_EQ(0u, texture->PrepareTexture()); |
| 51 | 57 |
| 52 factory->RemoveObserver(&observer); | 58 factory->RemoveObserver(&observer); |
| 53 } | 59 } |
| 54 | 60 |
| 55 } // anonymous namespace | 61 } // anonymous namespace |
| 56 } // namespace content | 62 } // namespace content |
| OLD | NEW |