Skip to content

Commit

Permalink
Disable window occlusion APIs when running browser tests
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
ccameron-chromium authored and Commit bot committed Mar 7, 2016
1 parent 71d4b0f commit 19b720a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions content/browser/web_contents/web_contents_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <string>

#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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions content/public/common/content_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions content/public/common/content_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
5 changes: 5 additions & 0 deletions content/public/test/browser_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 19b720a

Please sign in to comment.