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 "content/browser/compositor/image_transport_factory.h" 6 7 #include "base/run_loop.h" 8 #include "build/build_config.h" 9 #include "components/viz/common/gpu/context_lost_observer.h" 10 #include "components/viz/common/gpu/context_provider.h" 11 #include "content/browser/gpu/gpu_data_manager_impl.h" 12 #include "content/public/test/browser_test.h" 13 #include "content/public/test/content_browser_test.h" 14 #include "gpu/GLES2/gl2extchromium.h" 15 #include "gpu/command_buffer/client/gles2_interface.h" 16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "ui/compositor/compositor.h" 18 19 namespace content { 20 namespace { 21 22 using ImageTransportFactoryBrowserTest = ContentBrowserTest; 23 24 class MockContextLostObserver : public viz::ContextLostObserver { 25 public: 26 MOCK_METHOD0(OnContextLost, void()); 27 }; 28 29 // Flaky on ChromeOS: crbug.com/394083 30 #if defined(OS_CHROMEOS) 31 #define MAYBE_TestLostContext DISABLED_TestLostContext 32 #else 33 #define MAYBE_TestLostContext TestLostContext 34 #endif 35 // Checks that upon context loss the observer is notified. IN_PROC_BROWSER_TEST_F(ImageTransportFactoryBrowserTest,MAYBE_TestLostContext)36IN_PROC_BROWSER_TEST_F(ImageTransportFactoryBrowserTest, 37 MAYBE_TestLostContext) { 38 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); 39 40 // This test doesn't make sense in software compositing mode. 41 if (GpuDataManagerImpl::GetInstance()->IsGpuCompositingDisabled()) 42 return; 43 44 scoped_refptr<viz::ContextProvider> context_provider = 45 factory->GetContextFactory()->SharedMainThreadContextProvider(); 46 47 MockContextLostObserver observer; 48 context_provider->AddObserver(&observer); 49 50 base::RunLoop run_loop; 51 EXPECT_CALL(observer, OnContextLost()) 52 .WillOnce(testing::Invoke(&run_loop, &base::RunLoop::Quit)); 53 54 gpu::gles2::GLES2Interface* gl = context_provider->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 64 context_provider->RemoveObserver(&observer); 65 } 66 67 } // anonymous namespace 68 } // namespace content 69