Skip to content

Commit

Permalink
content: Make unittests opt into real GL NullDraw contexts.
Browse files Browse the repository at this point in the history
This breaks the dependency on the TestCompositor for all test suites
that are built on ContentTestSuite. Once it's no longer in use by
any test suite, we can remove it.

R=
BUG=270918

Review URL: https://codereview.chromium.org/175893002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253577 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
danakj@chromium.org committed Feb 26, 2014
1 parent 0e87499 commit c08bd68
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
11 changes: 11 additions & 0 deletions content/browser/compositor/image_transport_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

#include "content/browser/compositor/image_transport_factory.h"

#include "base/command_line.h"
#include "content/browser/compositor/gpu_process_transport_factory.h"
#include "content/browser/compositor/no_transport_image_transport_factory.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_switches.h"
#include "ui/gl/gl_implementation.h"

namespace content {

namespace {
ImageTransportFactory* g_factory = NULL;
bool g_initialized_for_unit_tests = false;
static gfx::DisableNullDrawGLBindings* g_disable_null_draw = NULL;
}

// static
Expand All @@ -29,6 +33,11 @@ void ImageTransportFactory::InitializeForUnitTests(
DCHECK(!g_factory);
DCHECK(!g_initialized_for_unit_tests);
g_initialized_for_unit_tests = true;

CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kEnablePixelOutputInTests))
g_disable_null_draw = new gfx::DisableNullDrawGLBindings;

g_factory = new NoTransportImageTransportFactory(test_factory.Pass());
ui::ContextFactory::SetInstance(g_factory->AsContextFactory());
}
Expand All @@ -38,6 +47,8 @@ void ImageTransportFactory::Terminate() {
ui::ContextFactory::SetInstance(NULL);
delete g_factory;
g_factory = NULL;
delete g_disable_null_draw;
g_disable_null_draw = NULL;
g_initialized_for_unit_tests = false;
}

Expand Down
4 changes: 2 additions & 2 deletions content/browser/renderer_host/render_widget_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "ui/aura/env.h"
#include "ui/aura/test/test_screen.h"
#include "ui/compositor/test/test_context_factory.h"
#include "ui/compositor/test/in_process_context_factory.h"
#endif

#if defined(OS_WIN) || defined(USE_AURA)
Expand Down Expand Up @@ -585,7 +585,7 @@ class RenderWidgetHostTest : public testing::Test {
process_ = new RenderWidgetHostProcess(browser_context_.get());
#if defined(USE_AURA)
ImageTransportFactory::InitializeForUnitTests(
scoped_ptr<ui::ContextFactory>(new ui::TestContextFactory));
scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory));
aura::Env::CreateInstance();
screen_.reset(aura::TestScreen::Create());
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "ui/base/ui_base_types.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
#include "ui/compositor/test/test_context_factory.h"
#include "ui/compositor/test/in_process_context_factory.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"

Expand Down Expand Up @@ -194,7 +194,7 @@ class RenderWidgetHostViewAuraTest : public testing::Test {

void SetUpEnvironment() {
ImageTransportFactory::InitializeForUnitTests(
scoped_ptr<ui::ContextFactory>(new ui::TestContextFactory));
scoped_ptr<ui::ContextFactory>(new ui::InProcessContextFactory));
aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
aura_test_helper_->SetUp();

Expand Down
13 changes: 9 additions & 4 deletions content/common/gpu/client/gl_helper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkTypes.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/gl_implementation.h"
#include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"

#if defined(OS_MACOSX)
Expand Down Expand Up @@ -1451,6 +1451,11 @@ class GLHelperTest : public testing::Test {
std::deque<GLHelperScaling::ScaleOp> x_ops_, y_ops_;
};

class GLHelperPixelTest : public GLHelperTest {
private:
gfx::DisableNullDrawGLBindings enable_pixel_output_;
};

TEST_F(GLHelperTest, ARGBSyncReadbackTest) {
const int kTestSize = 64;
bool result = TestTextureFormatReadback(gfx::Size(kTestSize,kTestSize),
Expand Down Expand Up @@ -1483,7 +1488,7 @@ TEST_F(GLHelperTest, RGB565ASyncReadbackTest) {
EXPECT_EQ(result, true);
}

TEST_F(GLHelperTest, YUVReadbackOptTest) {
TEST_F(GLHelperPixelTest, YUVReadbackOptTest) {
// This test uses the cb_command tracing events to detect how many
// scaling passes are actually performed by the YUV readback pipeline.
StartTracing(TRACE_DISABLED_BY_DEFAULT("cb_command"));
Expand Down Expand Up @@ -1519,7 +1524,7 @@ TEST_F(GLHelperTest, YUVReadbackOptTest) {
}
}

TEST_F(GLHelperTest, YUVReadbackTest) {
TEST_F(GLHelperPixelTest, YUVReadbackTest) {
int sizes[] = {2, 4, 14};
for (int flip = 0; flip <= 1; flip++) {
for (int use_mrt = 0; use_mrt <= 1; use_mrt++) {
Expand Down Expand Up @@ -1562,7 +1567,7 @@ TEST_F(GLHelperTest, YUVReadbackTest) {

// Per pixel tests, all sizes are small so that we can print
// out the generated bitmaps.
TEST_F(GLHelperTest, ScaleTest) {
TEST_F(GLHelperPixelTest, ScaleTest) {
int sizes[] = {3, 6, 16};
for (int flip = 0; flip <= 1; flip++) {
for (size_t q = 0; q < arraysize(kQualities); q++) {
Expand Down
16 changes: 7 additions & 9 deletions content/test/content_test_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
#include "content/test/content_test_suite.h"

#include "base/base_paths.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "content/public/test/test_content_client_initializer.h"
#include "content/test/test_content_client.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"

#if !defined(OS_IOS)
#include "ui/gl/gl_surface.h"
#endif

#if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
#endif

#if !defined(OS_IOS)
#include "base/base_switches.h"
#include "base/command_line.h"
#include "ui/gl/gl_surface.h"
#endif

namespace {

class TestInitializationListener : public testing::EmptyTestEventListener {
Expand Down Expand Up @@ -70,14 +70,12 @@ void ContentTestSuite::Initialize() {
#endif

ContentTestSuiteBase::Initialize();

#if !defined(OS_IOS)
// When running in a child process for Mac sandbox tests, the sandbox exists
// to initialize GL, so don't do it here.
if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestChildProcess))
gfx::GLSurface::InitializeOneOffForTests();
gfx::GLSurface::InitializeOneOffForTests(true);
#endif

testing::TestEventListeners& listeners =
testing::UnitTest::GetInstance()->listeners();
listeners.Append(new TestInitializationListener);
Expand Down

0 comments on commit c08bd68

Please sign in to comment.