cef/libcef/browser/screen_util_unittest.cc
Nik Pavlov d3a2237a5a alloy: mac: Fix default popup window positioning (see issue #3244)
Popup windows will be created on the display that best matches the requested
coordinates. The requested size will apply to the content area (as required by
JS documentation) and window size will be reduced if necessary to fit within the
target display. The requested origin will apply to the window (including frame)
and will be modified if necessary so that the window is fully visible on the
target display.

This change does not implement popup positioning for cefclient which uses an
application-created parent window.

This change grants access to the getScreenDetails JS API without user prompt.
2022-06-27 10:29:16 +00:00

81 lines
2.3 KiB
C++

// Copyright (c) 2022 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cef/libcef/browser/screen_util.h"
#include "tests/gtest/include/gtest/gtest.h"
namespace {
constexpr int kScreenWidth = 1024;
constexpr int kScreenHeight = 768;
const CefRect kMainScreen(0, 0, kScreenWidth, kScreenHeight);
const CefRect kLeftScreen(-1024, 0, kScreenWidth, kScreenHeight);
} // namespace
TEST(MakeVisibleOnScreenRect, RectSizeIsBiggerThanScreen) {
const CefRect rect{400, 500, 1500, 800};
auto result = MakeVisibleOnScreenRect(rect, kMainScreen);
EXPECT_EQ(result.x, 0);
EXPECT_EQ(result.width, kMainScreen.width);
EXPECT_EQ(result.y, 0);
EXPECT_EQ(result.height, kMainScreen.height);
}
TEST(MakeVisibleOnScreenRect, RightBorderIsOutsideTheScreen) {
const CefRect rect{600, 400, 500, 300};
auto result = MakeVisibleOnScreenRect(rect, kMainScreen);
EXPECT_EQ(result.x, 524);
EXPECT_EQ(result.width, rect.width);
EXPECT_EQ(result.y, rect.y);
EXPECT_EQ(result.height, rect.height);
}
TEST(MakeVisibleOnScreenRect, LeftBorderIsOutsideTheScreen) {
const CefRect rect{-400, 400, 500, 300};
auto result = MakeVisibleOnScreenRect(rect, kMainScreen);
EXPECT_EQ(result.x, 0);
EXPECT_EQ(result.width, rect.width);
EXPECT_EQ(result.y, rect.y);
EXPECT_EQ(result.height, rect.height);
}
TEST(MakeVisibleOnScreenRect, BottomBorderIsOutsideTheScreen) {
const CefRect rect{600, 500, 300, 300};
auto result = MakeVisibleOnScreenRect(rect, kMainScreen);
EXPECT_EQ(result.x, 600);
EXPECT_EQ(result.width, rect.width);
EXPECT_EQ(result.y, 468);
EXPECT_EQ(result.height, rect.height);
}
TEST(MakeVisibleOnScreenRect, RectIsVisibleOnTheLeftScreen) {
const CefRect rect{-500, 300, 300, 300};
auto result = MakeVisibleOnScreenRect(rect, kLeftScreen);
EXPECT_EQ(result.x, rect.x);
EXPECT_EQ(result.width, rect.width);
EXPECT_EQ(result.y, rect.y);
EXPECT_EQ(result.height, rect.height);
}
TEST(MakeVisibleOnScreenRect, RectSizeIsBiggerThanLeftScreen) {
const CefRect rect{-500, 300, 3000, 3000};
auto result = MakeVisibleOnScreenRect(rect, kLeftScreen);
EXPECT_EQ(result.x, kLeftScreen.x);
EXPECT_EQ(result.width, kLeftScreen.width);
EXPECT_EQ(result.y, kLeftScreen.y);
EXPECT_EQ(result.height, kLeftScreen.height);
}