Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / compositor / image_transport_factory_browsertest.cc
blobd4792fbe8d6ef04b1bc2c5831dd544f1b4a419e1
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/browser/compositor/owned_mailbox.h"
9 #include "content/public/browser/gpu_data_manager.h"
10 #include "content/public/test/content_browser_test.h"
11 #include "gpu/GLES2/gl2extchromium.h"
12 #include "gpu/command_buffer/client/gles2_interface.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "ui/compositor/compositor.h"
16 namespace content {
17 namespace {
19 class ImageTransportFactoryBrowserTest : public ContentBrowserTest {};
21 class MockImageTransportFactoryObserver : public ImageTransportFactoryObserver {
22 public:
23 MOCK_METHOD0(OnLostResources, void());
26 // This crashes on Mac ASAN
27 // http://crbug.com/335083
28 #if defined(OS_MACOSX)
29 #define MAYBE_TestLostContext DISABLED_TestLostContext
30 #else
31 #define MAYBE_TestLostContext TestLostContext
32 #endif
33 // Checks that upon context loss, the observer is called and the created
34 // resources are reset.
35 IN_PROC_BROWSER_TEST_F(ImageTransportFactoryBrowserTest,
36 MAYBE_TestLostContext) {
37 // This test doesn't make sense in software compositing mode.
38 if (!GpuDataManager::GetInstance()->CanUseGpuBrowserCompositor())
39 return;
41 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
43 scoped_refptr<OwnedMailbox> mailbox =
44 new OwnedMailbox(factory->GetGLHelper());
45 EXPECT_FALSE(mailbox->mailbox().IsZero());
47 MockImageTransportFactoryObserver observer;
48 factory->AddObserver(&observer);
50 base::RunLoop run_loop;
51 EXPECT_CALL(observer, OnLostResources())
52 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
54 ui::ContextFactory* context_factory = ui::ContextFactory::GetInstance();
55 gpu::gles2::GLES2Interface* gl =
56 context_factory->SharedMainThreadContextProvider()->ContextGL();
57 gl->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
58 GL_INNOCENT_CONTEXT_RESET_ARB);
60 // We have to flush to make sure that the client side gets a chance to notice
61 // the context is gone.
62 gl->Flush();
64 run_loop.Run();
65 EXPECT_TRUE(mailbox->mailbox().IsZero());
67 factory->RemoveObserver(&observer);
70 } // anonymous namespace
71 } // namespace content