2016-01-19 21:09:01 +01:00
|
|
|
// Copyright (c) 2016 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.
|
|
|
|
|
2016-11-16 00:22:34 +01:00
|
|
|
#include "include/base/cef_bind.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/views/cef_box_layout.h"
|
|
|
|
#include "include/views/cef_layout.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "include/views/cef_panel.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/image_util.h"
|
|
|
|
#include "tests/ceftests/thread_helper.h"
|
|
|
|
#include "tests/ceftests/views/test_window_delegate.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
#define WINDOW_TEST_ASYNC(name) UI_THREAD_TEST_ASYNC(ViewsWindowTest, name)
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
#if !defined(OS_WIN)
|
2017-05-17 11:29:28 +02:00
|
|
|
#define VK_MENU 0x12 // ALT key.
|
2017-02-17 00:19:43 +01:00
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Window state change delay in MS.
|
|
|
|
const int kStateDelayMS = 200;
|
|
|
|
|
|
|
|
const int kWSize = TestWindowDelegate::kWSize;
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
// Test that |expected| and |actual| are within |allowed_deviance| of each
|
|
|
|
// other.
|
|
|
|
void ExpectCloseRects(const CefRect& expected,
|
|
|
|
const CefRect& actual,
|
|
|
|
int allowed_deviance) {
|
|
|
|
EXPECT_LE(abs(expected.x - actual.x), allowed_deviance);
|
|
|
|
EXPECT_LE(abs(expected.y - actual.y), allowed_deviance);
|
|
|
|
EXPECT_LE(abs(expected.width - actual.width), allowed_deviance);
|
|
|
|
EXPECT_LE(abs(expected.height - actual.height), allowed_deviance);
|
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowCreateImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowCreateFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.frameless = true;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RunWindowShowHide(CefRefPtr<CefWindow> window) {
|
|
|
|
EXPECT_FALSE(window->IsVisible());
|
|
|
|
EXPECT_FALSE(window->IsDrawn());
|
|
|
|
window->Show();
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
|
|
|
window->Hide();
|
|
|
|
EXPECT_FALSE(window->IsVisible());
|
|
|
|
EXPECT_FALSE(window->IsDrawn());
|
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowShowHideImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowShowHide);
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowShowHideFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowShowHide);
|
|
|
|
config.frameless = true;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const int kWPanel1ID = 1;
|
|
|
|
const int kWPanel2ID = 2;
|
|
|
|
|
|
|
|
void CreateBoxLayout(CefRefPtr<CefWindow> parent) {
|
|
|
|
CefRefPtr<CefPanel> panel_child1 = CefPanel::CreatePanel(nullptr);
|
|
|
|
panel_child1->SetID(kWPanel1ID);
|
|
|
|
panel_child1->SetBackgroundColor(CefColorSetARGB(255, 0, 0, 255));
|
|
|
|
EXPECT_TRUE(panel_child1->IsVisible());
|
|
|
|
EXPECT_FALSE(panel_child1->IsDrawn());
|
|
|
|
|
|
|
|
CefRefPtr<CefPanel> panel_child2 = CefPanel::CreatePanel(nullptr);
|
|
|
|
panel_child2->SetID(kWPanel2ID);
|
|
|
|
panel_child2->SetBackgroundColor(CefColorSetARGB(255, 0, 255, 0));
|
|
|
|
EXPECT_TRUE(panel_child2->IsVisible());
|
|
|
|
EXPECT_FALSE(panel_child2->IsDrawn());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Set to BoxLayout. Default layout is vertical with children stretched along
|
|
|
|
// the horizontal axis.
|
|
|
|
CefBoxLayoutSettings settings;
|
|
|
|
parent->SetToBoxLayout(settings);
|
|
|
|
|
|
|
|
parent->AddChildView(panel_child1);
|
|
|
|
parent->AddChildView(panel_child2);
|
|
|
|
|
|
|
|
// IsDrawn() returns true because the Panels now have a RootView from the
|
|
|
|
// Window.
|
|
|
|
EXPECT_TRUE(panel_child1->IsDrawn());
|
|
|
|
EXPECT_TRUE(panel_child1->IsDrawn());
|
|
|
|
|
|
|
|
// Stretch children equally along the vertical axis using flex.
|
|
|
|
CefRefPtr<CefBoxLayout> layout = parent->GetLayout()->AsBoxLayout();
|
|
|
|
layout->SetFlexForView(panel_child1, 1);
|
|
|
|
layout->SetFlexForView(panel_child2, 1);
|
|
|
|
|
|
|
|
// Force layout.
|
|
|
|
parent->Layout();
|
|
|
|
|
|
|
|
// The children should each take up 50% of the client area.
|
2017-05-17 11:29:28 +02:00
|
|
|
ExpectCloseRects(CefRect(0, 0, kWSize, kWSize / 2), panel_child1->GetBounds(),
|
|
|
|
1);
|
2016-05-25 01:35:43 +02:00
|
|
|
ExpectCloseRects(CefRect(0, kWSize / 2, kWSize, kWSize / 2),
|
|
|
|
panel_child2->GetBounds(), 1);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RunWindowLayoutAndCoords(CefRefPtr<CefWindow> window) {
|
|
|
|
CreateBoxLayout(window);
|
|
|
|
|
|
|
|
CefRefPtr<CefView> view1 = window->GetViewForID(kWPanel1ID);
|
|
|
|
EXPECT_TRUE(view1.get());
|
|
|
|
CefRefPtr<CefView> view2 = window->GetViewForID(kWPanel2ID);
|
|
|
|
EXPECT_TRUE(view2.get());
|
|
|
|
|
|
|
|
window->Show();
|
|
|
|
|
|
|
|
CefRect client_bounds_in_screen = window->GetClientAreaBoundsInScreen();
|
|
|
|
CefPoint point;
|
|
|
|
|
|
|
|
// Test view to screen coordinate conversions.
|
|
|
|
point = CefPoint(0, 0);
|
|
|
|
EXPECT_TRUE(view1->ConvertPointToScreen(point));
|
|
|
|
EXPECT_EQ(CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y),
|
|
|
|
point);
|
|
|
|
point = CefPoint(0, 0);
|
|
|
|
EXPECT_TRUE(view2->ConvertPointToScreen(point));
|
|
|
|
EXPECT_EQ(CefPoint(client_bounds_in_screen.x,
|
|
|
|
client_bounds_in_screen.y + kWSize / 2),
|
|
|
|
point);
|
|
|
|
|
|
|
|
// Test view from screen coordinate conversions.
|
|
|
|
point = CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y);
|
|
|
|
EXPECT_TRUE(view1->ConvertPointFromScreen(point));
|
|
|
|
EXPECT_EQ(CefPoint(0, 0), point);
|
|
|
|
point = CefPoint(client_bounds_in_screen.x,
|
|
|
|
client_bounds_in_screen.y + kWSize / 2);
|
|
|
|
EXPECT_TRUE(view2->ConvertPointFromScreen(point));
|
|
|
|
EXPECT_EQ(CefPoint(0, 0), point);
|
|
|
|
|
|
|
|
// Test view to window coordinate conversions.
|
|
|
|
point = CefPoint(0, 0);
|
|
|
|
EXPECT_TRUE(view1->ConvertPointToWindow(point));
|
|
|
|
EXPECT_EQ(CefPoint(0, 0), point);
|
|
|
|
point = CefPoint(0, 0);
|
|
|
|
EXPECT_TRUE(view2->ConvertPointToWindow(point));
|
|
|
|
EXPECT_EQ(CefPoint(0, kWSize / 2), point);
|
|
|
|
|
|
|
|
// Test view from window coordinate conversions.
|
|
|
|
point = CefPoint(0, 0);
|
|
|
|
EXPECT_TRUE(view1->ConvertPointFromWindow(point));
|
|
|
|
EXPECT_EQ(CefPoint(0, 0), point);
|
|
|
|
point = CefPoint(0, kWSize / 2);
|
|
|
|
EXPECT_TRUE(view2->ConvertPointFromWindow(point));
|
|
|
|
EXPECT_EQ(CefPoint(0, 0), point);
|
|
|
|
|
|
|
|
// Test view to view coordinate conversions.
|
|
|
|
point = CefPoint(0, 0);
|
|
|
|
EXPECT_TRUE(view1->ConvertPointToView(view2, point));
|
|
|
|
EXPECT_EQ(CefPoint(0, -kWSize / 2), point);
|
|
|
|
point = CefPoint(0, 0);
|
|
|
|
EXPECT_TRUE(view2->ConvertPointToView(view1, point));
|
|
|
|
EXPECT_EQ(CefPoint(0, kWSize / 2), point);
|
|
|
|
|
|
|
|
// Test view from view coordinate conversions.
|
|
|
|
point = CefPoint(0, -kWSize / 2);
|
|
|
|
EXPECT_TRUE(view1->ConvertPointFromView(view2, point));
|
|
|
|
EXPECT_EQ(CefPoint(0, 0), point);
|
|
|
|
point = CefPoint(0, kWSize / 2);
|
|
|
|
EXPECT_TRUE(view2->ConvertPointFromView(view1, point));
|
|
|
|
EXPECT_EQ(CefPoint(0, 0), point);
|
|
|
|
|
|
|
|
CefRefPtr<CefDisplay> display = window->GetDisplay();
|
|
|
|
EXPECT_TRUE(display.get());
|
|
|
|
|
|
|
|
// We don't know what the pixel values will be, but they should be reversable.
|
|
|
|
point = CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y);
|
|
|
|
display->ConvertPointToPixels(point);
|
|
|
|
display->ConvertPointFromPixels(point);
|
|
|
|
EXPECT_EQ(CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y),
|
|
|
|
point);
|
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowLayoutAndCoordsImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowLayoutAndCoords);
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowLayoutAndCoordsFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowLayoutAndCoords);
|
|
|
|
config.frameless = true;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyRestore(CefRefPtr<CefWindow> window) {
|
|
|
|
EXPECT_FALSE(window->IsMinimized());
|
|
|
|
EXPECT_FALSE(window->IsMaximized());
|
|
|
|
EXPECT_FALSE(window->IsFullscreen());
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
|
|
|
|
|
|
|
// End the test by closing the Window.
|
|
|
|
window->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyMaximize(CefRefPtr<CefWindow> window) {
|
|
|
|
EXPECT_FALSE(window->IsMinimized());
|
|
|
|
EXPECT_TRUE(window->IsMaximized());
|
|
|
|
EXPECT_FALSE(window->IsFullscreen());
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
|
|
|
|
|
|
|
window->Restore();
|
|
|
|
CefPostDelayedTask(TID_UI, base::Bind(VerifyRestore, window), kStateDelayMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunWindowMaximize(CefRefPtr<CefWindow> window) {
|
|
|
|
CreateBoxLayout(window);
|
|
|
|
window->Show();
|
|
|
|
EXPECT_FALSE(window->IsMinimized());
|
|
|
|
EXPECT_FALSE(window->IsMaximized());
|
|
|
|
EXPECT_FALSE(window->IsFullscreen());
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
|
|
|
|
|
|
|
window->Maximize();
|
|
|
|
CefPostDelayedTask(TID_UI, base::Bind(VerifyMaximize, window), kStateDelayMS);
|
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowMaximizeImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowMaximize);
|
|
|
|
config.close_window = false;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowMaximizeFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowMaximize);
|
|
|
|
config.frameless = true;
|
|
|
|
config.close_window = false;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyMinimize(CefRefPtr<CefWindow> window) {
|
|
|
|
EXPECT_TRUE(window->IsMinimized());
|
|
|
|
EXPECT_FALSE(window->IsMaximized());
|
|
|
|
EXPECT_FALSE(window->IsFullscreen());
|
2019-03-13 22:27:37 +01:00
|
|
|
|
|
|
|
// This result is a bit unexpected, but I guess the platform considers a
|
|
|
|
// window to be visible even when it's minimized.
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
window->Restore();
|
|
|
|
CefPostDelayedTask(TID_UI, base::Bind(VerifyRestore, window), kStateDelayMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunWindowMinimize(CefRefPtr<CefWindow> window) {
|
|
|
|
CreateBoxLayout(window);
|
|
|
|
window->Show();
|
|
|
|
EXPECT_FALSE(window->IsMinimized());
|
|
|
|
EXPECT_FALSE(window->IsMaximized());
|
|
|
|
EXPECT_FALSE(window->IsFullscreen());
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
|
|
|
|
|
|
|
window->Minimize();
|
|
|
|
CefPostDelayedTask(TID_UI, base::Bind(VerifyMinimize, window), kStateDelayMS);
|
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowMinimizeImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowMinimize);
|
|
|
|
config.close_window = false;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowMinimizeFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowMinimize);
|
|
|
|
config.frameless = true;
|
|
|
|
config.close_window = false;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyFullscreenExit(CefRefPtr<CefWindow> window) {
|
|
|
|
EXPECT_FALSE(window->IsMinimized());
|
|
|
|
EXPECT_FALSE(window->IsMaximized());
|
|
|
|
EXPECT_FALSE(window->IsFullscreen());
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
|
|
|
|
|
|
|
// End the test by closing the Window.
|
|
|
|
window->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyFullscreen(CefRefPtr<CefWindow> window) {
|
|
|
|
EXPECT_FALSE(window->IsMinimized());
|
|
|
|
EXPECT_FALSE(window->IsMaximized());
|
|
|
|
EXPECT_TRUE(window->IsFullscreen());
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
|
|
|
|
|
|
|
window->SetFullscreen(false);
|
|
|
|
CefPostDelayedTask(TID_UI, base::Bind(VerifyFullscreenExit, window),
|
|
|
|
kStateDelayMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunWindowFullscreen(CefRefPtr<CefWindow> window) {
|
|
|
|
CreateBoxLayout(window);
|
|
|
|
window->Show();
|
|
|
|
EXPECT_FALSE(window->IsMinimized());
|
|
|
|
EXPECT_FALSE(window->IsMaximized());
|
|
|
|
EXPECT_FALSE(window->IsFullscreen());
|
|
|
|
EXPECT_TRUE(window->IsVisible());
|
|
|
|
EXPECT_TRUE(window->IsDrawn());
|
|
|
|
|
|
|
|
window->SetFullscreen(true);
|
|
|
|
CefPostDelayedTask(TID_UI, base::Bind(VerifyFullscreen, window),
|
|
|
|
kStateDelayMS);
|
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowFullscreenImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowFullscreen);
|
|
|
|
config.close_window = false;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowFullscreenFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowFullscreen);
|
|
|
|
config.frameless = true;
|
|
|
|
config.close_window = false;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RunWindowIcon(CefRefPtr<CefWindow> window) {
|
|
|
|
CefRefPtr<CefImage> image = CefImage::CreateImage();
|
|
|
|
image_util::LoadIconImage(image, 1.0);
|
|
|
|
image_util::LoadIconImage(image, 2.0);
|
|
|
|
|
|
|
|
EXPECT_FALSE(window->GetWindowIcon().get());
|
|
|
|
window->SetWindowIcon(image);
|
|
|
|
EXPECT_TRUE(image->IsSame(window->GetWindowIcon()));
|
|
|
|
|
|
|
|
EXPECT_FALSE(window->GetWindowAppIcon().get());
|
|
|
|
window->SetWindowAppIcon(image);
|
|
|
|
EXPECT_TRUE(image->IsSame(window->GetWindowAppIcon()));
|
|
|
|
|
|
|
|
window->Show();
|
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowIconImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowIcon);
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
void WindowIconFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowIcon);
|
|
|
|
config.frameless = true;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int kChar = 'A';
|
|
|
|
const int kCloseWindowId = 2;
|
|
|
|
bool got_accelerator;
|
|
|
|
int got_key_event_alt_count;
|
|
|
|
bool got_key_event_char;
|
|
|
|
|
|
|
|
void TriggerAccelerator(CefRefPtr<CefWindow> window) {
|
|
|
|
window->SendKeyPress(kChar, EVENTFLAG_ALT_DOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnKeyEvent(CefRefPtr<CefWindow> window, const CefKeyEvent& event) {
|
|
|
|
if (event.type != KEYEVENT_RAWKEYDOWN)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (event.windows_key_code == VK_MENU) {
|
|
|
|
// First we get the ALT key press in all cases.
|
|
|
|
EXPECT_FALSE(got_key_event_char);
|
|
|
|
if (got_key_event_alt_count == 0)
|
|
|
|
EXPECT_FALSE(got_accelerator);
|
|
|
|
else
|
|
|
|
EXPECT_TRUE(got_accelerator);
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
EXPECT_EQ(EVENTFLAG_ALT_DOWN, static_cast<int>(event.modifiers));
|
2017-02-17 00:19:43 +01:00
|
|
|
got_key_event_alt_count++;
|
|
|
|
} else if (event.windows_key_code == kChar) {
|
|
|
|
// Then we get the char key press with the ALT modifier if the accelerator
|
|
|
|
// isn't registered.
|
|
|
|
EXPECT_TRUE(got_accelerator);
|
|
|
|
EXPECT_EQ(got_key_event_alt_count, 2);
|
|
|
|
EXPECT_FALSE(got_key_event_char);
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
EXPECT_EQ(EVENTFLAG_ALT_DOWN, static_cast<int>(event.modifiers));
|
2017-02-17 00:19:43 +01:00
|
|
|
got_key_event_char = true;
|
|
|
|
|
|
|
|
// Call this method just to make sure it doesn't crash.
|
|
|
|
window->RemoveAllAccelerators();
|
|
|
|
|
|
|
|
// End the test by closing the Window.
|
|
|
|
window->Close();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OnAccelerator(CefRefPtr<CefWindow> window, int command_id) {
|
|
|
|
EXPECT_FALSE(got_accelerator);
|
|
|
|
EXPECT_EQ(got_key_event_alt_count, 1);
|
|
|
|
EXPECT_FALSE(got_key_event_char);
|
|
|
|
|
|
|
|
EXPECT_EQ(kCloseWindowId, command_id);
|
|
|
|
got_accelerator = true;
|
|
|
|
|
|
|
|
// Remove the accelerator.
|
|
|
|
window->RemoveAccelerator(kCloseWindowId);
|
|
|
|
|
|
|
|
// Now send the event without the accelerator registered. Should result in a
|
|
|
|
// call to OnKeyEvent.
|
|
|
|
TriggerAccelerator(window);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunWindowAccelerator(CefRefPtr<CefWindow> window) {
|
|
|
|
window->SetAccelerator(kCloseWindowId, kChar, false, false, true);
|
|
|
|
window->Show();
|
|
|
|
|
|
|
|
CefPostDelayedTask(TID_UI, base::Bind(TriggerAccelerator, window),
|
|
|
|
kStateDelayMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyWindowAccelerator(CefRefPtr<CefWindow> window) {
|
|
|
|
EXPECT_TRUE(got_accelerator);
|
|
|
|
EXPECT_EQ(got_key_event_alt_count, 2);
|
|
|
|
EXPECT_TRUE(got_key_event_char);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expected order of events:
|
|
|
|
// 1. OnKeyEvent for ALT key press.
|
|
|
|
// 2. OnAccelerator for ALT+Char key press (with accelerator registered).
|
|
|
|
// 3. OnKeyEvent for ALT key press.
|
|
|
|
// 4. OnKeyEvent for ALT+Char key press (without accelerator registered).
|
|
|
|
void WindowAcceleratorImpl(CefRefPtr<CefWaitableEvent> event) {
|
|
|
|
got_accelerator = false;
|
|
|
|
got_key_event_alt_count = 0;
|
|
|
|
got_key_event_char = false;
|
|
|
|
|
|
|
|
TestWindowDelegate::Config config;
|
|
|
|
config.on_window_created = base::Bind(RunWindowAccelerator);
|
|
|
|
config.on_window_destroyed = base::Bind(VerifyWindowAccelerator);
|
|
|
|
config.on_accelerator = base::Bind(OnAccelerator);
|
|
|
|
config.on_key_event = base::Bind(OnKeyEvent);
|
|
|
|
config.close_window = false;
|
|
|
|
TestWindowDelegate::RunTest(event, config);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test window functionality. This is primarily to exercise exposed CEF APIs
|
|
|
|
// and is not intended to comprehensively test window-related behavior (which
|
|
|
|
// we presume that Chromium is testing).
|
2019-03-13 22:27:37 +01:00
|
|
|
WINDOW_TEST_ASYNC(WindowCreate)
|
|
|
|
WINDOW_TEST_ASYNC(WindowCreateFrameless)
|
|
|
|
WINDOW_TEST_ASYNC(WindowShowHide)
|
|
|
|
WINDOW_TEST_ASYNC(WindowShowHideFrameless)
|
|
|
|
WINDOW_TEST_ASYNC(WindowLayoutAndCoords)
|
|
|
|
WINDOW_TEST_ASYNC(WindowLayoutAndCoordsFrameless)
|
|
|
|
WINDOW_TEST_ASYNC(WindowMaximize)
|
|
|
|
WINDOW_TEST_ASYNC(WindowMaximizeFrameless)
|
|
|
|
WINDOW_TEST_ASYNC(WindowMinimize)
|
|
|
|
WINDOW_TEST_ASYNC(WindowMinimizeFrameless)
|
|
|
|
WINDOW_TEST_ASYNC(WindowFullscreen)
|
|
|
|
WINDOW_TEST_ASYNC(WindowFullscreenFrameless)
|
|
|
|
WINDOW_TEST_ASYNC(WindowIcon)
|
|
|
|
WINDOW_TEST_ASYNC(WindowIconFrameless)
|
|
|
|
WINDOW_TEST_ASYNC(WindowAccelerator)
|