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.
5 #include "base/run_loop.h"
6 #include "cc/output/context_provider.h"
7 #include "content/browser/compositor/image_transport_factory.h"
8 #include "content/public/browser/gpu_data_manager.h"
9 #include "content/public/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"
18 class ImageTransportFactoryBrowserTest
: public ContentBrowserTest
{};
20 class MockImageTransportFactoryObserver
: public ImageTransportFactoryObserver
{
22 MOCK_METHOD0(OnLostResources
, void());
25 // This crashes on Mac ASAN
26 // http://crbug.com/335083
27 #if defined(OS_MACOSX)
28 #define MAYBE_TestLostContext DISABLED_TestLostContext
30 #define MAYBE_TestLostContext TestLostContext
32 // Checks that upon context loss, the observer is called and the created
33 // resources are reset.
34 IN_PROC_BROWSER_TEST_F(ImageTransportFactoryBrowserTest
,
35 MAYBE_TestLostContext
) {
36 // This test doesn't make sense in software compositing mode.
37 if (!GpuDataManager::GetInstance()->CanUseGpuBrowserCompositor())
40 ImageTransportFactory
* factory
= ImageTransportFactory::GetInstance();
41 scoped_refptr
<ui::Texture
> texture
= factory
->CreateTransportClient(1.f
);
42 ASSERT_TRUE(texture
.get());
44 MockImageTransportFactoryObserver observer
;
45 factory
->AddObserver(&observer
);
47 base::RunLoop run_loop
;
48 EXPECT_CALL(observer
, OnLostResources())
49 .WillOnce(testing::InvokeWithoutArgs(&run_loop
, &base::RunLoop::Quit
));
51 ui::ContextFactory
* context_factory
= ui::ContextFactory::GetInstance();
53 gpu::gles2::GLES2Interface
* gl
=
54 context_factory
->SharedMainThreadContextProvider()->ContextGL();
55 gl
->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB
,
56 GL_INNOCENT_CONTEXT_RESET_ARB
);
58 // We have to flush to make sure that the client side gets a chance to notice
59 // the context is gone.
63 EXPECT_EQ(0u, texture
->PrepareTexture());
65 factory
->RemoveObserver(&observer
);
68 } // anonymous namespace
69 } // namespace content