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

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: tot merge Created 4 years, 4 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 398282381f0344504a3e4eb9db881110d424e701..7394f6d36496b238811f066b45cade598be4f78a 100644
--- a/content/browser/gpu/gpu_ipc_browsertests.cc
+++ b/content/browser/gpu/gpu_ipc_browsertests.cc
@@ -6,6 +6,7 @@
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "build/build_config.h"
+#include "content/browser/compositor/image_transport_factory.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
#include "content/browser/gpu/gpu_process_host_ui_shim.h"
#include "content/common/gpu/client/context_provider_command_buffer.h"
@@ -40,14 +41,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);
@@ -55,10 +63,28 @@ class ContextTestBase : public content::ContentBrowserTest {
content::BrowserGpuChannelHostFactory::instance();
CHECK(factory);
base::RunLoop run_loop;
- factory->EstablishGpuChannel(run_loop.QuitClosure());
+ factory->EstablishGpuChannel(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));
@@ -102,7 +128,6 @@ class BrowserGpuChannelHostFactoryTest : public ContentBrowserTest {
// consistent codepath.
if (!BrowserGpuChannelHostFactory::instance())
BrowserGpuChannelHostFactory::Initialize(false);
-
CHECK(GetFactory());
ContentBrowserTest::SetUpOnMainThread();
@@ -119,27 +144,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(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
@@ -166,7 +194,8 @@ IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
MAYBE_EstablishAndTerminate) {
DCHECK(!IsChannelEstablished());
base::RunLoop run_loop;
- GetFactory()->EstablishGpuChannel(run_loop.QuitClosure());
+ GetFactory()->EstablishGpuChannel(
+ base::Bind(&OnEstablishedGpuChannel, run_loop.QuitClosure(), nullptr));
GetFactory()->Terminate();
// The callback should still trigger.
@@ -190,7 +219,8 @@ IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest,
// Expect established callback immediately.
bool event = false;
GetFactory()->EstablishGpuChannel(
- base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event));
+ base::Bind(&BrowserGpuChannelHostFactoryTest::Signal,
+ base::Unretained(this), &event));
EXPECT_TRUE(event);
EXPECT_EQ(gpu_channel.get(), GetGpuChannel());
}
@@ -253,7 +283,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