1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/frame/desktop_browser_frame_aura_linux.h"
#include "base/test/bind.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test.h"
#include "ui/base/mojom/window_show_state.mojom.h"
#include "ui/color/color_provider_key.h"
#include "ui/color/color_provider_manager.h"
#include "ui/ozone/public/ozone_platform.h"
using DesktopBrowserFrameAuraLinuxTest = InProcessBrowserTest;
using SupportsForTest =
ui::OzonePlatform::PlatformRuntimeProperties::SupportsForTest;
namespace {
gfx::Size GetWindowSize(Browser* browser) {
BrowserView* const browser_view =
BrowserView::GetBrowserViewForBrowser(browser);
const NativeBrowserFrame* const frame =
browser_view->frame()->native_browser_frame();
gfx::Rect bounds;
ui::mojom::WindowShowState show_state;
frame->GetWindowPlacement(&bounds, &show_state);
return bounds.size();
}
void VerifyColorsForFrameType(const Browser* browser, bool use_custom_frame) {
ThemeService* theme_service =
ThemeServiceFactory::GetForProfile(browser->profile());
EXPECT_EQ(use_custom_frame, theme_service->ShouldUseCustomFrame());
ui::ColorProviderManager::ResetForTesting();
bool initialized_color_provider_for_custom_frame;
ui::ColorProviderManager::GetForTesting().AppendColorProviderInitializer(
base::BindLambdaForTesting(
[&initialized_color_provider_for_custom_frame](
ui::ColorProvider* provider, const ui::ColorProviderKey& key) {
initialized_color_provider_for_custom_frame =
key.frame_type == ui::ColorProviderKey::FrameType::kChromium;
}));
ASSERT_NE(nullptr,
BrowserView::GetBrowserViewForBrowser(browser)->GetColorProvider());
EXPECT_EQ(use_custom_frame, initialized_color_provider_for_custom_frame);
ui::ColorProviderManager::ResetForTesting();
}
} // namespace
// Tests that DesktopBrowserFrameAuraLinux::UseCustomFrame() returns the correct
// value that respects 1) the current value of the user preference and
// 2) capabilities of the platform.
// Also tests the regressions found in crbug.com/1243937 and crbug.com/1329756.
IN_PROC_BROWSER_TEST_F(DesktopBrowserFrameAuraLinuxTest, UseCustomFrame) {
const BrowserView* const browser_view =
BrowserView::GetBrowserViewForBrowser(browser());
const DesktopBrowserFrameAuraLinux* const frame =
static_cast<DesktopBrowserFrameAuraLinux*>(
browser_view->frame()->native_browser_frame());
auto* pref_service = browser_view->browser()->profile()->GetPrefs();
// Try overriding the runtime platform property that indicates whether the
// platform supports server-side window decorations. For each variant,
// check what is the effective value of the property (the platform may
// ignore the override), then pass through variants for the user preference
// and check what DesktopBrowserFrameAuraLinux::UseCustomFrame() returns
// finally.
auto* const platform = ui::OzonePlatform::GetInstance();
for (const auto ssd_support_override :
{SupportsForTest::kYes, SupportsForTest::kNo}) {
ui::OzonePlatform::PlatformRuntimeProperties::
override_supports_ssd_for_test = ssd_support_override;
if (platform->GetPlatformRuntimeProperties()
.supports_server_side_window_decorations) {
// This platform either supports overriding the property or supports SSD
// always.
// UseCustomFrame() should return what the user preference suggests.
for (const auto setting : {true, false}) {
pref_service->SetBoolean(prefs::kUseCustomChromeFrame, setting);
EXPECT_EQ(frame->UseCustomFrame(), setting)
<< " when setting is " << setting;
VerifyColorsForFrameType(browser(), frame->UseCustomFrame());
}
} else {
// This platform either does not support overriding the property or does
// not support SSD.
// UseCustomFrame() should return true always.
for (const auto setting : {true, false}) {
pref_service->SetBoolean(prefs::kUseCustomChromeFrame, setting);
EXPECT_TRUE(frame->UseCustomFrame()) << " when setting is " << setting;
VerifyColorsForFrameType(browser(), frame->UseCustomFrame());
}
}
}
// Reset the override.
ui::OzonePlatform::PlatformRuntimeProperties::override_supports_ssd_for_test =
SupportsForTest::kNotSet;
}
// Tests that the new browser window restores the bounds properly: its size must
// be the same as the already existing window has.
// The regression was found in https://crbug.com/1287212.
IN_PROC_BROWSER_TEST_F(DesktopBrowserFrameAuraLinuxTest, NewWindowSize) {
// Ensure the first window is active before creating the second one.
ui_test_utils::BrowserActivationWaiter(browser()).WaitForActivation();
Profile* profile = browser()->profile();
Browser::CreateParams params(profile, true /* user_gesture */);
Browser* browser2 = Browser::Create(params);
browser2->window()->Show();
// The first window saves its placement on losing the active state, then the
// second window needs to go through the initialisation, update its size and
// frame extents. We wait until everything calms down.
base::RunLoop().RunUntilIdle();
EXPECT_EQ(GetWindowSize(browser()), GetWindowSize(browser2));
}
|