diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-07 22:55:44 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-07 22:55:44 +0000 |
commit | f9451a81caf32ebae0c5e13903698b6270ee4b9d (patch) | |
tree | e897644ae1ea172d6ac5d28a669e61d8bbad39cc | |
parent | ef0efbe57a1ae50c4cae7292ad36d84706712446 (diff) | |
download | chromium_src-f9451a81caf32ebae0c5e13903698b6270ee4b9d.zip chromium_src-f9451a81caf32ebae0c5e13903698b6270ee4b9d.tar.gz chromium_src-f9451a81caf32ebae0c5e13903698b6270ee4b9d.tar.bz2 |
Revert 216278 "Clean up compositor initialization/destruction."
interactive_ui_test failures in TabDragging tests:
http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%282%29/builds/17046
> Clean up compositor initialization/destruction.
>
> Moved from https://codereview.chromium.org/21052007/
>
> Currently the ContextFactory is outliving the compositor thread in
> tests, which is bad since the contexts in there can be bound to the
> compositor thread. Then we end up reusing those contexts and bad
> things happen.
>
> This enforces ordering for initializing and destroying the
> compositor as follows:
>
> Initialize ContextFactory
> ..Compositor::Initialize
> ....Create Compositor instances
> ....Delete Compositor instances
> ..Compositor::Terminate
>
> The Compositor::Terminate call also destroys the ContextFactory.
>
> The ContextFactory can be initialized in one of two ways:
> 1. ImageTransportFactory::Initialize will set up the
> ContextFactory. This is used by things that invoke all of
> content/browser/.
> 2. Compositor::InitializeContextFactoryForTests() must be
> explicitly called by any unit tests that create a compositor.
>
> Since some tests want a real GL context and some don't, this
> does away with the misnomer of initializing the Compositor once
> for the entire test suite, and then re-initializing somewhere
> in the middle of the test suite. Instead, each test must
> Initialize/Terminate the compositor with the ContextFactory
> type of its choice.
>
> Incidently, this test enables 20 tests on aura or win_aura that
> were previously being skipped.
>
> TBR=piman@chromium.org
> BUG=258625
>
> Review URL: https://codereview.chromium.org/22293003
TBR=danakj@chromium.org
Review URL: https://codereview.chromium.org/22603007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216294 0039d316-1c4b-4281-b951-d872f2087c98
48 files changed, 402 insertions, 372 deletions
diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index a21eddc..532876e 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -17,7 +17,6 @@ #include "base/logging.h" #include "content/public/test/test_browser_context.h" #include "ui/aura/window.h" -#include "ui/compositor/compositor.h" namespace ash { namespace test { @@ -214,10 +213,6 @@ double TestShellDelegate::GetSavedScreenMagnifierScale() { } RootWindowHostFactory* TestShellDelegate::CreateRootWindowHostFactory() { - // The ContextFactory must exist before any Compositors are created. - bool allow_test_contexts = true; - ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts); - return RootWindowHostFactory::Create(); } diff --git a/ash/test/test_suite.cc b/ash/test/test_suite.cc index 54c24ee..02c5f29 100644 --- a/ash/test/test_suite.cc +++ b/ash/test/test_suite.cc @@ -12,6 +12,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" +#include "ui/compositor/compositor_setup.h" #include "ui/gfx/gfx_paths.h" #if defined(OS_MACOSX) @@ -54,6 +55,7 @@ void AuraShellTestSuite::Initialize() { // Force unittests to run using en-US so if we test against string // output, it'll pass regardless of the system language. ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); + ui::SetupTestCompositor(); } void AuraShellTestSuite::Shutdown() { diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc b/chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc index ffaf714..b533deb 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc +++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc @@ -347,14 +347,6 @@ class FileManagerBrowserTest : drive_volume_(std::tr1::get<0>(GetParam()) != IN_GUEST_MODE ? new DriveTestVolume() : NULL) {} - virtual void SetUp() OVERRIDE { - // TODO(danakj): The GPU Video Decoder needs real GL bindings. - // crbug.com/269087 - UseRealGLBindings(); - - ExtensionApiTest::SetUp(); - } - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; virtual void SetUpOnMainThread() OVERRIDE; diff --git a/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc b/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc index 1e75fa7..490abfd 100644 --- a/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc +++ b/chrome/browser/extensions/api/tab_capture/tab_capture_apitest.cc @@ -37,14 +37,6 @@ class TabCaptureApiTest : public ExtensionApiTest { public: TabCaptureApiTest() {} - virtual void SetUp() OVERRIDE { - // TODO(danakj): The GPU Video Decoder needs real GL bindings. - // crbug.com/269087 - UseRealGLBindings(); - - ExtensionApiTest::SetUp(); - } - void AddExtensionToCommandLineWhitelist() { CommandLine::ForCurrentProcess()->AppendSwitchASCII( switches::kWhitelistedExtensionID, kExtensionId); diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc index c2565f8..af1689f 100644 --- a/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc +++ b/chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc @@ -20,6 +20,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_switches.h" +#include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/gpu_data_manager.h" #include "content/public/browser/notification_observer.h" @@ -311,6 +312,17 @@ IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, EmptyCrx) { } class ExtensionWebstoreGetWebGLStatusTest : public InProcessBrowserTest { + public: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + // We need to launch GPU process to decide if WebGL is allowed. + // Run it on top of osmesa to avoid bot driver issues. +#if !defined(OS_MACOSX) + CHECK(test_launcher_utils::OverrideGLImplementation( + command_line, gfx::kGLImplementationOSMesaName)) << + "kUseGL must not be set multiple times!"; +#endif + } + protected: void RunTest(bool webgl_allowed) { static const char kEmptyArgs[] = "[]"; diff --git a/chrome/browser/extensions/extension_resource_request_policy_apitest.cc b/chrome/browser/extensions/extension_resource_request_policy_apitest.cc index 44fd689..6049f6e 100644 --- a/chrome/browser/extensions/extension_resource_request_policy_apitest.cc +++ b/chrome/browser/extensions/extension_resource_request_policy_apitest.cc @@ -17,14 +17,6 @@ class ExtensionResourceRequestPolicyTest : public ExtensionApiTest { protected: - virtual void SetUp() OVERRIDE { - // TODO(danakj): The GPU Video Decoder needs real GL bindings. - // crbug.com/269087 - UseRealGLBindings(); - - ExtensionApiTest::SetUp(); - } - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { ExtensionApiTest::SetUpCommandLine(command_line); command_line->AppendSwitch( diff --git a/chrome/browser/extensions/requirements_checker_browsertest.cc b/chrome/browser/extensions/requirements_checker_browsertest.cc index 73bbfbd..30b01d6 100644 --- a/chrome/browser/extensions/requirements_checker_browsertest.cc +++ b/chrome/browser/extensions/requirements_checker_browsertest.cc @@ -17,6 +17,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_file_util.h" +#include "chrome/test/base/test_launcher_utils.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/gpu_data_manager.h" #include "gpu/config/gpu_info.h" @@ -28,6 +29,16 @@ namespace extensions { class RequirementsCheckerBrowserTest : public ExtensionBrowserTest { public: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + // We need to launch GPU process to decide if WebGL is allowed. + // Run it on top of osmesa to avoid bot driver issues. +#if !defined(OS_MACOSX) + CHECK(test_launcher_utils::OverrideGLImplementation( + command_line, gfx::kGLImplementationOSMesaName)) << + "kUseGL must not be set multiple times!"; +#endif + } + scoped_refptr<const Extension> LoadExtensionFromDirName( const std::string& extension_dir_name) { base::FilePath extension_path; @@ -179,4 +190,4 @@ IN_PROC_BROWSER_TEST_F(RequirementsCheckerBrowserTest, Check3DExtension) { content::BrowserThread::GetBlockingPool()->FlushForTesting(); } -} // namespace extensions +} // extensions diff --git a/chrome/browser/extensions/web_view_browsertest.cc b/chrome/browser/extensions/web_view_browsertest.cc index 13fe584..9dd1903 100644 --- a/chrome/browser/extensions/web_view_browsertest.cc +++ b/chrome/browser/extensions/web_view_browsertest.cc @@ -13,6 +13,7 @@ #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/extensions/extension.h" +#include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/render_process_host.h" @@ -22,6 +23,7 @@ #include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_response.h" +#include "ui/compositor/compositor_setup.h" #include "ui/gl/gl_switches.h" // For fine-grained suppression on flaky tests. @@ -148,6 +150,15 @@ class MockDownloadWebContentsDelegate : public content::WebContentsDelegate { class WebViewTest : public extensions::PlatformAppBrowserTest { protected: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); +#if !defined(OS_MACOSX) + CHECK(test_launcher_utils::OverrideGLImplementation( + command_line, gfx::kGLImplementationOSMesaName)) << + "kUseGL must not be set by test framework code!"; +#endif + } + virtual void SetUp() OVERRIDE { const testing::TestInfo* const test_info = testing::UnitTest::GetInstance()->current_test_info(); diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc index 1e6546d..e075cc1 100644 --- a/chrome/browser/prerender/prerender_browsertest.cc +++ b/chrome/browser/prerender/prerender_browsertest.cc @@ -645,14 +645,6 @@ class PrerenderBrowserTest : virtual public InProcessBrowserTest { return web_contents->GetController().GetDefaultSessionStorageNamespace(); } - virtual void SetUp() OVERRIDE { - // TODO(danakj): The GPU Video Decoder needs real GL bindings. - // crbug.com/269087 - UseRealGLBindings(); - - InProcessBrowserTest::SetUp(); - } - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { #if defined(FULL_SAFE_BROWSING) SafeBrowsingService::RegisterFactory(safe_browsing_factory_.get()); @@ -2750,10 +2742,6 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, class PrerenderBrowserTestWithExtensions : public PrerenderBrowserTest, public ExtensionApiTest { public: - virtual void SetUp() OVERRIDE { - PrerenderBrowserTest::SetUp(); - } - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { PrerenderBrowserTest::SetUpCommandLine(command_line); ExtensionApiTest::SetUpCommandLine(command_line); diff --git a/chrome/browser/ui/ash/ash_init.cc b/chrome/browser/ui/ash/ash_init.cc index f8dda09..fb9f561 100644 --- a/chrome/browser/ui/ash/ash_init.cc +++ b/chrome/browser/ui/ash/ash_init.cc @@ -22,6 +22,7 @@ #include "chrome/common/chrome_switches.h" #include "ui/aura/env.h" #include "ui/aura/root_window.h" +#include "ui/compositor/compositor_setup.h" #if defined(OS_CHROMEOS) #include "base/chromeos/chromeos_version.h" diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc index 014386c..9ac7c38 100644 --- a/chrome/test/base/in_process_browser_test.cc +++ b/chrome/test/base/in_process_browser_test.cc @@ -51,6 +51,7 @@ #include "net/dns/mock_host_resolver.h" #include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/spawned_test_server/spawned_test_server.h" +#include "ui/compositor/compositor_switches.h" #if defined(OS_MACOSX) #include "base/mac/scoped_nsautorelease_pool.h" @@ -60,6 +61,7 @@ #include "base/win/scoped_com_initializer.h" #include "base/win/windows_version.h" #include "ui/base/win/atl_module.h" +#include "ui/compositor/compositor_setup.h" #include "win8/test/metro_registration_helper.h" #include "win8/test/test_registrar_constants.h" #endif @@ -218,6 +220,9 @@ void InProcessBrowserTest::SetUp() { com_initializer_.reset(new base::win::ScopedCOMInitializer()); ui::win::CreateATLModuleIfNeeded(); ASSERT_TRUE(win8::MakeTestDefaultBrowserSynchronously()); + + // Ash browser tests need the real compositor. + ui::DisableTestCompositor(); } #endif @@ -373,6 +378,16 @@ CommandLine InProcessBrowserTest::GetCommandLineForRelaunch() { switches.erase(switches::kSingleProcess); new_command_line.AppendSwitch(content::kLaunchAsBrowser); +#if defined(USE_AURA) + // Copy what UITestBase::SetLaunchSwitches() does, and also what + // ChromeTestSuite does if the process had went into the test path. Otherwise + // tests will fail on bots. + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableTestCompositor)) { + new_command_line.AppendSwitch(switches::kTestCompositor); + } +#endif + base::FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); new_command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir); diff --git a/chrome/test/base/test_launcher_utils.cc b/chrome/test/base/test_launcher_utils.cc index 1f81ef9..fac13af 100644 --- a/chrome/test/base/test_launcher_utils.cc +++ b/chrome/test/base/test_launcher_utils.cc @@ -12,6 +12,7 @@ #include "base/strings/string_number_conversions.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "ui/gl/gl_switches.h" #if defined(USE_AURA) #include "ui/views/corewm/corewm_switches.h" @@ -96,4 +97,14 @@ bool OverrideUserDataDir(const base::FilePath& user_data_dir) { return success; } +bool OverrideGLImplementation(CommandLine* command_line, + const std::string& implementation_name) { + if (command_line->HasSwitch(switches::kUseGL)) + return false; + + command_line->AppendSwitchASCII(switches::kUseGL, implementation_name); + + return true; +} + } // namespace test_launcher_utils diff --git a/chrome/test/base/test_launcher_utils.h b/chrome/test/base/test_launcher_utils.h index 18d46b5..242be69 100644 --- a/chrome/test/base/test_launcher_utils.h +++ b/chrome/test/base/test_launcher_utils.h @@ -23,6 +23,12 @@ void PrepareBrowserCommandLineForTests(CommandLine* command_line); bool OverrideUserDataDir( const base::FilePath& user_data_dir) WARN_UNUSED_RESULT; +// Override the GL implementation. The names are the same as for the --use-gl +// command line switch. Use the constants in the gfx namespace. +bool OverrideGLImplementation( + CommandLine* command_line, + const std::string& implementation_name) WARN_UNUSED_RESULT; + } // namespace test_launcher_utils #endif // CHROME_TEST_BASE_TEST_LAUNCHER_UTILS_H_ diff --git a/chrome/test/base/view_event_test_base.cc b/chrome/test/base/view_event_test_base.cc index 4654a7e..aabfb25 100644 --- a/chrome/test/base/view_event_test_base.cc +++ b/chrome/test/base/view_event_test_base.cc @@ -22,9 +22,6 @@ #include "ash/shell.h" #include "ash/test/test_session_state_delegate.h" #include "ash/test/test_shell_delegate.h" -#if defined(OS_WIN) -#include "ui/compositor/compositor.h" -#endif #endif #if defined(USE_AURA) @@ -104,26 +101,20 @@ void ViewEventTestBase::SetUp() { // interactive_ui_tests is brought up on that platform. gfx::Screen::SetScreenInstance( gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); - - // The ContextFactory must exist before any Compositors are created. The - // ash::Shell code path below handles this, but since we skip it we must - // do this here. - bool allow_test_contexts = true; - ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts); -#else // !OS_WIN +#else // Ash Shell can't just live on its own without a browser process, we need to // also create the message center. message_center::MessageCenter::Initialize(); #if defined(OS_CHROMEOS) chromeos::CrasAudioHandler::InitializeForTesting(); -#endif // OS_CHROMEOS +#endif ash::test::TestShellDelegate* shell_delegate = new ash::test::TestShellDelegate(); ash::Shell::CreateInstance(shell_delegate); shell_delegate->test_session_state_delegate() ->SetActiveUserSessionStarted(true); context = ash::Shell::GetPrimaryRootWindow(); -#endif // !OS_WIN +#endif #elif defined(USE_AURA) // Instead of using the ash shell, use an AuraTestHelper to create and manage // the test screen. @@ -131,7 +122,7 @@ void ViewEventTestBase::SetUp() { new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); aura_test_helper_->SetUp(); context = aura_test_helper_->root_window(); -#endif // USE_AURA +#endif window_ = views::Widget::CreateWindowWithContext(this, context); } diff --git a/chrome/test/gpu/gpu_feature_browsertest.cc b/chrome/test/gpu/gpu_feature_browsertest.cc index 8a6af16..7ace688 100644 --- a/chrome/test/gpu/gpu_feature_browsertest.cc +++ b/chrome/test/gpu/gpu_feature_browsertest.cc @@ -14,6 +14,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/tracing.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/gpu_data_manager.h" @@ -23,7 +24,8 @@ #include "gpu/config/gpu_info.h" #include "gpu/config/gpu_test_config.h" #include "net/base/net_util.h" -#include "ui/gl/gl_implementation.h" +#include "ui/compositor/compositor_setup.h" +#include "ui/gl/gl_switches.h" #if defined(OS_MACOSX) #include "ui/gl/io_surface_support_mac.h" @@ -47,14 +49,7 @@ const char kWebGLCreationEvent[] = "DrawingBufferCreation"; class GpuFeatureTest : public InProcessBrowserTest { public: - GpuFeatureTest() : category_patterns_("test_gpu") {} - - virtual void SetUp() OVERRIDE { - // We expect to use real GL contexts for these tests. - UseRealGLContexts(); - - InProcessBrowserTest::SetUp(); - } + GpuFeatureTest() : category_patterns_("test_gpu"), gpu_enabled_(false) {} virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { base::FilePath test_dir; @@ -63,7 +58,18 @@ class GpuFeatureTest : public InProcessBrowserTest { } virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + // Do not use mesa if real GPU is required. + if (!command_line->HasSwitch(switches::kUseGpuInTests)) { +#if !defined(OS_MACOSX) + CHECK(test_launcher_utils::OverrideGLImplementation( + command_line, gfx::kGLImplementationOSMesaName)) << + "kUseGL must not be set by test framework code!"; +#endif + } else { + gpu_enabled_ = true; + } command_line->AppendSwitch(switches::kDisablePopupBlocking); + ui::DisableTestCompositor(); command_line->AppendSwitchASCII(switches::kWindowSize, "400,300"); } @@ -79,7 +85,7 @@ class GpuFeatureTest : public InProcessBrowserTest { bool new_tab) { #if defined(OS_LINUX) && !defined(NDEBUG) // Bypass tests on GPU Linux Debug bots. - if (gfx::GetGLImplementation() != gfx::kGLImplementationOSMesaGL) + if (gpu_enabled_) return; #endif @@ -111,7 +117,7 @@ class GpuFeatureTest : public InProcessBrowserTest { bool event_expected = false) { #if defined(OS_LINUX) && !defined(NDEBUG) // Bypass tests on GPU Linux Debug bots. - if (gfx::GetGLImplementation() != gfx::kGLImplementationOSMesaGL) + if (gpu_enabled_) return; #endif #if defined(OS_MACOSX) @@ -167,6 +173,7 @@ class GpuFeatureTest : public InProcessBrowserTest { scoped_ptr<TraceAnalyzer> analyzer_; std::string category_patterns_; std::string trace_events_json_; + bool gpu_enabled_; }; #if defined(OS_WIN) || defined(ADDRESS_SANITIZER) @@ -301,7 +308,9 @@ IN_PROC_BROWSER_TEST_F(GpuFeatureTest, MultisamplingAllowed) { gpu::GPU_FEATURE_TYPE_MULTISAMPLING)); // Multisampling is not supported if running on top of osmesa. - if (gfx::GetGLImplementation() != gfx::kGLImplementationOSMesaGL) + std::string use_gl = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kUseGL); + if (use_gl == gfx::kGLImplementationOSMesaName) return; // Linux Intel uses mesa driver, where multisampling is not supported. @@ -549,4 +558,4 @@ IN_PROC_BROWSER_TEST_F(GpuFeatureTest, IOSurfaceReuse) { } #endif -} // namespace +} // namespace anonymous diff --git a/chrome/test/gpu/webgl_infobar_browsertest.cc b/chrome/test/gpu/webgl_infobar_browsertest.cc index e21df14..35071ae 100644 --- a/chrome/test/gpu/webgl_infobar_browsertest.cc +++ b/chrome/test/gpu/webgl_infobar_browsertest.cc @@ -51,6 +51,13 @@ void SimulateGPUCrash(Browser* browser) { class WebGLInfobarTest : public InProcessBrowserTest { protected: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + // GPU tests require gpu acceleration. +#if !defined(OS_MACOSX) + command_line->AppendSwitchASCII( + switches::kUseGL, gfx::kGLImplementationOSMesaName); +#endif + } virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { base::FilePath test_dir; ASSERT_TRUE(PathService::Get(content::DIR_TEST_DATA, &test_dir)); diff --git a/chrome/test/ppapi/ppapi_test.cc b/chrome/test/ppapi/ppapi_test.cc index 6054c45d..5973877 100644 --- a/chrome/test/ppapi/ppapi_test.cc +++ b/chrome/test/ppapi/ppapi_test.cc @@ -22,6 +22,7 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/test/base/test_launcher_utils.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/dom_operation_notification_details.h" #include "content/public/browser/notification_service.h" @@ -116,6 +117,15 @@ PPAPITestBase::PPAPITestBase() { } void PPAPITestBase::SetUpCommandLine(CommandLine* command_line) { + // Do not use mesa if real GPU is required. + if (!command_line->HasSwitch(switches::kUseGpuInTests)) { +#if !defined(OS_MACOSX) + CHECK(test_launcher_utils::OverrideGLImplementation( + command_line, gfx::kGLImplementationOSMesaName)) << + "kUseGL must not be set by test framework code!"; +#endif + } + // The test sends us the result via a cookie. command_line->AppendSwitch(switches::kEnableFileCookies); diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 5e0e248..3dd2263 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -58,6 +58,10 @@ #include "base/win/windows_version.h" #endif +#if defined(USE_AURA) +#include "ui/compositor/compositor_switches.h" +#endif + using base::Time; using base::TimeDelta; using base::TimeTicks; @@ -204,6 +208,12 @@ void UITestBase::SetLaunchSwitches() { } if (!test_name_.empty()) launch_arguments_.AppendSwitchASCII(switches::kTestName, test_name_); +#if defined(USE_AURA) + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableTestCompositor)) { + launch_arguments_.AppendSwitch(switches::kTestCompositor); + } +#endif } void UITestBase::SetUpProfile() { diff --git a/components/test/run_all_unittests.cc b/components/test/run_all_unittests.cc index a881798..49032ba 100644 --- a/components/test/run_all_unittests.cc +++ b/components/test/run_all_unittests.cc @@ -6,6 +6,7 @@ #include "base/test/test_suite.h" #include "content/public/test/test_content_client_initializer.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/compositor/compositor_setup.h" namespace components { @@ -33,6 +34,9 @@ class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { int main(int argc, char** argv) { base::TestSuite test_suite(argc, argv); + // Mock out the compositor on platforms that use it. + ui::SetupTestCompositor(); + // The listener will set up common test environment for all components unit // tests. testing::TestEventListeners& listeners = diff --git a/content/browser/aura/gpu_process_transport_factory.cc b/content/browser/aura/gpu_process_transport_factory.cc index bc9e414..dda8bc878 100644 --- a/content/browser/aura/gpu_process_transport_factory.cc +++ b/content/browser/aura/gpu_process_transport_factory.cc @@ -319,8 +319,6 @@ void GpuProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { gl_helper_.reset(); } -bool GpuProcessTransportFactory::DoesCreateTestContexts() { return false; } - ui::ContextFactory* GpuProcessTransportFactory::AsContextFactory() { return this; } diff --git a/content/browser/aura/gpu_process_transport_factory.h b/content/browser/aura/gpu_process_transport_factory.h index 72b88d5..9e40b5c 100644 --- a/content/browser/aura/gpu_process_transport_factory.h +++ b/content/browser/aura/gpu_process_transport_factory.h @@ -35,7 +35,7 @@ class GpuProcessTransportFactory scoped_ptr<WebGraphicsContext3DCommandBufferImpl> CreateOffscreenCommandBufferContext(); - // ContextFactory implementation. + // ImageTransportFactory implementation. virtual scoped_ptr<WebKit::WebGraphicsContext3D> CreateOffscreenContext() OVERRIDE; virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface( @@ -46,9 +46,6 @@ class GpuProcessTransportFactory virtual void RemoveReflector( scoped_refptr<ui::Reflector> reflector) OVERRIDE; virtual void RemoveCompositor(ui::Compositor* compositor) OVERRIDE; - virtual bool DoesCreateTestContexts() OVERRIDE; - - // ImageTransportFactory implementation. virtual ui::ContextFactory* AsContextFactory() OVERRIDE; virtual gfx::GLSurfaceHandle CreateSharedSurfaceHandle() OVERRIDE; virtual void DestroySharedSurfaceHandle( diff --git a/content/browser/aura/image_transport_factory.cc b/content/browser/aura/image_transport_factory.cc index 28b04bf..2e92dd0 100644 --- a/content/browser/aura/image_transport_factory.cc +++ b/content/browser/aura/image_transport_factory.cc @@ -8,12 +8,7 @@ #include "content/browser/aura/gpu_process_transport_factory.h" #include "content/browser/aura/no_transport_image_transport_factory.h" #include "content/public/common/content_switches.h" -#include "ui/compositor/compositor.h" -#include "ui/compositor/compositor_switches.h" - -#if defined(OS_CHROMEOS) -#include "base/chromeos/chromeos_version.h" -#endif +#include "ui/compositor/compositor_setup.h" namespace content { @@ -21,32 +16,15 @@ namespace { ImageTransportFactory* g_factory; } - -static bool UseTestContextAndTransportFactory() { -#if defined(OS_CHROMEOS) - // If the test is running on the chromeos envrionment (such as - // device or vm bots), always use real contexts. - if (base::chromeos::IsRunningOnChromeOS()) - return false; -#endif - - // Only used if the enable command line flag is used. - CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (!command_line->HasSwitch(switches::kTestCompositor)) - return false; - - // The disable command line flag preempts the enable flag. - if (!command_line->HasSwitch(switches::kDisableTestCompositor)) - return true; - - return false; -} - // static void ImageTransportFactory::Initialize() { - if (UseTestContextAndTransportFactory()) { - g_factory = - new NoTransportImageTransportFactory(new ui::TestContextFactory); + CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kTestCompositor)) { + ui::SetupTestCompositor(); + } + if (ui::IsTestCompositorEnabled()) { + g_factory = new NoTransportImageTransportFactory( + new ui::TestContextFactory); } else { g_factory = new GpuProcessTransportFactory; } diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc index 4fc2ae8..5e6d887f 100644 --- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc +++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc @@ -247,11 +247,6 @@ class BrowserPluginHostTest : public ContentBrowserTest { content::BrowserPluginGuestManager::set_factory_for_testing( TestBrowserPluginHostFactory::GetInstance()); - // On legacy windows, the AcceptDragEvents test needs this to pass. -#if defined(OS_WIN) && !defined(USE_AURA) - UseRealGLBindings(); -#endif - ContentBrowserTest::SetUp(); } virtual void TearDown() OVERRIDE { diff --git a/content/browser/gpu/gpu_info_browsertest.cc b/content/browser/gpu/gpu_info_browsertest.cc index d555d1d..72487d4 100644 --- a/content/browser/gpu/gpu_info_browsertest.cc +++ b/content/browser/gpu/gpu_info_browsertest.cc @@ -11,6 +11,7 @@ #include "content/public/browser/gpu_data_manager_observer.h" #include "content/public/common/content_switches.h" #include "content/test/content_browser_test.h" +#include "ui/compositor/compositor_setup.h" namespace content { @@ -73,11 +74,9 @@ class GpuInfoBrowserTest : public ContentBrowserTest { : message_loop_(base::MessageLoop::TYPE_UI) { } - virtual void SetUp() { - // We expect real pixel output for these tests. - UseRealGLContexts(); - - ContentBrowserTest::SetUp(); + virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { + ContentBrowserTest::SetUpInProcessBrowserTestFixture(); + ui::DisableTestCompositor(); } base::MessageLoop* GetMessageLoop() { return &message_loop_; } diff --git a/content/browser/gpu/gpu_ipc_browsertests.cc b/content/browser/gpu/gpu_ipc_browsertests.cc index 0ee93db..7b7186c 100644 --- a/content/browser/gpu/gpu_ipc_browsertests.cc +++ b/content/browser/gpu/gpu_ipc_browsertests.cc @@ -26,6 +26,18 @@ class ContextTestBase : public content::ContentBrowserTest { ContentBrowserTest::SetUpOnMainThread(); } + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + // TODO(Hubbe): This code is very similar to some code in + // test/gpu/gpu_feature_browsertest.cc, and should really be + // shared in a common location. + if (!command_line->HasSwitch(switches::kUseGpuInTests)) { + CHECK(!command_line->HasSwitch(switches::kUseGL)) + << "kUseGL must not be set by test framework code!"; + command_line->AppendSwitchASCII(switches::kUseGL, + gfx::kGLImplementationOSMesaName); + } + } + virtual void TearDownOnMainThread() OVERRIDE { // Must delete the context first. context_.reset(NULL); diff --git a/content/browser/gpu/gpu_pixel_browsertest.cc b/content/browser/gpu/gpu_pixel_browsertest.cc index 5909321..dc0b91f 100644 --- a/content/browser/gpu/gpu_pixel_browsertest.cc +++ b/content/browser/gpu/gpu_pixel_browsertest.cc @@ -24,6 +24,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkColor.h" +#include "ui/compositor/compositor_setup.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/size.h" #include "ui/gl/gl_switches.h" @@ -105,13 +106,6 @@ class GpuPixelBrowserTest : public ContentBrowserTest { ref_img_option_(kReferenceImageNone) { } - virtual void SetUp() { - // We expect real pixel output for these tests. - UseRealGLContexts(); - - ContentBrowserTest::SetUp(); - } - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { command_line->AppendSwitchASCII(switches::kTestGLLib, "libllvmpipe.so"); @@ -156,6 +150,8 @@ class GpuPixelBrowserTest : public ContentBrowserTest { ReplaceFirstSubstringAfterOffset( &test_name_, 0, test_status_prefixes[i], std::string()); } + + ui::DisableTestCompositor(); } // If the existing ref image was saved from an revision older than the diff --git a/content/browser/media/media_browsertest.cc b/content/browser/media/media_browsertest.cc index 1d83035..e5bc620 100644 --- a/content/browser/media/media_browsertest.cc +++ b/content/browser/media/media_browsertest.cc @@ -26,14 +26,6 @@ const char MediaBrowserTest::kEnded[] = "ENDED"; const char MediaBrowserTest::kError[] = "ERROR"; const char MediaBrowserTest::kFailed[] = "FAILED"; -void MediaBrowserTest::SetUp() { - // TODO(danakj): The GPU Video Decoder needs real GL bindings. - // crbug.com/269087 - UseRealGLBindings(); - - ContentBrowserTest::SetUp(); -} - void MediaBrowserTest::RunMediaTestPage( const char* html_page, std::vector<StringPair>* query_params, const char* expected, bool http) { diff --git a/content/browser/media/media_browsertest.h b/content/browser/media/media_browsertest.h index 013283b..5da684e 100644 --- a/content/browser/media/media_browsertest.h +++ b/content/browser/media/media_browsertest.h @@ -17,8 +17,6 @@ class MediaBrowserTest : public ContentBrowserTest { typedef std::pair<const char*, const char*> StringPair; - virtual void SetUp() OVERRIDE; - // Runs a html page with a list of URL query parameters. // If http is true, the test starts a local http test server to load the test // page, otherwise a local file URL is loaded inside the content shell. diff --git a/content/browser/renderer_host/render_widget_host_view_browsertest.cc b/content/browser/renderer_host/render_widget_host_view_browsertest.cc index 2b47ff1..5dc1ed4 100644 --- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc +++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc @@ -28,6 +28,7 @@ #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkDevice.h" #include "ui/base/ui_base_switches.h" +#include "ui/compositor/compositor_setup.h" #include "ui/gfx/size_conversions.h" #include "ui/gl/gl_switches.h" @@ -211,18 +212,6 @@ class RenderWidgetHostViewBrowserTest : public ContentBrowserTest { class CompositingRenderWidgetHostViewBrowserTest : public RenderWidgetHostViewBrowserTest { public: - virtual void SetUp() OVERRIDE { - // We expect real pixel output for these tests. - UseRealGLContexts(); - - // On legacy windows, these tests need real GL bindings to pass. -#if defined(OS_WIN) && !defined(USE_AURA) - UseRealGLBindings(); -#endif - - RenderWidgetHostViewBrowserTest::SetUp(); - } - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { // Note: Not appending kForceCompositingMode switch here, since not all bots // support compositing. Some bots will run with compositing on, and others @@ -341,6 +330,15 @@ class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { // is enabled. IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, CopyFromBackingStore) { +#if defined(USE_AURA) + if (ui::IsTestCompositorEnabled()) { + LOG(WARNING) << ("Blindly passing this test: Aura test compositor doesn't " + "support copying from backing store."); + // TODO(jbauman): Aura test compositor should support copying from backing + // store. http://crbug.com/268644 + return; + } +#endif RunBasicCopyFromBackingStoreTest(); } @@ -383,7 +381,6 @@ IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, "not supported on this platform."); return; } - base::RunLoop run_loop; scoped_refptr<media::VideoFrame> dest = media::VideoFrame::CreateBlackFrame(frame_size()); @@ -417,6 +414,15 @@ IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, "supported on this platform."); return; } +#if defined(USE_AURA) + if (ui::IsTestCompositorEnabled()) { + LOG(WARNING) << ("Blindly passing this test: Aura test compositor doesn't " + "support frame subscription."); + // TODO(miu): Aura test compositor should support frame subscription for + // testing. http://crbug.com/240572 + return; + } +#endif base::RunLoop run_loop; scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber( @@ -444,6 +450,16 @@ IN_PROC_BROWSER_TEST_F(CompositingRenderWidgetHostViewBrowserTest, CopyTwice) { return; } +#if defined(USE_AURA) + if (ui::IsTestCompositorEnabled()) { + LOG(WARNING) << ("Blindly passing this test: Aura test compositor doesn't " + "support copying to video frame."); + // TODO(jbauman): Aura test compositor should support copying to video + // frame. http://crbug.com/268644 + return; + } +#endif + base::RunLoop run_loop; scoped_refptr<media::VideoFrame> first_output = media::VideoFrame::CreateBlackFrame(frame_size()); @@ -480,6 +496,23 @@ class CompositingRenderWidgetHostViewBrowserTestTabCapture allowable_error_(0), test_url_("data:text/html,<!doctype html>") {} + virtual void SetUp() OVERRIDE { + ui::DisableTestCompositor(); + CompositingRenderWidgetHostViewBrowserTest::SetUp(); + } + + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + // TODO(Hubbe): This code is very similar to some code in + // gpu_feature_browsertest.cc, and should really be shared in a common + // location. + if (!command_line->HasSwitch(switches::kUseGpuInTests)) { + CHECK(!command_line->HasSwitch(switches::kUseGL)) + << "kUseGL must not be set by test framework code!"; + command_line->AppendSwitchASCII(switches::kUseGL, + gfx::kGLImplementationOSMesaName); + } + } + void CopyFromCompositingSurfaceCallback(base::Closure quit_callback, bool result, const SkBitmap& bitmap) { diff --git a/content/browser/web_contents/web_contents_view_aura_browsertest.cc b/content/browser/web_contents/web_contents_view_aura_browsertest.cc index e0f34ab..caa07a4 100644 --- a/content/browser/web_contents/web_contents_view_aura_browsertest.cc +++ b/content/browser/web_contents/web_contents_view_aura_browsertest.cc @@ -24,6 +24,7 @@ #include "ui/aura/root_window.h" #include "ui/aura/test/event_generator.h" #include "ui/aura/window.h" +#include "ui/compositor/compositor_setup.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" namespace content { @@ -86,11 +87,6 @@ class WebContentsViewAuraTest : public ContentBrowserTest { : screenshot_manager_(NULL) { } - virtual void SetUp() OVERRIDE { - // TODO(jbauman): Remove this. http://crbug.com/268644 - UseRealGLContexts(); - } - // Executes the javascript synchronously and makes sure the returned value is // freed properly. void ExecuteSyncJSFunction(RenderViewHost* rvh, const std::string& jscript) { @@ -330,6 +326,9 @@ IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, // gesture. IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, OverscrollScreenshot) { + // http://crbug.com/268644 + if (ui::IsTestCompositorEnabled()) + return; ASSERT_NO_FATAL_FAILURE( StartTestWithPage("files/overscroll_navigation.html")); WebContentsImpl* web_contents = @@ -424,6 +423,9 @@ IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, // RenderViewHost to be swapped out. IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ScreenshotForSwappedOutRenderViews) { + // http://crbug.com/268644 + if (ui::IsTestCompositorEnabled()) + return; ASSERT_NO_FATAL_FAILURE( StartTestWithPage("files/overscroll_navigation.html")); // Create a new server with a different site. diff --git a/content/common/gpu/client/gl_helper.cc b/content/common/gpu/client/gl_helper.cc index 0a10d4a..e8afdd1 100644 --- a/content/common/gpu/client/gl_helper.cc +++ b/content/common/gpu/client/gl_helper.cc @@ -154,7 +154,7 @@ class GLHelper::CopyTextureToImpl : const base::Callback<void(bool)>& callback); void ReadbackPlane(TextureFrameBufferPair* source, - const scoped_refptr<media::VideoFrame>& target, + media::VideoFrame* target, int plane, int size_shift, const gfx::Rect& dst_subrect, @@ -232,7 +232,7 @@ class GLHelper::CopyTextureToImpl : virtual void ReadbackYUV( const gpu::Mailbox& mailbox, uint32 sync_point, - const scoped_refptr<media::VideoFrame>& target, + media::VideoFrame* target, const base::Callback<void(bool)>& callback) OVERRIDE; virtual ScalerInterface* scaler() OVERRIDE { @@ -270,7 +270,7 @@ class GLHelper::CopyTextureToImpl : virtual void ReadbackYUV( const gpu::Mailbox& mailbox, uint32 sync_point, - const scoped_refptr<media::VideoFrame>& target, + media::VideoFrame* target, const base::Callback<void(bool)>& callback) OVERRIDE; virtual ScalerInterface* scaler() OVERRIDE { @@ -729,7 +729,7 @@ void GLHelper::CopyTextureFullImage(WebKit::WebGLId texture, void GLHelper::CopyTextureToImpl::ReadbackPlane( TextureFrameBufferPair* source, - const scoped_refptr<media::VideoFrame>& target, + media::VideoFrame* target, int plane, int size_shift, const gfx::Rect& dst_subrect, @@ -813,17 +813,11 @@ GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUVImpl( DCHECK(!(dst_subrect.y() & 1)); } -static void CallbackKeepingVideoFrameAlive( - scoped_refptr<media::VideoFrame> video_frame, - const base::Callback<void(bool)>& callback, - bool success) { - callback.Run(success); -} void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( const gpu::Mailbox& mailbox, uint32 sync_point, - const scoped_refptr<media::VideoFrame>& target, + media::VideoFrame *target, const base::Callback<void(bool)>& callback) { WebGLId mailbox_texture = copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); @@ -844,8 +838,7 @@ void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( return; } - // Read back planes, one at a time. Keep the video frame alive while doing the - // readback. + // Read back planes, one at a time. copy_impl_->ReadbackPlane(y_.texture_and_framebuffer(), target, media::VideoFrame::kYPlane, @@ -863,9 +856,7 @@ void GLHelper::CopyTextureToImpl::ReadbackYUVImpl::ReadbackYUV( media::VideoFrame::kVPlane, 1, dst_subrect_, - base::Bind(&CallbackKeepingVideoFrameAlive, - target, - callback)); + callback); context_->bindFramebuffer(GL_FRAMEBUFFER, 0); media::LetterboxYUV(target, dst_subrect_); } @@ -942,7 +933,7 @@ GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV_MRT( void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( const gpu::Mailbox& mailbox, uint32 sync_point, - const scoped_refptr<media::VideoFrame>& target, + media::VideoFrame *target, const base::Callback<void(bool)>& callback) { WebGLId mailbox_texture = copy_impl_->ConsumeMailboxToTexture(mailbox, sync_point); @@ -985,9 +976,7 @@ void GLHelper::CopyTextureToImpl::ReadbackYUV_MRT::ReadbackYUV( media::VideoFrame::kVPlane, 1, dst_subrect_, - base::Bind(&CallbackKeepingVideoFrameAlive, - target, - callback)); + callback); context_->bindFramebuffer(GL_FRAMEBUFFER, 0); media::LetterboxYUV(target, dst_subrect_); } diff --git a/content/common/gpu/client/gl_helper.h b/content/common/gpu/client/gl_helper.h index b874f97..edc274c 100644 --- a/content/common/gpu/client/gl_helper.h +++ b/content/common/gpu/client/gl_helper.h @@ -383,7 +383,7 @@ public: virtual void ReadbackYUV( const gpu::Mailbox& mailbox, uint32 sync_point, - const scoped_refptr<media::VideoFrame>& target, + media::VideoFrame* target, const base::Callback<void(bool)>& callback) = 0; virtual GLHelper::ScalerInterface* scaler() = 0; }; diff --git a/content/public/test/browser_test_base.cc b/content/public/test/browser_test_base.cc index 9e14f7f..25d6330 100644 --- a/content/public/test/browser_test_base.cc +++ b/content/public/test/browser_test_base.cc @@ -13,9 +13,6 @@ #include "content/public/common/main_function_params.h" #include "content/public/test/test_utils.h" #include "net/test/embedded_test_server/embedded_test_server.h" -#include "ui/compositor/compositor_switches.h" -#include "ui/gl/gl_implementation.h" -#include "ui/gl/gl_switches.h" #if defined(OS_POSIX) #include "base/process/process_handle.h" @@ -67,9 +64,7 @@ extern int BrowserMain(const MainFunctionParams&); BrowserTestBase::BrowserTestBase() : embedded_test_server_( new net::test_server::EmbeddedTestServer( - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))), - allow_test_contexts_(true), - allow_osmesa_(true) { + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { #if defined(OS_MACOSX) base::mac::SetOverrideAmIBundled(true); base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); @@ -103,33 +98,6 @@ void BrowserTestBase::SetUp() { new base::Closure( base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); -#if defined(USE_AURA) - // Use test contexts for browser tests unless they override and force us to - // use a real context. - if (allow_test_contexts_) - command_line->AppendSwitch(switches::kTestCompositor); -#endif - - // When using real GL contexts, we usually use OSMesa as this works on all - // bots. The command line can override this behaviour to use a real GPU. - if (command_line->HasSwitch(switches::kUseGpuInTests)) - allow_osmesa_ = false; - -#if defined(OS_MACOSX) - // On Mac we always use a real GPU. - allow_osmesa_ = false; -#endif - - if (command_line->HasSwitch(switches::kUseGL)) { - NOTREACHED() << - "kUseGL should not be used with tests. Try kUseGpuInTests instead."; - } - - if (allow_osmesa_) { - command_line->AppendSwitchASCII( - switches::kUseGL, gfx::kGLImplementationOSMesaName); - } - SetUpInProcessBrowserTestFixture(); #if defined(OS_ANDROID) BrowserMainRunner::Create()->Initialize(params); diff --git a/content/public/test/browser_test_base.h b/content/public/test/browser_test_base.h index bc5b390..26f7c07 100644 --- a/content/public/test/browser_test_base.h +++ b/content/public/test/browser_test_base.h @@ -109,14 +109,6 @@ class BrowserTestBase : public testing::Test { // returns. void PostTaskToInProcessRendererAndWait(const base::Closure& task); - // Call this before SetUp() to use real GL contexts in Compositor for the - // test. - void UseRealGLContexts() { allow_test_contexts_ = false; } - - // Call this before SetUp() to use real GL drivers instead of OSMesa for the - // test. - void UseRealGLBindings() { allow_osmesa_ = false; } - private: void ProxyRunTestOnMainThreadLoop(); @@ -126,14 +118,6 @@ class BrowserTestBase : public testing::Test { // Embedded test server, cheap to create, started on demand. scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; - // When false, the ui::Compositor will be forced to use real GL contexts for - // the test, so that it produces real pixel output. - bool allow_test_contexts_; - - // When false, the GL backend will use a real GPU. When true, it uses OSMesa - // to run GL on the CPU in a way that works across all platforms. - bool allow_osmesa_; - #if defined(OS_POSIX) bool handle_sigterm_; #endif diff --git a/content/public/test/content_test_suite_base.cc b/content/public/test/content_test_suite_base.cc index 5bf5b5e..459c37d 100644 --- a/content/public/test/content_test_suite_base.cc +++ b/content/public/test/content_test_suite_base.cc @@ -16,6 +16,7 @@ #include "media/base/media.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/ui_base_paths.h" +#include "ui/compositor/compositor_setup.h" #if defined(OS_ANDROID) #include "base/android/jni_android.h" @@ -71,6 +72,9 @@ void ContentTestSuiteBase::Initialize() { RegisterPathProvider(); ui::RegisterPathProvider(); + // Mock out the compositor on platforms that use it. + ui::SetupTestCompositor(); + testing::UnitTest::GetInstance()->listeners().Append( new ContentTestSuiteBaseListener); } diff --git a/ui/aura/test/aura_test_helper.cc b/ui/aura/test/aura_test_helper.cc index 0bcc515a..b180190 100644 --- a/ui/aura/test/aura_test_helper.cc +++ b/ui/aura/test/aura_test_helper.cc @@ -16,7 +16,6 @@ #include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_stacking_client.h" #include "ui/base/ime/dummy_input_method.h" -#include "ui/compositor/compositor.h" #include "ui/compositor/layer_animator.h" #include "ui/compositor/scoped_animation_duration_scale_mode.h" #include "ui/gfx/screen.h" @@ -60,11 +59,6 @@ AuraTestHelper::~AuraTestHelper() { void AuraTestHelper::SetUp() { setup_called_ = true; - - // The ContextFactory must exist before any Compositors are created. - bool allow_test_contexts = true; - ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts); - Env::GetInstance(); test_screen_.reset(TestScreen::Create()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); diff --git a/ui/aura/test/test_suite.cc b/ui/aura/test/test_suite.cc index abd3422..5b76a17 100644 --- a/ui/aura/test/test_suite.cc +++ b/ui/aura/test/test_suite.cc @@ -9,6 +9,7 @@ #include "build/build_config.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" +#include "ui/compositor/compositor_setup.h" #include "ui/gfx/gfx_paths.h" #include "ui/gl/gl_implementation.h" @@ -27,6 +28,8 @@ void AuraTestSuite::Initialize() { // Force unittests to run using en-US so if we test against string // output, it'll pass regardless of the system language. ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); + + ui::SetupTestCompositor(); } void AuraTestSuite::Shutdown() { diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc index 5739bbf..c976ecf 100644 --- a/ui/compositor/compositor.cc +++ b/ui/compositor/compositor.cc @@ -50,9 +50,10 @@ enum SwapType { READPIXELS_SWAP, }; -bool g_compositor_initialized = false; base::Thread* g_compositor_thread = NULL; +bool g_test_compositor_enabled = false; + ui::ContextFactory* g_implicit_factory = NULL; ui::ContextFactory* g_context_factory = NULL; @@ -76,13 +77,39 @@ class PendingSwap { DISALLOW_COPY_AND_ASSIGN(PendingSwap); }; +void SetupImplicitFactory() { + // We leak the implicit factory so that we don't race with the tear down of + // the gl_bindings. + DCHECK(!g_context_factory); + DCHECK(!g_implicit_factory); + if (g_test_compositor_enabled) { + g_implicit_factory = new ui::TestContextFactory; + } else { + DVLOG(1) << "Using DefaultContextFactory"; + scoped_ptr<ui::DefaultContextFactory> instance( + new ui::DefaultContextFactory()); + if (instance->Initialize()) + g_implicit_factory = instance.release(); + } + g_context_factory = g_implicit_factory; +} + +void ResetImplicitFactory() { + if (!g_implicit_factory || g_context_factory != g_implicit_factory) + return; + delete g_implicit_factory; + g_implicit_factory = NULL; + g_context_factory = NULL; +} + } // namespace namespace ui { // static ContextFactory* ContextFactory::GetInstance() { - DCHECK(g_context_factory); + if (!g_context_factory) + SetupImplicitFactory(); return g_context_factory; } @@ -153,8 +180,6 @@ DefaultContextFactory::OffscreenContextProviderForCompositorThread() { void DefaultContextFactory::RemoveCompositor(Compositor* compositor) { } -bool DefaultContextFactory::DoesCreateTestContexts() { return false; } - scoped_ptr<WebKit::WebGraphicsContext3D> DefaultContextFactory::CreateContextCommon(Compositor* compositor, bool offscreen) { @@ -223,8 +248,6 @@ TestContextFactory::OffscreenContextProviderForCompositorThread() { void TestContextFactory::RemoveCompositor(Compositor* compositor) { } -bool TestContextFactory::DoesCreateTestContexts() { return true; } - Texture::Texture(bool flipped, const gfx::Size& size, float device_scale_factor) : size_(size), flipped_(flipped), @@ -387,9 +410,6 @@ Compositor::Compositor(CompositorDelegate* delegate, next_draw_is_resize_(false), disable_schedule_composite_(false), compositor_lock_(NULL) { - DCHECK(g_compositor_initialized) - << "Compositor::Initialize must be called before creating a Compositor."; - root_web_layer_ = cc::Layer::Create(); root_web_layer_->SetAnchorPoint(gfx::PointF(0.f, 0.f)); @@ -397,9 +417,7 @@ Compositor::Compositor(CompositorDelegate* delegate, cc::LayerTreeSettings settings; settings.refresh_rate = - ContextFactory::GetInstance()->DoesCreateTestContexts() - ? kTestRefreshRate - : kDefaultRefreshRate; + g_test_compositor_enabled ? kTestRefreshRate : kDefaultRefreshRate; settings.partial_swap_enabled = !command_line->HasSwitch(cc::switches::kUIDisablePartialSwap); settings.per_tile_painting_enabled = @@ -434,8 +452,6 @@ Compositor::Compositor(CompositorDelegate* delegate, } Compositor::~Compositor() { - DCHECK(g_compositor_initialized); - CancelCompositorLock(); DCHECK(!compositor_lock_); @@ -452,41 +468,6 @@ Compositor::~Compositor() { } // static -void Compositor::InitializeContextFactoryForTests(bool allow_test_contexts) { - DCHECK(!g_context_factory) << "ContextFactory already initialized."; - DCHECK(!g_implicit_factory) << - "ContextFactory for tests already initialized."; - - bool use_test_contexts = true; - - // Always use test contexts unless the disable command line flag is used. - CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kDisableTestCompositor)) - use_test_contexts = false; - -#if defined(OS_CHROMEOS) - // If the test is running on the chromeos envrionment (such as - // device or vm bots), always use real contexts. - if (base::chromeos::IsRunningOnChromeOS()) - use_test_contexts = false; -#endif - - if (!allow_test_contexts) - use_test_contexts = false; - - if (use_test_contexts) { - g_implicit_factory = new ui::TestContextFactory; - } else { - DVLOG(1) << "Using DefaultContextFactory"; - scoped_ptr<ui::DefaultContextFactory> instance( - new ui::DefaultContextFactory()); - if (instance->Initialize()) - g_implicit_factory = instance.release(); - } - g_context_factory = g_implicit_factory; -} - -// static void Compositor::Initialize() { #if defined(OS_CHROMEOS) bool use_thread = !CommandLine::ForCurrentProcess()->HasSwitch( @@ -502,9 +483,6 @@ void Compositor::Initialize() { g_compositor_thread = new base::Thread("Browser Compositor"); g_compositor_thread->Start(); } - - DCHECK(!g_compositor_initialized) << "Compositor initialized twice."; - g_compositor_initialized = true; } // static @@ -522,24 +500,11 @@ scoped_refptr<base::MessageLoopProxy> Compositor::GetCompositorMessageLoop() { // static void Compositor::Terminate() { - if (g_context_factory) { - if (g_implicit_factory) { - delete g_implicit_factory; - g_implicit_factory = NULL; - } - g_context_factory = NULL; - } - if (g_compositor_thread) { - DCHECK(!g_context_factory) - << "The ContextFactory should not outlive the compositor thread."; g_compositor_thread->Stop(); delete g_compositor_thread; g_compositor_thread = NULL; } - - DCHECK(g_compositor_initialized) << "Compositor::Initialize() didn't happen."; - g_compositor_initialized = false; } void Compositor::ScheduleDraw() { @@ -786,4 +751,27 @@ void Compositor::NotifyEnd() { OnCompositingEnded(this)); } +COMPOSITOR_EXPORT void SetupTestCompositor() { + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableTestCompositor)) { + g_test_compositor_enabled = true; + } +#if defined(OS_CHROMEOS) + // If the test is running on the chromeos envrionment (such as + // device or vm bots), use the real compositor. + if (base::chromeos::IsRunningOnChromeOS()) + g_test_compositor_enabled = false; +#endif + ResetImplicitFactory(); +} + +COMPOSITOR_EXPORT void DisableTestCompositor() { + ResetImplicitFactory(); + g_test_compositor_enabled = false; +} + +COMPOSITOR_EXPORT bool IsTestCompositorEnabled() { + return g_test_compositor_enabled; +} + } // namespace ui diff --git a/ui/compositor/compositor.gyp b/ui/compositor/compositor.gyp index 57a4aaf..131a6d8 100644 --- a/ui/compositor/compositor.gyp +++ b/ui/compositor/compositor.gyp @@ -28,6 +28,7 @@ 'compositor.h', 'compositor_export.h', 'compositor_observer.h', + 'compositor_setup.h', 'compositor_switches.cc', 'compositor_switches.h', 'context_provider_from_context_factory.cc', diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h index 92cdd71..c8689b179 100644 --- a/ui/compositor/compositor.h +++ b/ui/compositor/compositor.h @@ -99,10 +99,6 @@ class COMPOSITOR_EXPORT ContextFactory { // Destroys per-compositor data. virtual void RemoveCompositor(Compositor* compositor) = 0; - - // When true, the factory uses test contexts that do not do real GL - // operations. - virtual bool DoesCreateTestContexts() = 0; }; // The default factory that creates in-process contexts. @@ -127,7 +123,6 @@ class COMPOSITOR_EXPORT DefaultContextFactory : public ContextFactory { virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForCompositorThread() OVERRIDE; virtual void RemoveCompositor(Compositor* compositor) OVERRIDE; - virtual bool DoesCreateTestContexts() OVERRIDE; bool Initialize(); @@ -166,7 +161,6 @@ class COMPOSITOR_EXPORT TestContextFactory : public ContextFactory { virtual scoped_refptr<cc::ContextProvider> OffscreenContextProviderForCompositorThread() OVERRIDE; virtual void RemoveCompositor(Compositor* compositor) OVERRIDE; - virtual bool DoesCreateTestContexts() OVERRIDE; private: scoped_refptr<ContextProviderFromContextFactory> @@ -296,14 +290,6 @@ class COMPOSITOR_EXPORT Compositor gfx::AcceleratedWidget widget); virtual ~Compositor(); - // Set up the compositor ContextFactory for a test environment. Unit tests - // that do not have a full content environment need to call this before - // initializing the Compositor. - // Some tests expect pixel output, and they should pass false for - // |allow_test_contexts|. Most unit tests should pass true. Once this has been - // called, the Initialize() and Terminate() methods should be used as normal. - static void InitializeContextFactoryForTests(bool allow_test_contexts); - static void Initialize(); static bool WasInitializedWithThread(); static scoped_refptr<base::MessageLoopProxy> GetCompositorMessageLoop(); diff --git a/ui/compositor/compositor_setup.h b/ui/compositor/compositor_setup.h new file mode 100644 index 0000000..254f389 --- /dev/null +++ b/ui/compositor/compositor_setup.h @@ -0,0 +1,29 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_COMPOSITOR_COMPOSITOR_SETUP_H_ +#define UI_COMPOSITOR_COMPOSITOR_SETUP_H_ + +#include "ui/compositor/compositor_export.h" + +namespace ui { + +// Configures the compositor in such a way that it doesn't render anything. +// Does nothing on platforms that aren't using the compositor. +#if !defined(USE_AURA) +// To centralize the ifdef to this file we define the function as doing nothing +// on all platforms that don't use a compositor. +static inline void SetupTestCompositor() {} +static inline void DisableTestCompositor() {} +#else +COMPOSITOR_EXPORT void SetupTestCompositor(); + +// Disables the test compositor so that the normal compositor is used. +COMPOSITOR_EXPORT void DisableTestCompositor(); +COMPOSITOR_EXPORT bool IsTestCompositorEnabled(); +#endif + +} // namespace ui + +#endif // UI_COMPOSITOR_COMPOSITOR_SETUP_H_ diff --git a/ui/compositor/layer_unittest.cc b/ui/compositor/layer_unittest.cc index 9385dbb..79ef288 100644 --- a/ui/compositor/layer_unittest.cc +++ b/ui/compositor/layer_unittest.cc @@ -17,6 +17,7 @@ #include "cc/test/pixel_test_utils.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/compositor/compositor_observer.h" +#include "ui/compositor/compositor_setup.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_animation_sequence.h" #include "ui/compositor/layer_animator.h" @@ -81,18 +82,13 @@ class LayerWithRealCompositorTest : public testing::Test { // Overridden from testing::Test: virtual void SetUp() OVERRIDE { - bool allow_test_contexts = false; - Compositor::InitializeContextFactoryForTests(allow_test_contexts); - Compositor::Initialize(); - + DisableTestCompositor(); const gfx::Rect host_bounds(10, 10, 500, 500); window_.reset(TestCompositorHost::Create(host_bounds)); window_->Show(); } virtual void TearDown() OVERRIDE { - window_.reset(); - Compositor::Terminate(); } Compositor* GetCompositor() { @@ -311,7 +307,43 @@ class TestCompositorObserver : public CompositorObserver { } // namespace -TEST_F(LayerWithRealCompositorTest, Draw) { +#if defined(OS_WIN) +// These are disabled on windows as they don't run correctly on the buildbot. +// Reenable once we move to the real compositor. +#define MAYBE_Delegate DISABLED_Delegate +#define MAYBE_Draw DISABLED_Draw +#define MAYBE_DrawTree DISABLED_DrawTree +#define MAYBE_Hierarchy DISABLED_Hierarchy +#define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture +#define MAYBE_DrawPixels DISABLED_DrawPixels +#define MAYBE_SetRootLayer DISABLED_SetRootLayer +#define MAYBE_CompositorObservers DISABLED_CompositorObservers +#define MAYBE_ModifyHierarchy DISABLED_ModifyHierarchy +#define MAYBE_Opacity DISABLED_Opacity +#define MAYBE_ScaleUpDown DISABLED_ScaleUpDown +#define MAYBE_ScaleReparent DISABLED_ScaleReparent +#define MAYBE_NoScaleCanvas DISABLED_NoScaleCanvas +#define MAYBE_AddRemoveThreadedAnimations DISABLED_AddRemoveThreadedAnimations +#define MAYBE_SwitchCCLayerAnimations DISABLED_SwitchCCLayerAnimations +#else +#define MAYBE_Delegate Delegate +#define MAYBE_Draw Draw +#define MAYBE_DrawTree DrawTree +#define MAYBE_Hierarchy Hierarchy +#define MAYBE_HierarchyNoTexture HierarchyNoTexture +#define MAYBE_DrawPixels DrawPixels +#define MAYBE_SetRootLayer SetRootLayer +#define MAYBE_CompositorObservers CompositorObservers +#define MAYBE_ModifyHierarchy ModifyHierarchy +#define MAYBE_Opacity Opacity +#define MAYBE_ScaleUpDown ScaleUpDown +#define MAYBE_ScaleReparent ScaleReparent +#define MAYBE_NoScaleCanvas NoScaleCanvas +#define MAYBE_AddRemoveThreadedAnimations AddRemoveThreadedAnimations +#define MAYBE_SwitchCCLayerAnimations SwitchCCLayerAnimations +#endif + +TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) { scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 50, 50))); DrawTree(layer.get()); @@ -323,7 +355,7 @@ TEST_F(LayerWithRealCompositorTest, Draw) { // | +-- L3 - yellow // +-- L4 - magenta // -TEST_F(LayerWithRealCompositorTest, Hierarchy) { +TEST_F(LayerWithRealCompositorTest, MAYBE_Hierarchy) { scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, @@ -347,16 +379,12 @@ class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { // Overridden from testing::Test: virtual void SetUp() OVERRIDE { - bool allow_test_contexts = true; - Compositor::InitializeContextFactoryForTests(allow_test_contexts); - Compositor::Initialize(); + ui::SetupTestCompositor(); compositor_.reset(new Compositor(this, gfx::kNullAcceleratedWidget)); compositor_->SetScaleAndSize(1.0f, gfx::Size(1000, 1000)); } virtual void TearDown() OVERRIDE { - compositor_.reset(); - Compositor::Terminate(); } Compositor* compositor() { return compositor_.get(); } @@ -463,7 +491,7 @@ TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Medium) { EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords); } -TEST_F(LayerWithRealCompositorTest, Delegate) { +TEST_F(LayerWithRealCompositorTest, MAYBE_Delegate) { scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK, gfx::Rect(20, 20, 400, 400))); GetCompositor()->SetRootLayer(l1.get()); @@ -492,7 +520,7 @@ TEST_F(LayerWithRealCompositorTest, Delegate) { EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50)); } -TEST_F(LayerWithRealCompositorTest, DrawTree) { +TEST_F(LayerWithRealCompositorTest, MAYBE_DrawTree) { scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, @@ -526,7 +554,7 @@ TEST_F(LayerWithRealCompositorTest, DrawTree) { // | +-- L3 - yellow // +-- L4 - magenta // -TEST_F(LayerWithRealCompositorTest, HierarchyNoTexture) { +TEST_F(LayerWithRealCompositorTest, MAYBE_HierarchyNoTexture) { scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350))); @@ -562,11 +590,15 @@ class LayerWithNullDelegateTest : public LayerWithDelegateTest { LayerWithNullDelegateTest() {} virtual ~LayerWithNullDelegateTest() {} + // Overridden from testing::Test: virtual void SetUp() OVERRIDE { LayerWithDelegateTest::SetUp(); default_layer_delegate_.reset(new NullLayerDelegate()); } + virtual void TearDown() OVERRIDE { + } + virtual Layer* CreateLayer(LayerType type) OVERRIDE { Layer* layer = new Layer(type); layer->set_delegate(default_layer_delegate_.get()); @@ -769,53 +801,35 @@ TEST_F(LayerWithNullDelegateTest, SetBoundsSchedulesPaint) { } // Checks that pixels are actually drawn to the screen with a read back. -TEST_F(LayerWithRealCompositorTest, DrawPixels) { - gfx::Size viewport_size = GetCompositor()->size(); - - // The window should be some non-trivial size but may not be exactly - // 500x500 on all platforms/bots. - EXPECT_GE(viewport_size.width(), 200); - EXPECT_GE(viewport_size.height(), 200); - - int blue_height = 10; - - scoped_ptr<Layer> layer( - CreateColorLayer(SK_ColorRED, gfx::Rect(viewport_size))); - scoped_ptr<Layer> layer2( - CreateColorLayer(SK_ColorBLUE, - gfx::Rect(0, 0, viewport_size.width(), blue_height))); +// Currently disabled on all platforms, see http://crbug.com/148709. +TEST_F(LayerWithRealCompositorTest, MAYBE_DrawPixels) { + scoped_ptr<Layer> layer(CreateColorLayer(SK_ColorRED, + gfx::Rect(0, 0, 500, 500))); + scoped_ptr<Layer> layer2(CreateColorLayer(SK_ColorBLUE, + gfx::Rect(0, 0, 500, 10))); layer->Add(layer2.get()); DrawTree(layer.get()); SkBitmap bitmap; - ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, gfx::Rect(viewport_size))); + gfx::Size size = GetCompositor()->size(); + ASSERT_TRUE(GetCompositor()->ReadPixels(&bitmap, + gfx::Rect(0, 10, + size.width(), size.height() - 10))); ASSERT_FALSE(bitmap.empty()); SkAutoLockPixels lock(bitmap); - for (int x = 0; x < viewport_size.width(); x++) { - for (int y = 0; y < viewport_size.height(); y++) { - SkColor actual_color = bitmap.getColor(x, y); - SkColor expected_color = y < blue_height ? SK_ColorBLUE : SK_ColorRED; - EXPECT_EQ(expected_color, actual_color) - << "Pixel error at x=" << x << " y=" << y << "; " - << "actual RGBA=(" - << SkColorGetR(actual_color) << "," - << SkColorGetG(actual_color) << "," - << SkColorGetB(actual_color) << "," - << SkColorGetA(actual_color) << "); " - << "expected RGBA=(" - << SkColorGetR(expected_color) << "," - << SkColorGetG(expected_color) << "," - << SkColorGetB(expected_color) << "," - << SkColorGetA(expected_color) << ")"; - } - } + bool is_all_red = true; + for (int x = 0; is_all_red && x < 500; x++) + for (int y = 0; is_all_red && y < 490; y++) + is_all_red = is_all_red && (bitmap.getColor(x, y) == SK_ColorRED); + + EXPECT_TRUE(is_all_red); } // Checks the logic around Compositor::SetRootLayer and Layer::SetCompositor. -TEST_F(LayerWithRealCompositorTest, SetRootLayer) { +TEST_F(LayerWithRealCompositorTest, MAYBE_SetRootLayer) { Compositor* compositor = GetCompositor(); scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); @@ -847,7 +861,7 @@ TEST_F(LayerWithRealCompositorTest, SetRootLayer) { // - After ScheduleDraw is called, or // - Whenever SetBounds, SetOpacity or SetTransform are called. // TODO(vollick): could be reorganized into compositor_unittest.cc -TEST_F(LayerWithRealCompositorTest, CompositorObservers) { +TEST_F(LayerWithRealCompositorTest, MAYBE_CompositorObservers) { scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED, gfx::Rect(20, 20, 400, 400))); scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE, @@ -921,7 +935,7 @@ TEST_F(LayerWithRealCompositorTest, CompositorObservers) { } // Checks that modifying the hierarchy correctly affects final composite. -TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { +TEST_F(LayerWithRealCompositorTest, MAYBE_ModifyHierarchy) { GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); // l0 @@ -990,7 +1004,7 @@ TEST_F(LayerWithRealCompositorTest, ModifyHierarchy) { // Opacity is rendered correctly. // Checks that modifying the hierarchy correctly affects final composite. -TEST_F(LayerWithRealCompositorTest, Opacity) { +TEST_F(LayerWithRealCompositorTest, MAYBE_Opacity) { GetCompositor()->SetScaleAndSize(1.0f, gfx::Size(50, 50)); // l0 @@ -1098,7 +1112,7 @@ TEST_F(LayerWithDelegateTest, SchedulePaintFromOnPaintLayer) { gfx::Rect(10, 10, 30, 30))); } -TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { +TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleUpDown) { scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, gfx::Rect(10, 20, 200, 220))); TestLayerDelegate root_delegate; @@ -1184,7 +1198,7 @@ TEST_F(LayerWithRealCompositorTest, ScaleUpDown) { EXPECT_EQ("0.0 0.0", l1_delegate.ToScaleString()); } -TEST_F(LayerWithRealCompositorTest, ScaleReparent) { +TEST_F(LayerWithRealCompositorTest, MAYBE_ScaleReparent) { scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, gfx::Rect(10, 20, 200, 220))); scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, @@ -1229,7 +1243,7 @@ TEST_F(LayerWithRealCompositorTest, ScaleReparent) { } // Tests layer::set_scale_content(false). -TEST_F(LayerWithRealCompositorTest, NoScaleCanvas) { +TEST_F(LayerWithRealCompositorTest, MAYBE_NoScaleCanvas) { scoped_ptr<Layer> root(CreateColorLayer(SK_ColorWHITE, gfx::Rect(10, 20, 200, 220))); scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorWHITE, @@ -1344,7 +1358,7 @@ TEST_F(LayerWithDelegateTest, DelegatedLayer) { } // Tests Layer::AddThreadedAnimation and Layer::RemoveThreadedAnimation. -TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { +TEST_F(LayerWithRealCompositorTest, MAYBE_AddRemoveThreadedAnimations) { scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); scoped_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); scoped_ptr<Layer> l2(CreateLayer(LAYER_TEXTURED)); @@ -1391,7 +1405,7 @@ TEST_F(LayerWithRealCompositorTest, AddRemoveThreadedAnimations) { // Tests that in-progress threaded animations complete when a Layer's // cc::Layer changes. -TEST_F(LayerWithRealCompositorTest, SwitchCCLayerAnimations) { +TEST_F(LayerWithRealCompositorTest, MAYBE_SwitchCCLayerAnimations) { scoped_ptr<Layer> root(CreateLayer(LAYER_TEXTURED)); scoped_ptr<Layer> l1(CreateLayer(LAYER_TEXTURED)); GetCompositor()->SetRootLayer(root.get()); diff --git a/ui/compositor/test/test_suite.cc b/ui/compositor/test/test_suite.cc index 3f89cce..58329f2 100644 --- a/ui/compositor/test/test_suite.cc +++ b/ui/compositor/test/test_suite.cc @@ -28,15 +28,19 @@ void CompositorTestSuite::Initialize() { #if defined(USE_X11) XInitThreads(); #endif - CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL)); +#if defined(OS_LINUX) + gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL); +#endif base::TestSuite::Initialize(); gfx::RegisterPathProvider(); message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); + Compositor::Initialize(); } void CompositorTestSuite::Shutdown() { + Compositor::Terminate(); message_loop_.reset(); base::TestSuite::Shutdown(); diff --git a/ui/keyboard/keyboard_test_suite.cc b/ui/keyboard/keyboard_test_suite.cc index dc4ec5b..5b4db504d 100644 --- a/ui/keyboard/keyboard_test_suite.cc +++ b/ui/keyboard/keyboard_test_suite.cc @@ -4,6 +4,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "ui/compositor/compositor_setup.h" #include "ui/test/test_suite.h" class KeyboardTestSuite : public ui::test::UITestSuite { @@ -22,6 +23,8 @@ class KeyboardTestSuite : public ui::test::UITestSuite { void KeyboardTestSuite::Initialize() { ui::test::UITestSuite::Initialize(); + + ui::SetupTestCompositor(); } void KeyboardTestSuite::Shutdown() { diff --git a/ui/message_center/test/run_all_unittests.cc b/ui/message_center/test/run_all_unittests.cc index ff863b6..c9c3318 100644 --- a/ui/message_center/test/run_all_unittests.cc +++ b/ui/message_center/test/run_all_unittests.cc @@ -9,6 +9,10 @@ #include "ui/test/test_suite.h" #include "ui/views/view.h" +#if defined(TOOLKIT_VIEWS) +#include "ui/compositor/compositor_setup.h" +#endif + class MessageCenterTestSuite : public ui::test::UITestSuite { public: MessageCenterTestSuite(int argc, char** argv) @@ -25,6 +29,10 @@ class MessageCenterTestSuite : public ui::test::UITestSuite { void MessageCenterTestSuite::Initialize() { ui::test::UITestSuite::Initialize(); + +#if defined(TOOLKIT_VIEWS) + ui::SetupTestCompositor(); +#endif } void MessageCenterTestSuite::Shutdown() { diff --git a/ui/snapshot/snapshot_aura_unittest.cc b/ui/snapshot/snapshot_aura_unittest.cc index b72629c..206069b 100644 --- a/ui/snapshot/snapshot_aura_unittest.cc +++ b/ui/snapshot/snapshot_aura_unittest.cc @@ -11,6 +11,7 @@ #include "ui/aura/test/test_window_delegate.h" #include "ui/aura/test/test_windows.h" #include "ui/aura/window.h" +#include "ui/compositor/compositor_setup.h" #include "ui/compositor/layer.h" #include "ui/gfx/canvas.h" #include "ui/gfx/gfx_paths.h" diff --git a/ui/views/run_all_unittests.cc b/ui/views/run_all_unittests.cc index 6c425d7..cd73011 100644 --- a/ui/views/run_all_unittests.cc +++ b/ui/views/run_all_unittests.cc @@ -7,6 +7,7 @@ #include "base/test/test_suite.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" +#include "ui/compositor/compositor_setup.h" #include "ui/views/view.h" class ViewTestSuite : public base::TestSuite { @@ -18,6 +19,8 @@ class ViewTestSuite : public base::TestSuite { base::TestSuite::Initialize(); ui::RegisterPathProvider(); ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); + + ui::SetupTestCompositor(); } private: diff --git a/ui/views/widget/desktop_aura/desktop_capture_client_unittest.cc b/ui/views/widget/desktop_aura/desktop_capture_client_unittest.cc index d96c445..eafeee6 100644 --- a/ui/views/widget/desktop_aura/desktop_capture_client_unittest.cc +++ b/ui/views/widget/desktop_aura/desktop_capture_client_unittest.cc @@ -45,14 +45,6 @@ class DesktopCaptureClientTest : public aura::test::AuraTestBase { virtual void TearDown() OVERRIDE { RunAllPendingInMessageLoop(); - - second_desktop_position_client_.reset(); - second_desktop_capture_client_.reset(); - - // Kill any active compositors before we hit the compositor shutdown paths. - second_root_.reset(); - - desktop_position_client_.reset(); desktop_capture_client_.reset(); AuraTestBase::TearDown(); |