OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/run_loop.h" | |
6 #include "cc/output/context_provider.h" | |
7 #include "content/browser/aura/image_transport_factory.h" | |
8 #include "content/public/browser/gpu_data_manager.h" | |
9 #include "content/test/content_browser_test.h" | |
10 #include "gpu/GLES2/gl2extchromium.h" | |
11 #include "gpu/command_buffer/client/gles2_interface.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "ui/compositor/compositor.h" | |
14 | |
15 namespace content { | |
16 namespace { | |
17 | |
18 class ImageTransportFactoryBrowserTest : public ContentBrowserTest { | |
19 public: | |
20 ImageTransportFactoryBrowserTest() {} | |
21 | |
22 virtual void SetUp() OVERRIDE { | |
23 UseRealGLContexts(); | |
24 ContentBrowserTest::SetUp(); | |
25 } | |
26 }; | |
27 | |
28 class MockImageTransportFactoryObserver : public ImageTransportFactoryObserver { | |
29 public: | |
30 MOCK_METHOD0(OnLostResources, void()); | |
31 }; | |
32 | |
33 // Checks that upon context loss, the observer is called and the created | |
34 // resources are reset. | |
35 IN_PROC_BROWSER_TEST_F(ImageTransportFactoryBrowserTest, TestLostContext) { | |
36 // This test doesn't make sense in software compositing mode. | |
37 if (!GpuDataManager::GetInstance()->CanUseGpuBrowserCompositor()) | |
38 return; | |
39 | |
40 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | |
41 scoped_refptr<ui::Texture> texture = factory->CreateTransportClient(1.f); | |
42 ASSERT_TRUE(texture.get()); | |
43 | |
44 MockImageTransportFactoryObserver observer; | |
45 factory->AddObserver(&observer); | |
46 | |
47 base::RunLoop run_loop; | |
48 EXPECT_CALL(observer, OnLostResources()) | |
49 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | |
50 | |
51 ui::ContextFactory* context_factory = ui::ContextFactory::GetInstance(); | |
52 | |
53 gpu::gles2::GLES2Interface* gl = | |
54 context_factory->SharedMainThreadContextProvider()->ContextGL(); | |
55 gl->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | |
56 GL_INNOCENT_CONTEXT_RESET_ARB); | |
57 | |
58 // We have to flush to make sure that the client side gets a chance to notice | |
59 // the context is gone. | |
60 gl->Flush(); | |
61 | |
62 run_loop.Run(); | |
63 EXPECT_EQ(0u, texture->PrepareTexture()); | |
64 | |
65 factory->RemoveObserver(&observer); | |
66 } | |
67 | |
68 } // anonymous namespace | |
69 } // namespace content | |
OLD | NEW |