diff --git a/cef_paths2.gypi b/cef_paths2.gypi index c51ca9eab..36ffbc142 100644 --- a/cef_paths2.gypi +++ b/cef_paths2.gypi @@ -409,7 +409,6 @@ 'tests/cefsimple/simple_handler_linux.cc', ], 'ceftests_sources_common': [ - 'tests/ceftests/accessibility_unittest.cc', 'tests/ceftests/browser_info_map_unittest.cc', 'tests/ceftests/command_line_unittest.cc', 'tests/ceftests/cookie_unittest.cc', @@ -431,6 +430,8 @@ 'tests/ceftests/message_router_unittest.cc', 'tests/ceftests/navigation_unittest.cc', 'tests/ceftests/os_rendering_unittest.cc', + 'tests/ceftests/osr_accessibility_unittest.cc', + 'tests/ceftests/osr_display_unittest.cc', 'tests/ceftests/parser_unittest.cc', 'tests/ceftests/plugin_unittest.cc', 'tests/ceftests/preference_unittest.cc', diff --git a/libcef/browser/osr/browser_platform_delegate_osr.cc b/libcef/browser/osr/browser_platform_delegate_osr.cc index 2f022cc97..3ed41cff9 100644 --- a/libcef/browser/osr/browser_platform_delegate_osr.cc +++ b/libcef/browser/osr/browser_platform_delegate_osr.cc @@ -198,6 +198,16 @@ void CefBrowserPlatformDelegateOsr::WasHidden(bool hidden) { else view->Show(); } + + // Also notify the WebContentsImpl for consistency. + content::WebContentsImpl* web_contents = + static_cast(browser_->web_contents()); + if (web_contents) { + if (hidden) + web_contents->WasHidden(); + else + web_contents->WasShown(); + } } void CefBrowserPlatformDelegateOsr::NotifyScreenInfoChanged() { diff --git a/tests/ceftests/accessibility_unittest.cc b/tests/ceftests/osr_accessibility_unittest.cc similarity index 94% rename from tests/ceftests/accessibility_unittest.cc rename to tests/ceftests/osr_accessibility_unittest.cc index ec30b716e..a145034d2 100644 --- a/tests/ceftests/accessibility_unittest.cc +++ b/tests/ceftests/osr_accessibility_unittest.cc @@ -16,17 +16,17 @@ namespace { const char kTestUrl[] = "https://tests/AccessibilityTestHandler"; const char kTipText[] = "Also known as User ID"; -// default osr widget size +// Default OSR widget size. const int kOsrWidth = 600; const int kOsrHeight = 400; -// test type +// Test type. enum AccessibilityTestType { // Enabling Accessibility should trigger the AccessibilityHandler callback // with Accessibility tree details - TEST_ENABLE_ACCESSIBILITY, + TEST_ENABLE, // Disabling Accessibility should disable accessibility notification changes - TEST_DISABLE_ACCESSIBILITY, + TEST_DISABLE, // Focus change on element should trigger Accessibility focus event TEST_FOCUS_CHANGE, // Hide/Show etc should trigger Location Change callbacks @@ -44,10 +44,10 @@ class AccessibilityTestHandler : public TestHandler, return this; } - CefRefPtr GetRenderHandler() OVERRIDE { return this; } + CefRefPtr GetRenderHandler() override { return this; } // Cef Renderer Handler Methods - bool GetViewRect(CefRefPtr browser, CefRect& rect) OVERRIDE { + bool GetViewRect(CefRefPtr browser, CefRect& rect) override { rect = CefRect(0, 0, kOsrWidth, kOsrHeight); return true; } @@ -64,27 +64,10 @@ class AccessibilityTestHandler : public TestHandler, const CefRenderHandler::RectList& dirtyRects, const void* buffer, int width, - int height) OVERRIDE { + int height) override { // Do nothing. } - // OSRTestHandler functions - void CreateOSRBrowser(const CefString& url) { - CefWindowInfo windowInfo; - CefBrowserSettings settings; - -#if defined(OS_WIN) - windowInfo.SetAsWindowless(GetDesktopWindow()); -#elif defined(OS_MACOSX) - windowInfo.SetAsWindowless(kNullWindowHandle); -#elif defined(OS_LINUX) - windowInfo.SetAsWindowless(kNullWindowHandle); -#else -#error "Unsupported platform" -#endif - CefBrowserHost::CreateBrowser(windowInfo, this, url, settings, NULL); - } - void RunTest() override { std::string html = "AccessibilityTest" @@ -111,11 +94,11 @@ class AccessibilityTestHandler : public TestHandler, // Enable Accessibility browser->GetHost()->SetAccessibilityState(STATE_ENABLED); switch (test_type_) { - case TEST_ENABLE_ACCESSIBILITY: { + case TEST_ENABLE: { // This should trigger OnAccessibilityTreeChange // And update will be validated } break; - case TEST_DISABLE_ACCESSIBILITY: { + case TEST_DISABLE: { // Post a delayed task to disable Accessibility CefPostDelayedTask( TID_UI, @@ -131,12 +114,12 @@ class AccessibilityTestHandler : public TestHandler, } } - void OnAccessibilityTreeChange(CefRefPtr value) OVERRIDE { + void OnAccessibilityTreeChange(CefRefPtr value) override { switch (test_type_) { - case TEST_ENABLE_ACCESSIBILITY: { + case TEST_ENABLE: { TestEnableAccessibilityUpdate(value); } break; - case TEST_DISABLE_ACCESSIBILITY: { + case TEST_DISABLE: { // Once Accessibility is disabled in the delayed Task // We should not reach here EXPECT_FALSE(accessibility_disabled_); @@ -217,7 +200,7 @@ class AccessibilityTestHandler : public TestHandler, } } - void OnAccessibilityLocationChange(CefRefPtr value) OVERRIDE { + void OnAccessibilityLocationChange(CefRefPtr value) override { if (test_type_ == TEST_LOCATION_CHANGE) { EXPECT_TRUE(edit_box_id_ != -1); EXPECT_TRUE(value.get()); @@ -259,6 +242,22 @@ class AccessibilityTestHandler : public TestHandler, } private: + void CreateOSRBrowser(const CefString& url) { + CefWindowInfo windowInfo; + CefBrowserSettings settings; + +#if defined(OS_WIN) + windowInfo.SetAsWindowless(GetDesktopWindow()); +#elif defined(OS_MACOSX) + windowInfo.SetAsWindowless(kNullWindowHandle); +#elif defined(OS_LINUX) + windowInfo.SetAsWindowless(kNullWindowHandle); +#else +#error "Unsupported platform" +#endif + CefBrowserHost::CreateBrowser(windowInfo, this, url, settings, NULL); + } + void HideEditBox(CefRefPtr browser) { // Set focus on edit box // This should trigger Location update if enabled @@ -426,34 +425,30 @@ class AccessibilityTestHandler : public TestHandler, } // namespace -TEST(AccessibilityTest, EnableAccessibility) { +TEST(OSRTest, AccessibilityEnable) { CefRefPtr handler = - new AccessibilityTestHandler(TEST_ENABLE_ACCESSIBILITY); + new AccessibilityTestHandler(TEST_ENABLE); handler->ExecuteTest(); - EXPECT_TRUE(true); ReleaseAndWaitForDestructor(handler); } -TEST(AccessibilityTest, DisableAccessibility) { +TEST(OSRTest, AccessibilityDisable) { CefRefPtr handler = - new AccessibilityTestHandler(TEST_DISABLE_ACCESSIBILITY); + new AccessibilityTestHandler(TEST_DISABLE); handler->ExecuteTest(); - EXPECT_TRUE(true); ReleaseAndWaitForDestructor(handler); } -TEST(AccessibilityTest, FocusChange) { +TEST(OSRTest, AccessibilityFocusChange) { CefRefPtr handler = new AccessibilityTestHandler(TEST_FOCUS_CHANGE); handler->ExecuteTest(); - EXPECT_TRUE(true); ReleaseAndWaitForDestructor(handler); } -TEST(AccessibilityTest, LocationChange) { +TEST(OSRTest, AccessibilityLocationChange) { CefRefPtr handler = new AccessibilityTestHandler(TEST_LOCATION_CHANGE); handler->ExecuteTest(); - EXPECT_TRUE(true); ReleaseAndWaitForDestructor(handler); } diff --git a/tests/ceftests/osr_display_unittest.cc b/tests/ceftests/osr_display_unittest.cc new file mode 100644 index 000000000..6ed7379d5 --- /dev/null +++ b/tests/ceftests/osr_display_unittest.cc @@ -0,0 +1,174 @@ +// Copyright (c) 2017 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 "include/base/cef_bind.h" +#include "include/wrapper/cef_closure_task.h" + +#include "tests/ceftests/routing_test_handler.h" +#include "tests/gtest/include/gtest/gtest.h" + +namespace { + +const char kTestUrl1[] = "https://tests/DisplayTestHandler.START"; +const char kTestUrl2[] = "https://tests/DisplayTestHandler.NAVIGATE"; +const char kTestMsg[] = "DisplayTestHandler.Status"; + +// Default OSR widget size. +const int kOsrWidth = 600; +const int kOsrHeight = 400; + +class DisplayTestHandler : public RoutingTestHandler, public CefRenderHandler { + public: + DisplayTestHandler() : status_(START) {} + + CefRefPtr GetRenderHandler() override { return this; } + + bool GetViewRect(CefRefPtr browser, CefRect& rect) override { + rect = CefRect(0, 0, kOsrWidth, kOsrHeight); + return true; + } + + bool GetScreenInfo(CefRefPtr browser, + CefScreenInfo& screen_info) override { + screen_info.rect = CefRect(0, 0, kOsrWidth, kOsrHeight); + screen_info.available_rect = screen_info.rect; + return true; + } + + void OnPaint(CefRefPtr browser, + CefRenderHandler::PaintElementType type, + const CefRenderHandler::RectList& dirtyRects, + const void* buffer, + int width, + int height) override { + if (!got_paint_[status_]) { + got_paint_[status_].yes(); + + if (status_ == START) + OnStartIfDone(); + else if (status_ == SHOW) + CefPostTask(TID_UI, base::Bind(&DisplayTestHandler::DestroyTest, this)); + else + EXPECT_FALSE(true); // Not reached. + } + } + + void RunTest() override { + // Add the resources that we will navigate to/from. + AddResource(kTestUrl1, GetPageContents("Page1", "START"), "text/html"); + AddResource(kTestUrl2, GetPageContents("Page2", "NAVIGATE"), "text/html"); + + // Create the browser. + CreateOSRBrowser(kTestUrl1); + + // Time out the test after a reasonable period of time. + SetTestTimeout(5000); + } + + bool OnQuery(CefRefPtr browser, + CefRefPtr frame, + int64 query_id, + const CefString& request, + bool persistent, + CefRefPtr callback) override { + const std::string& request_str = request.ToString(); + if (request_str.find(kTestMsg) == 0) { + const std::string& status = request_str.substr(sizeof(kTestMsg)); + if (status == "START") { + got_start_msg_.yes(); + OnStartIfDone(); + } else if (status == "NAVIGATE") { + got_navigate_msg_.yes(); + // Wait a bit to verify no OnPaint callback. + CefPostDelayedTask( + TID_UI, base::Bind(&DisplayTestHandler::OnNavigate, this), 250); + } + } + callback->Success(""); + return true; + } + + void DestroyTest() override { + EXPECT_TRUE(got_paint_[START]); + EXPECT_FALSE(got_paint_[NAVIGATE]); + EXPECT_TRUE(got_paint_[SHOW]); + + EXPECT_TRUE(got_start_msg_); + EXPECT_TRUE(got_navigate_msg_); + + EXPECT_EQ(status_, SHOW); + + RoutingTestHandler::DestroyTest(); + } + + private: + void CreateOSRBrowser(const CefString& url) { + CefWindowInfo windowInfo; + CefBrowserSettings settings; + +#if defined(OS_WIN) + windowInfo.SetAsWindowless(GetDesktopWindow()); +#else + windowInfo.SetAsWindowless(kNullWindowHandle); +#endif + + CefBrowserHost::CreateBrowser(windowInfo, this, url, settings, NULL); + } + + std::string GetPageContents(const std::string& name, + const std::string& status) { + return "Page1"; + } + + void OnStartIfDone() { + if (got_start_msg_ && got_paint_[START]) + CefPostTask(TID_UI, base::Bind(&DisplayTestHandler::OnStart, this)); + } + + void OnStart() { + EXPECT_EQ(status_, START); + + // Hide the browser. OnPaint should not be called again until + // WasHidden(false) is explicitly called. + GetBrowser()->GetHost()->WasHidden(true); + status_ = NAVIGATE; + + GetBrowser()->GetMainFrame()->LoadURL(kTestUrl2); + } + + void OnNavigate() { + EXPECT_EQ(status_, NAVIGATE); + + // Show the browser. + status_ = SHOW; + GetBrowser()->GetHost()->WasHidden(false); + + // Force a call to OnPaint. + GetBrowser()->GetHost()->Invalidate(PET_VIEW); + } + + enum Status { + START, + NAVIGATE, + SHOW, + STATUS_COUNT, + }; + Status status_; + + TrackCallback got_paint_[STATUS_COUNT]; + TrackCallback got_start_msg_; + TrackCallback got_navigate_msg_; + + IMPLEMENT_REFCOUNTING(DisplayTestHandler); +}; + +} // namespace + +// Test that browser visibility is not changed due to navigation. +TEST(OSRTest, NavigateWhileHidden) { + CefRefPtr handler = new DisplayTestHandler(); + handler->ExecuteTest(); + ReleaseAndWaitForDestructor(handler); +}