Commit 4616a063 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

views: No bubble anchor view without title revealed in immersive mode.

Bubbles are anchored to the app menu button by default. In immersive not
revealed mode, the app menu button is drawn somewhere offscreen. To
avoid the bubble being placed partially offscreen, return a null anchor
view. This will cause the bubble to be drawn in the top left corner,
just like regular fullscreen.

Test: browser_tests ImmersiveModeControllerAshWebAppBrowserTest.PermissionsBubbleAnchor
Change-Id: I1aeaea0da64d3a301a898ae5e7778d123eb2e433
Fixed: 1087143
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2311896Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Reviewed-by: default avatarWei Li <weili@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792013}
parent 6a9446f7
...@@ -34,9 +34,17 @@ AnchorConfiguration GetPageInfoAnchorConfiguration(Browser* browser, ...@@ -34,9 +34,17 @@ AnchorConfiguration GetPageInfoAnchorConfiguration(Browser* browser,
// Fall back to menu button. // Fall back to menu button.
views::Button* app_menu_button = views::Button* app_menu_button =
browser_view->toolbar_button_provider()->GetAppMenuButton(); browser_view->toolbar_button_provider()->GetAppMenuButton();
if (app_menu_button && app_menu_button->IsDrawn()) if (!app_menu_button || !app_menu_button->IsDrawn())
return {app_menu_button, app_menu_button, views::BubbleBorder::TOP_RIGHT}; return {};
return {};
// The app menu button is not visible when immersive mode is enabled and the
// title bar is not revealed. So return null anchor configuration.
if (browser_view->IsImmersiveModeEnabled() &&
!browser_view->immersive_mode_controller()->IsRevealed()) {
return {};
}
return {app_menu_button, app_menu_button, views::BubbleBorder::TOP_RIGHT};
} }
AnchorConfiguration GetPermissionPromptBubbleAnchorConfiguration( AnchorConfiguration GetPermissionPromptBubbleAnchorConfiguration(
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "chrome/browser/web_applications/test/web_app_test.h" #include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/permissions/permission_request_manager_test_api.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "content/public/test/content_mock_cert_verifier.h" #include "content/public/test/content_mock_cert_verifier.h"
#include "net/cert/mock_cert_verifier.h" #include "net/cert/mock_cert_verifier.h"
...@@ -331,6 +332,57 @@ IN_PROC_BROWSER_TEST_P(ImmersiveModeControllerAshWebAppBrowserTest, ...@@ -331,6 +332,57 @@ IN_PROC_BROWSER_TEST_P(ImmersiveModeControllerAshWebAppBrowserTest,
VerifyButtonsInImmersiveMode(frame_view); VerifyButtonsInImmersiveMode(frame_view);
} }
// Tests that the permissions bubble dialog is anchored to the correct location.
// The dialog's anchor is normally the app menu button which is on the header.
// In immersive mode but not revealed, the app menu button is placed off screen
// but still drawn. In this case, we should have a null anchor view so that the
// bubble gets placed in the default top left corner. Regression test for
// https://crbug.com/1087143.
IN_PROC_BROWSER_TEST_P(ImmersiveModeControllerAshWebAppBrowserTest,
PermissionsBubbleAnchor) {
LaunchAppBrowser();
auto test_api =
std::make_unique<test::PermissionRequestManagerTestApi>(browser());
EXPECT_TRUE(test_api->manager());
// Add a permission bubble using the test api.
test_api->AddSimpleRequest(
browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
ContentSettingsType::GEOLOCATION);
// The permission prompt is shown asynchronously. Without immersive mode
// enabled the anchor should exist.
base::RunLoop().RunUntilIdle();
views::Widget* prompt_window = test_api->GetPromptWindow();
views::BubbleDialogDelegate* bubble_dialog =
prompt_window->AsWidget()->widget_delegate()->AsBubbleDialogDelegate();
ASSERT_TRUE(bubble_dialog);
EXPECT_TRUE(bubble_dialog->GetAnchorView());
// Turn on immersive, but do not reveal. The app menu button is hidden from
// sight so the anchor should be null. The bubble will get placed in the top
// left corner of the app.
auto* immersive_mode_controller =
BrowserView::GetBrowserViewForBrowser(browser())
->immersive_mode_controller();
immersive_mode_controller->SetEnabled(true);
EXPECT_FALSE(immersive_mode_controller->IsRevealed());
EXPECT_FALSE(bubble_dialog->GetAnchorView());
// Reveal the header. The anchor should exist since the app menu button is now
// visible.
{
std::unique_ptr<ImmersiveRevealedLock> focus_reveal_lock(
immersive_mode_controller->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_YES));
EXPECT_TRUE(immersive_mode_controller->IsRevealed());
EXPECT_TRUE(bubble_dialog->GetAnchorView());
}
EXPECT_FALSE(immersive_mode_controller->IsRevealed());
EXPECT_FALSE(bubble_dialog->GetAnchorView());
}
INSTANTIATE_TEST_SUITE_P(All, INSTANTIATE_TEST_SUITE_P(All,
ImmersiveModeControllerAshWebAppBrowserTest, ImmersiveModeControllerAshWebAppBrowserTest,
::testing::Values(web_app::ProviderType::kBookmarkApps, ::testing::Values(web_app::ProviderType::kBookmarkApps,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment