chromium/third_party/blink/renderer/core/testing/scoped_mock_overlay_scrollbars.h

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TESTING_SCOPED_MOCK_OVERLAY_SCROLLBARS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TESTING_SCOPED_MOCK_OVERLAY_SCROLLBARS_H_

#include "base/check_op.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "third_party/blink/renderer/core/scroll/scrollbar_theme.h"

namespace blink {

// Without the default parameter, the instance forces to use mocked overlay
// scrollbars instead of through WebThemeEngine to avoid crash in unit tests
// that don't initialize chrome WebThemeEngine implementation, and to ensure
// consistent layout regardless of differences between scrollbar themes.
//
// WebViewHelper and PageTestBase include this, so this is only needed if a
// test tests non-overlay scrollbars, or needs a bigger scope of mock overlay
// scrollbar settings than the scope of them.
//
// Note that ScopedMockOverlayScrollbars(false) doesn't always force
// non-overlay scrollbars because the platform (e.g. Android) may not support
// non-overlay scrollbars. Use USE_NON_OVERLAY_SCROLLBAR() instead. It will
// skip the test if non-overlay scrollbar is not supported by the platform.
//
// Note that unit tests should use ScopedMockOverlayScrollbars instead of
// ScrollbarThemeSettings::SetOverlayScrollbarsEnabled() because overlay
// scrollbars in testing must be mocked for the following reasons:
// 1. ScrollbarThemeSettings::SetOverlayScrollbarsEnabled() controls blink
//    scrollbar theme only, not the chrome WebThemeEngine implementation;
// 2. The chrome WebThemeEngine implementation may not support overlay
//    scrollbars;
// 3. The chrome WebThemeEngine implementation may not support dynamic
//    switching between overlay and non-overlay scrollbars.
//
class ScopedMockOverlayScrollbars {};

// This is used in tests that needs non-overlay scrollbars. To make sure the
// 'return' works, this macro must be used in a test directly, not in a function
// called by a test or a compound statement.
#define USE_NON_OVERLAY_SCROLLBARS_OR_QUIT()

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_TESTING_SCOPED_MOCK_OVERLAY_SCROLLBARS_H_