From 19b720a9ad1f5a0ce9e432e275d2a61a15c6ceac Mon Sep 17 00:00:00 2001 From: ccameron Date: Sun, 6 Mar 2016 16:14:33 -0800 Subject: [PATCH] Disable window occlusion APIs when running browser tests The positioning of windows is not predictable when running tests, and some tests can end up having their renderer processes backgrounded due to occlusion, causing unpredictable behavior. Disable occlusion API use when running tests. Occlusion is a Mac-only API for the moment, but leave this as non-Mac so that it can be picked up if needed. Also, get rid of the "we're on 10.9+" check. We always are now. BUG=558585 Review URL: https://codereview.chromium.org/1762883002 Cr-Commit-Position: refs/heads/master@{#379500} --- content/browser/web_contents/web_contents_view_mac.mm | 10 +++++++--- content/public/common/content_switches.cc | 5 +++++ content/public/common/content_switches.h | 2 ++ content/public/test/browser_test_base.cc | 5 +++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/content/browser/web_contents/web_contents_view_mac.mm b/content/browser/web_contents/web_contents_view_mac.mm index e569f0180976b..5d079a58b01e6 100644 --- a/content/browser/web_contents/web_contents_view_mac.mm +++ b/content/browser/web_contents/web_contents_view_mac.mm @@ -8,6 +8,7 @@ #include +#include "base/command_line.h" #import "base/mac/mac_util.h" #import "base/mac/scoped_sending_event.h" #include "base/mac/sdk_forward_declarations.h" @@ -23,6 +24,7 @@ #include "content/common/view_messages.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_view_delegate.h" +#include "content/public/common/content_switches.h" #include "skia/ext/skia_utils_mac.h" #import "third_party/mozilla/NSPasteboard+Utils.h" #include "ui/base/clipboard/custom_data_helper.h" @@ -636,10 +638,12 @@ - (void)viewWillMoveToWindow:(NSWindow*)newWindow { NSNotificationCenter* notificationCenter = [NSNotificationCenter defaultCenter]; - // Occlusion notification APIs are new in Mavericks. - bool supportsOcclusionAPIs = base::mac::IsOSMavericksOrLater(); + // Occlusion is highly undesirable for browser tests, since it will + // flakily change test behavior. + static bool isDisabled = base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableBackgroundingOccludedWindowsForTesting); - if (supportsOcclusionAPIs) { + if (!isDisabled) { if (oldWindow) { [notificationCenter removeObserver:self diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index e2cf9e5cdf667..92b7dc4ccc265 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -90,6 +90,11 @@ const char kDisableAcceleratedVideoDecode[] = // users with many windows/tabs and lots of memory. const char kDisableBackingStoreLimit[] = "disable-backing-store-limit"; +// Disable backgrounding renders for occluded windows. Done for tests to avoid +// nondeterministic behavior. +extern const char kDisableBackgroundingOccludedWindowsForTesting[] = + "disable-backgrounding-occluded-windows"; + // Disable one or more Blink runtime-enabled features. // Use names from RuntimeEnabledFeatures.in, separated by commas. // Applied after kEnableBlinkFeatures, and after other flags that change these diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index c64011d610509..6143111b66bdb 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -35,6 +35,8 @@ CONTENT_EXPORT extern const char kDisableAcceleratedJpegDecoding[]; CONTENT_EXPORT extern const char kDisableAcceleratedMjpegDecode[]; CONTENT_EXPORT extern const char kDisableAcceleratedVideoDecode[]; extern const char kDisableBackingStoreLimit[]; +CONTENT_EXPORT extern const char + kDisableBackgroundingOccludedWindowsForTesting[]; CONTENT_EXPORT extern const char kDisableBlinkFeatures[]; CONTENT_EXPORT extern const char kDisableDatabases[]; CONTENT_EXPORT extern const char kDisableDelayAgnosticAec[]; diff --git a/content/public/test/browser_test_base.cc b/content/public/test/browser_test_base.cc index 2e6500a8830a2..7b7513aabb472 100644 --- a/content/public/test/browser_test_base.cc +++ b/content/public/test/browser_test_base.cc @@ -200,6 +200,11 @@ void BrowserTestBase::SetUp() { if (use_software_compositing_) command_line->AppendSwitch(switches::kDisableGpu); + // The layout of windows on screen is unpredictable during tests, so disable + // occlusion when running browser tests. + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kDisableBackgroundingOccludedWindowsForTesting); + #if defined(USE_AURA) // Most tests do not need pixel output, so we don't produce any. The command // line can override this behaviour to allow for visual debugging.