Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Unified Diff: content/browser/gpu/gpu_ipc_browsertests.cc

Issue 2197613003: gpu: Introduce GpuChannelEstablishFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/gpu/gpu_ipc_browsertests.cc
diff --git a/content/browser/gpu/gpu_ipc_browsertests.cc b/content/browser/gpu/gpu_ipc_browsertests.cc
index 016e49169b5bd5058eef4dfbef3255e73d928633..64f56a55fbe46d60c59bca1e9aaa378d80e43cf1 100644
--- a/content/browser/gpu/gpu_ipc_browsertests.cc
+++ b/content/browser/gpu/gpu_ipc_browsertests.cc
@@ -44,14 +44,21 @@ scoped_refptr<content::ContextProviderCommandBuffer> CreateContext(
nullptr, content::command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING));
}
-class ContextTestBase : public content::ContentBrowserTest {
+void OnEstablishedGpuChannel(
+ const base::Closure& quit_closure,
+ scoped_refptr<gpu::GpuChannelHost>* retvalue,
+ scoped_refptr<gpu::GpuChannelHost> established_host) {
+ if (retvalue)
+ *retvalue = std::move(established_host);
+ quit_closure.Run();
+}
+
+class EstablishGpuChannelHelper {
public:
- void SetUpOnMainThread() override {
- // This may leave the provider_ null in some cases, so tests need to early
- // out.
- if (!content::BrowserGpuChannelHostFactory::CanUseForTesting())
- return;
+ EstablishGpuChannelHelper() {}
+ ~EstablishGpuChannelHelper() {}
+ scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSyncRunLoop() {
if (!content::BrowserGpuChannelHostFactory::instance())
content::BrowserGpuChannelHostFactory::Initialize(true);
@@ -59,10 +66,29 @@ class ContextTestBase : public content::ContentBrowserTest {
content::BrowserGpuChannelHostFactory::instance();
CHECK(factory);
base::RunLoop run_loop;
- factory->EstablishGpuChannel(kInitCause, run_loop.QuitClosure());
+ factory->EstablishGpuChannel(
+ kInitCause, base::Bind(&OnEstablishedGpuChannel, run_loop.QuitClosure(),
+ &gpu_channel_host_));
run_loop.Run();
- scoped_refptr<gpu::GpuChannelHost> gpu_channel_host(
- factory->GetGpuChannel());
+ return std::move(gpu_channel_host_);
+ }
+
+ private:
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_;
+ DISALLOW_COPY_AND_ASSIGN(EstablishGpuChannelHelper);
+};
+
+class ContextTestBase : public content::ContentBrowserTest {
+ public:
+ void SetUpOnMainThread() override {
+ // This may leave the provider_ null in some cases, so tests need to early
+ // out.
+ if (!content::BrowserGpuChannelHostFactory::CanUseForTesting())
+ return;
+
+ EstablishGpuChannelHelper helper;
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
+ helper.EstablishGpuChannelSyncRunLoop();
CHECK(gpu_channel_host);
provider_ = CreateContext(std::move(gpu_channel_host));
@@ -123,27 +149,30 @@ class BrowserGpuChannelHostFactoryTest : public ContentBrowserTest {
callback.Run();
}
+ void Signal(bool* event,
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
+ CHECK_EQ(*event, false);
+ *event = true;
+ gpu_channel_host_ = std::move(gpu_channel_host);
+ }
+
protected:
BrowserGpuChannelHostFactory* GetFactory() {
return BrowserGpuChannelHostFactory::instance();
}
bool IsChannelEstablished() {
- return GetFactory()->GetGpuChannel() != NULL;
+ return gpu_channel_host_ && !gpu_channel_host_->IsLost();
}
void EstablishAndWait() {
- base::RunLoop run_loop;
- GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure());
- run_loop.Run();
+ EstablishGpuChannelHelper helper;
+ gpu_channel_host_ = helper.EstablishGpuChannelSyncRunLoop();
}
- gpu::GpuChannelHost* GetGpuChannel() { return GetFactory()->GetGpuChannel(); }
+ gpu::GpuChannelHost* GetGpuChannel() { return gpu_channel_host_.get(); }
- static void Signal(bool *event) {
- CHECK_EQ(*event, false);
- *event = true;
- }
+ scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_;
};
// Test fails on Chromeos + Mac, flaky on Windows because UI Compositor
@@ -170,7 +199,9 @@ IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
MAYBE_EstablishAndTerminate) {
DCHECK(!IsChannelEstablished());
base::RunLoop run_loop;
- GetFactory()->EstablishGpuChannel(kInitCause, run_loop.QuitClosure());
+ GetFactory()->EstablishGpuChannel(
+ kInitCause,
+ base::Bind(&OnEstablishedGpuChannel, run_loop.QuitClosure(), nullptr));
GetFactory()->Terminate();
// The callback should still trigger.
@@ -194,8 +225,8 @@ IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
// Expect established callback immediately.
bool event = false;
GetFactory()->EstablishGpuChannel(
- kInitCause,
- base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event));
+ kInitCause, base::Bind(&BrowserGpuChannelHostFactoryTest::Signal,
+ base::Unretained(this), &event));
EXPECT_TRUE(event);
EXPECT_EQ(gpu_channel.get(), GetGpuChannel());
}
@@ -258,7 +289,7 @@ IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
// Test fails on Chromeos + Mac, flaky on Windows because UI Compositor
// establishes a GPU channel.
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
-#define MAYBE_CrashAndRecover
+#define MAYBE_CrashAndRecover CrashAndRecover
#else
#define MAYBE_CrashAndRecover DISABLED_CrashAndRecover
#endif

Powered by Google App Engine
This is Rietveld 408576698