Commit 62972354 authored by Olesia Marukhno's avatar Olesia Marukhno Committed by Commit Bot

Update permission prompt tests for chip UI

Also move all permission dialog browser tests to separate file.

Bug: 1148277
Change-Id: I69006766d26d8193f883df2671427cc0eecc2bd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2534855
Commit-Queue: Olesia Marukhno <olesiamarukhno@google.com>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827754}
parent 85e33f87
......@@ -199,40 +199,6 @@ class PermissionRequestManagerBrowserTest : public InProcessBrowserTest {
DISALLOW_COPY_AND_ASSIGN(PermissionRequestManagerBrowserTest);
};
// Harness for testing permissions dialogs invoked by PermissionRequestManager.
// Uses a "real" PermissionPromptFactory rather than a mock.
class PermissionDialogTest
: public SupportsTestDialog<PermissionRequestManagerBrowserTest> {
public:
PermissionDialogTest() {}
// InProcessBrowserTest:
void SetUpOnMainThread() override {
// Skip super: It will install a mock permission UI factory, but for this
// test we want to show "real" UI.
ui_test_utils::NavigateToURL(browser(),
GURL("https://toplevel.example.com"));
}
GURL GetUrl() { return GURL("https://example.com"); }
permissions::PermissionRequest* MakeRegisterProtocolHandlerRequest();
permissions::PermissionRequest* MakePermissionRequest(
ContentSettingsType permission);
void AddRequestForContentSetting(const std::string& name);
// TestBrowserDialog:
void ShowUi(const std::string& name) override;
void DismissUi() override;
// Holds requests that do not delete themselves.
std::vector<std::unique_ptr<permissions::PermissionRequest>> owned_requests_;
private:
DISALLOW_COPY_AND_ASSIGN(PermissionDialogTest);
};
class PermissionRequestManagerWithBackForwardCacheBrowserTest
: public PermissionRequestManagerBrowserTest {
public:
......@@ -247,121 +213,6 @@ class PermissionRequestManagerWithBackForwardCacheBrowserTest
base::test::ScopedFeatureList feature_list_;
};
permissions::PermissionRequest*
PermissionDialogTest::MakeRegisterProtocolHandlerRequest() {
std::string protocol = "mailto";
bool user_gesture = true;
ProtocolHandler handler =
ProtocolHandler::CreateProtocolHandler(protocol, GetUrl());
ProtocolHandlerRegistry* registry =
ProtocolHandlerRegistryFactory::GetForBrowserContext(
browser()->profile());
// Deleted in RegisterProtocolHandlerPermissionRequest::RequestFinished().
return new RegisterProtocolHandlerPermissionRequest(
registry, handler, GetUrl(), user_gesture, base::ScopedClosureRunner());
}
permissions::PermissionRequest* PermissionDialogTest::MakePermissionRequest(
ContentSettingsType permission) {
bool user_gesture = true;
auto decided = [](ContentSetting, bool) {};
auto cleanup = [] {}; // Leave cleanup to test harness destructor.
owned_requests_.push_back(
std::make_unique<permissions::PermissionRequestImpl>(
GetUrl(), permission, user_gesture, base::BindOnce(decided),
base::BindOnce(cleanup)));
return owned_requests_.back().get();
}
void PermissionDialogTest::AddRequestForContentSetting(
const std::string& name) {
constexpr const char* kMultipleName = "multiple";
constexpr struct {
const char* name;
ContentSettingsType type;
} kNameToType[] = {
{"flash", ContentSettingsType::PLUGINS},
{"geolocation", ContentSettingsType::GEOLOCATION},
{"protected_media", ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER},
{"notifications", ContentSettingsType::NOTIFICATIONS},
{"mic", ContentSettingsType::MEDIASTREAM_MIC},
{"camera", ContentSettingsType::MEDIASTREAM_CAMERA},
{"protocol_handlers", ContentSettingsType::PROTOCOL_HANDLERS},
{"midi", ContentSettingsType::MIDI_SYSEX},
{"storage_access", ContentSettingsType::STORAGE_ACCESS},
{"downloads", ContentSettingsType::AUTOMATIC_DOWNLOADS},
{kMultipleName, ContentSettingsType::DEFAULT}};
const auto* it = std::begin(kNameToType);
for (; it != std::end(kNameToType); ++it) {
if (name == it->name)
break;
}
if (it == std::end(kNameToType)) {
ADD_FAILURE() << "Unknown: " << name;
return;
}
permissions::PermissionRequestManager* manager =
GetPermissionRequestManager();
content::RenderFrameHost* source_frame = GetActiveMainFrame();
switch (it->type) {
case ContentSettingsType::PROTOCOL_HANDLERS:
manager->AddRequest(source_frame, MakeRegisterProtocolHandlerRequest());
break;
case ContentSettingsType::AUTOMATIC_DOWNLOADS:
manager->AddRequest(source_frame,
new DownloadPermissionRequest(
nullptr, url::Origin::Create(GetUrl())));
break;
case ContentSettingsType::DURABLE_STORAGE:
// TODO(tapted): Prompt for quota request.
break;
case ContentSettingsType::MEDIASTREAM_MIC:
case ContentSettingsType::MEDIASTREAM_CAMERA:
case ContentSettingsType::MIDI_SYSEX:
case ContentSettingsType::NOTIFICATIONS:
case ContentSettingsType::GEOLOCATION:
case ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER: // ChromeOS only.
case ContentSettingsType::PPAPI_BROKER:
case ContentSettingsType::PLUGINS: // Flash.
case ContentSettingsType::STORAGE_ACCESS:
manager->AddRequest(source_frame, MakePermissionRequest(it->type));
break;
case ContentSettingsType::DEFAULT:
// Permissions to request for a "multiple" request. Only mic/camera
// requests are grouped together.
EXPECT_EQ(kMultipleName, name);
manager->AddRequest(
source_frame,
MakePermissionRequest(ContentSettingsType::MEDIASTREAM_MIC));
manager->AddRequest(
source_frame,
MakePermissionRequest(ContentSettingsType::MEDIASTREAM_CAMERA));
break;
default:
ADD_FAILURE() << "Not a permission type, or one that doesn't prompt.";
return;
}
}
void PermissionDialogTest::ShowUi(const std::string& name) {
if (name == "security_key") {
// This one doesn't have a ContentSettingsType.
GetPermissionRequestManager()->AddRequest(
GetActiveMainFrame(),
NewAttestationPermissionRequest(url::Origin::Create(GetUrl()),
base::BindOnce([](bool) {})));
} else {
AddRequestForContentSetting(name);
}
base::RunLoop().RunUntilIdle();
}
void PermissionDialogTest::DismissUi() {
GetPermissionRequestManager()->Closing();
TestBrowserDialog::DismissUi();
}
// Requests before the load event should be bundled into one bubble.
// http://crbug.com/512849 flaky
IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest,
......@@ -918,145 +769,6 @@ IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest,
EXPECT_EQ(0u, GetPermissionRequestManager()->Requests().size());
}
// Test bubbles showing when tabs move between windows. Simulates a situation
// that could result in permission bubbles not being dismissed, and a problem
// referencing a temporary drag window. See http://crbug.com/754552.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, SwitchBrowserWindow) {
ShowUi("geolocation");
TabStripModel* strip = browser()->tab_strip_model();
// Drag out into a dragging window. E.g. see steps in [BrowserWindowController
// detachTabsToNewWindow:..].
std::vector<TabStripModelDelegate::NewStripContents> contentses(1);
contentses.back().add_types = TabStripModel::ADD_ACTIVE;
contentses.back().web_contents = strip->DetachWebContentsAt(0);
Browser* dragging_browser = strip->delegate()->CreateNewStripWithContents(
std::move(contentses), gfx::Rect(100, 100, 640, 480), false);
// Attach the tab back to the original window. E.g. See steps in
// [BrowserWindowController moveTabViews:..].
TabStripModel* drag_strip = dragging_browser->tab_strip_model();
std::unique_ptr<content::WebContents> removed_contents =
drag_strip->DetachWebContentsAt(0);
strip->InsertWebContentsAt(0, std::move(removed_contents),
TabStripModel::ADD_ACTIVE);
// Clear the request. There should be no crash.
test::PermissionRequestManagerTestApi(GetPermissionRequestManager())
.SimulateWebContentsDestroyed();
owned_requests_.clear();
}
// crbug.com/989858
#if defined(OS_WIN)
#define MAYBE_ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest \
DISABLED_ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest
#else
#define MAYBE_ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest \
ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest
#endif
// Regression test for https://crbug.com/933321.
IN_PROC_BROWSER_TEST_F(
PermissionDialogTest,
MAYBE_ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest) {
ShowUi("geolocation");
ASSERT_TRUE(VerifyUi());
// Simulate a render process crash while the permission prompt is pending.
content::RenderViewHost* render_view_host = browser()
->tab_strip_model()
->GetActiveWebContents()
->GetMainFrame()
->GetRenderViewHost();
content::RenderProcessHost* render_process_host =
render_view_host->GetProcess();
content::RenderProcessHostWatcher crash_observer(
render_process_host,
content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
ASSERT_TRUE(render_process_host->Shutdown(0));
crash_observer.Wait();
// The permission request is still pending, but the BrowserView's WebView is
// now showing a crash overlay, so the permission prompt is hidden.
//
// Now close the tab. This will first detach the WebContents, causing the
// WebView's crash overlay to be torn down, which, in turn, will temporarily
// make the dying WebContents visible again, albeit without being attached to
// any BrowserView.
//
// Wait until the WebContents, and with it, the PermissionRequestManager, is
// gone, and make sure nothing crashes.
content::WebContentsDestroyedWatcher web_contents_destroyed_watcher(
browser()->tab_strip_model()->GetActiveWebContents());
browser()->tab_strip_model()->CloseAllTabs();
web_contents_destroyed_watcher.Wait();
}
// Host wants to run flash.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_flash) {
ShowAndVerifyUi();
}
// Host wants to know your location.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_geolocation) {
ShowAndVerifyUi();
}
// Host wants to show notifications.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_notifications) {
ShowAndVerifyUi();
}
// Host wants to use your microphone.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_mic) {
ShowAndVerifyUi();
}
// Host wants to use your camera.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_camera) {
ShowAndVerifyUi();
}
// Host wants to open email links.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_protocol_handlers) {
ShowAndVerifyUi();
}
// Host wants to use your MIDI devices.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_midi) {
ShowAndVerifyUi();
}
// Host wants to access storage from the site in which it's embedded.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_storage_access) {
ShowAndVerifyUi();
}
// Host wants to trigger multiple downloads.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_downloads) {
ShowAndVerifyUi();
}
// Host wants to access data about your security key.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_security_key) {
ShowAndVerifyUi();
}
// Shows a permissions bubble with multiple requests.
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeUi_multiple) {
ShowAndVerifyUi();
}
// ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER is ChromeOS only.
#if defined(OS_CHROMEOS)
#define MAYBE_InvokeUi_protected_media InvokeUi_protected_media
#else
#define MAYBE_InvokeUi_protected_media DISABLED_InvokeUi_protected_media
#endif
IN_PROC_BROWSER_TEST_F(PermissionDialogTest, MAYBE_InvokeUi_protected_media) {
ShowAndVerifyUi();
}
IN_PROC_BROWSER_TEST_F(PermissionRequestManagerWithBackForwardCacheBrowserTest,
NoPermissionBubbleShownForPagesInCache) {
ASSERT_TRUE(embedded_test_server()->Start());
......
......@@ -59,6 +59,10 @@ class PermissionChip : public views::View,
// BubbleOwnerDelegate:
bool IsBubbleShowing() const override;
PermissionPromptBubbleView* prompt_bubble_for_testing() {
return prompt_bubble_;
}
private:
void ChipButtonPressed();
void Collapse();
......
// Copyright 2020 The Chromium 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 "base/run_loop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/location_bar/permission_chip.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/test/permissions/permission_request_manager_test_api.h"
#include "components/permissions/features.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/test/button_test_api.h"
class PermissionChipPromptBrowserTest : public DialogBrowserTest {
public:
PermissionChipPromptBrowserTest() {
feature_list_.InitAndEnableFeature(permissions::features::kPermissionChip);
}
PermissionChipPromptBrowserTest(const PermissionChipPromptBrowserTest&) =
delete;
PermissionChipPromptBrowserTest& operator=(
const PermissionChipPromptBrowserTest&) = delete;
// DialogBrowserTest:
void ShowUi(const std::string& name) override {
std::unique_ptr<test::PermissionRequestManagerTestApi> test_api_ =
std::make_unique<test::PermissionRequestManagerTestApi>(browser());
EXPECT_TRUE(test_api_->manager());
test_api_->AddSimpleRequest(GetActiveMainFrame(),
ContentSettingsType::GEOLOCATION);
base::RunLoop().RunUntilIdle();
BrowserView* browser_view =
BrowserView::GetBrowserViewForBrowser(browser());
PermissionChip* permission_chip =
browser_view->toolbar()->location_bar()->permission_chip();
ASSERT_TRUE(permission_chip);
views::test::ButtonTestApi(permission_chip->button())
.NotifyClick(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(),
gfx::Point(), ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, 0));
}
content::RenderFrameHost* GetActiveMainFrame() {
return browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
}
private:
base::test::ScopedFeatureList feature_list_;
};
IN_PROC_BROWSER_TEST_F(PermissionChipPromptBrowserTest, InvokeUi_geolocation) {
ShowAndVerifyUi();
}
......@@ -2,47 +2,342 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/feature_list.h"
#include "base/run_loop.h"
#include "build/build_config.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include "chrome/browser/custom_handlers/register_protocol_handler_permission_request.h"
#include "chrome/browser/download/download_permission_request.h"
#include "chrome/browser/permissions/attestation_permission_request.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/permission_chip.h"
#include "chrome/browser/ui/views/permission_bubble/permission_prompt_bubble_view.h"
#include "chrome/browser/ui/views/permission_bubble/permission_prompt_impl.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/permissions/permission_request_manager_test_api.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_request_impl.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "ui/events/base_event_utils.h"
#include "ui/views/test/ax_event_counter.h"
#include "ui/views/test/button_test_api.h"
class PermissionPromptBubbleViewBrowserTest : public DialogBrowserTest {
class PermissionPromptBubbleViewBrowserTest
: public DialogBrowserTest,
public ::testing::WithParamInterface<bool> {
public:
PermissionPromptBubbleViewBrowserTest() = default;
PermissionPromptBubbleViewBrowserTest() {
feature_list_.InitWithFeatureState(permissions::features::kPermissionChip,
GetParam());
}
PermissionPromptBubbleViewBrowserTest(
const PermissionPromptBubbleViewBrowserTest&) = delete;
PermissionPromptBubbleViewBrowserTest& operator=(
const PermissionPromptBubbleViewBrowserTest&) = delete;
// DialogBrowserTest:
void ShowUi(const std::string& name) override {
std::unique_ptr<test::PermissionRequestManagerTestApi> test_api_ =
// InProcessBrowserTest:
void SetUpOnMainThread() override {
ui_test_utils::NavigateToURL(browser(),
GURL("https://toplevel.example.com"));
test_api_ =
std::make_unique<test::PermissionRequestManagerTestApi>(browser());
EXPECT_TRUE(test_api_->manager());
test_api_->AddSimpleRequest(
browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
ContentSettingsType::GEOLOCATION);
}
// DialogBrowserTest:
void ShowUi(const std::string& name) override {
const std::string& actual_name = name.substr(0, name.find("/"));
if (actual_name == "security_key") {
// This one doesn't have a ContentSettingsType.
test_api_->manager()->AddRequest(
GetActiveMainFrame(),
NewAttestationPermissionRequest(url::Origin::Create(GetTestUrl()),
base::BindOnce([](bool) {})));
} else {
AddRequestForContentSetting(actual_name);
}
base::RunLoop().RunUntilIdle();
PermissionChip* permission_chip = GetPermissionChipView();
if (permission_chip->GetVisible()) {
views::test::ButtonTestApi(permission_chip->button())
.NotifyClick(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(),
gfx::Point(), ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, 0));
base::RunLoop().RunUntilIdle();
}
}
};
IN_PROC_BROWSER_TEST_F(PermissionPromptBubbleViewBrowserTest,
InvokeUi_geolocation) {
ShowAndVerifyUi();
}
bool VerifyUi() override {
const bool should_close_on_deactivate =
GetPermissionChipView()->GetVisible();
views::Widget* prompt_widget = test_api_->GetPromptWindow();
views::BubbleDialogDelegate* bubble_dialog =
prompt_widget->widget_delegate()->AsBubbleDialogDelegate();
EXPECT_EQ(bubble_dialog->close_on_deactivate(), should_close_on_deactivate);
return DialogBrowserTest::VerifyUi();
}
GURL GetTestUrl() { return GURL("https://example.com"); }
content::RenderFrameHost* GetActiveMainFrame() {
return browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame();
}
PermissionChip* GetPermissionChipView() {
BrowserView* browser_view =
BrowserView::GetBrowserViewForBrowser(browser());
return browser_view->toolbar()->location_bar()->permission_chip();
}
IN_PROC_BROWSER_TEST_F(PermissionPromptBubbleViewBrowserTest,
permissions::PermissionRequest* MakeRegisterProtocolHandlerRequest() {
std::string protocol = "mailto";
bool user_gesture = true;
ProtocolHandler handler =
ProtocolHandler::CreateProtocolHandler(protocol, GetTestUrl());
ProtocolHandlerRegistry* registry =
ProtocolHandlerRegistryFactory::GetForBrowserContext(
browser()->profile());
// Deleted in RegisterProtocolHandlerPermissionRequest::RequestFinished().
return new RegisterProtocolHandlerPermissionRequest(
registry, handler, GetTestUrl(), user_gesture,
base::ScopedClosureRunner());
}
void AddRequestForContentSetting(const std::string& name) {
constexpr const char* kMultipleName = "multiple";
constexpr struct {
const char* name;
ContentSettingsType type;
} kNameToType[] = {
{"flash", ContentSettingsType::PLUGINS},
{"geolocation", ContentSettingsType::GEOLOCATION},
{"protected_media", ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER},
{"notifications", ContentSettingsType::NOTIFICATIONS},
{"mic", ContentSettingsType::MEDIASTREAM_MIC},
{"camera", ContentSettingsType::MEDIASTREAM_CAMERA},
{"protocol_handlers", ContentSettingsType::PROTOCOL_HANDLERS},
{"midi", ContentSettingsType::MIDI_SYSEX},
{"storage_access", ContentSettingsType::STORAGE_ACCESS},
{"downloads", ContentSettingsType::AUTOMATIC_DOWNLOADS},
{kMultipleName, ContentSettingsType::DEFAULT}};
const auto* it = std::begin(kNameToType);
for (; it != std::end(kNameToType); ++it) {
if (name == it->name)
break;
}
if (it == std::end(kNameToType)) {
ADD_FAILURE() << "Unknown: " << name;
return;
}
permissions::PermissionRequestManager* manager = test_api_->manager();
content::RenderFrameHost* source_frame = GetActiveMainFrame();
switch (it->type) {
case ContentSettingsType::PROTOCOL_HANDLERS:
manager->AddRequest(source_frame, MakeRegisterProtocolHandlerRequest());
break;
case ContentSettingsType::AUTOMATIC_DOWNLOADS:
manager->AddRequest(source_frame,
new DownloadPermissionRequest(
nullptr, url::Origin::Create(GetTestUrl())));
break;
case ContentSettingsType::DURABLE_STORAGE:
// TODO(tapted): Prompt for quota request.
break;
case ContentSettingsType::MEDIASTREAM_MIC:
case ContentSettingsType::MEDIASTREAM_CAMERA:
case ContentSettingsType::MIDI_SYSEX:
case ContentSettingsType::NOTIFICATIONS:
case ContentSettingsType::GEOLOCATION:
case ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER: // ChromeOS only.
case ContentSettingsType::PPAPI_BROKER:
case ContentSettingsType::PLUGINS: // Flash.
case ContentSettingsType::STORAGE_ACCESS:
test_api_->AddSimpleRequest(source_frame, it->type);
break;
case ContentSettingsType::DEFAULT:
// Permissions to request for a "multiple" request. Only mic/camera
// requests are grouped together.
EXPECT_EQ(kMultipleName, name);
test_api_->AddSimpleRequest(source_frame,
ContentSettingsType::MEDIASTREAM_MIC);
test_api_->AddSimpleRequest(source_frame,
ContentSettingsType::MEDIASTREAM_CAMERA);
break;
default:
ADD_FAILURE() << "Not a permission type, or one that doesn't prompt.";
return;
}
}
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<test::PermissionRequestManagerTestApi> test_api_;
};
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
AlertAccessibleEvent) {
views::test::AXEventCounter counter(views::AXEventManager::Get());
EXPECT_EQ(0, counter.GetCount(ax::mojom::Event::kAlert));
ShowUi("PermissionPromptBubble");
ShowUi("geolocation");
EXPECT_EQ(1, counter.GetCount(ax::mojom::Event::kAlert));
}
// Test bubbles showing when tabs move between windows. Simulates a situation
// that could result in permission bubbles not being dismissed, and a problem
// referencing a temporary drag window. See http://crbug.com/754552.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
SwitchBrowserWindow) {
ShowUi("geolocation");
TabStripModel* strip = browser()->tab_strip_model();
// Drag out into a dragging window. E.g. see steps in [BrowserWindowController
// detachTabsToNewWindow:..].
std::vector<TabStripModelDelegate::NewStripContents> contentses(1);
contentses.back().add_types = TabStripModel::ADD_ACTIVE;
contentses.back().web_contents = strip->DetachWebContentsAt(0);
Browser* dragging_browser = strip->delegate()->CreateNewStripWithContents(
std::move(contentses), gfx::Rect(100, 100, 640, 480), false);
// Attach the tab back to the original window. E.g. See steps in
// [BrowserWindowController moveTabViews:..].
TabStripModel* drag_strip = dragging_browser->tab_strip_model();
std::unique_ptr<content::WebContents> removed_contents =
drag_strip->DetachWebContentsAt(0);
strip->InsertWebContentsAt(0, std::move(removed_contents),
TabStripModel::ADD_ACTIVE);
// Clear the request. There should be no crash.
test_api_->SimulateWebContentsDestroyed();
}
// crbug.com/989858
#if defined(OS_WIN)
#define MAYBE_ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest \
DISABLED_ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest
#else
#define MAYBE_ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest \
ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest
#endif
// Regression test for https://crbug.com/933321.
IN_PROC_BROWSER_TEST_P(
PermissionPromptBubbleViewBrowserTest,
MAYBE_ActiveTabClosedAfterRendererCrashesWithPendingPermissionRequest) {
ShowUi("geolocation");
ASSERT_TRUE(VerifyUi());
// Simulate a render process crash while the permission prompt is pending.
content::RenderViewHost* render_view_host = browser()
->tab_strip_model()
->GetActiveWebContents()
->GetMainFrame()
->GetRenderViewHost();
content::RenderProcessHost* render_process_host =
render_view_host->GetProcess();
content::RenderProcessHostWatcher crash_observer(
render_process_host,
content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
ASSERT_TRUE(render_process_host->Shutdown(0));
crash_observer.Wait();
// The permission request is still pending, but the BrowserView's WebView is
// now showing a crash overlay, so the permission prompt is hidden.
//
// Now close the tab. This will first detach the WebContents, causing the
// WebView's crash overlay to be torn down, which, in turn, will temporarily
// make the dying WebContents visible again, albeit without being attached to
// any BrowserView.
//
// Wait until the WebContents, and with it, the PermissionRequestManager, is
// gone, and make sure nothing crashes.
content::WebContentsDestroyedWatcher web_contents_destroyed_watcher(
browser()->tab_strip_model()->GetActiveWebContents());
browser()->tab_strip_model()->CloseAllTabs();
web_contents_destroyed_watcher.Wait();
}
// Host wants to run flash.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest, InvokeUi_flash) {
ShowAndVerifyUi();
}
// Host wants to know your location.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
InvokeUi_geolocation) {
ShowAndVerifyUi();
}
// Host wants to show notifications.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
InvokeUi_notifications) {
ShowAndVerifyUi();
}
// Host wants to use your microphone.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest, InvokeUi_mic) {
ShowAndVerifyUi();
}
// Host wants to use your camera.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest, InvokeUi_camera) {
ShowAndVerifyUi();
}
// Host wants to open email links.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
InvokeUi_protocol_handlers) {
ShowAndVerifyUi();
}
// Host wants to use your MIDI devices.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest, InvokeUi_midi) {
ShowAndVerifyUi();
}
// Host wants to access storage from the site in which it's embedded.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
InvokeUi_storage_access) {
ShowAndVerifyUi();
}
// Host wants to trigger multiple downloads.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
InvokeUi_downloads) {
ShowAndVerifyUi();
}
// Host wants to access data about your security key.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
InvokeUi_security_key) {
ShowAndVerifyUi();
}
// Shows a permissions bubble with multiple requests.
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
InvokeUi_multiple) {
ShowAndVerifyUi();
}
// ContentSettingsType::PROTECTED_MEDIA_IDENTIFIER is ChromeOS only.
#if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_P(PermissionPromptBubbleViewBrowserTest,
InvokeUi_protected_media) {
ShowAndVerifyUi();
}
#endif
INSTANTIATE_TEST_SUITE_P(All,
PermissionPromptBubbleViewBrowserTest,
::testing::Values(false, true));
......@@ -36,7 +36,10 @@ class PermissionPromptImpl : public permissions::PermissionPrompt,
const override;
PermissionPromptBubbleView* prompt_bubble_for_testing() {
return prompt_bubble_;
if (prompt_bubble_)
return prompt_bubble_;
return permission_chip_ ? permission_chip_->prompt_bubble_for_testing()
: nullptr;
}
// views::WidgetObserver:
......
......@@ -2223,7 +2223,6 @@ if (!is_android) {
"../browser/ui/views/location_bar/location_bar_view_browsertest.cc",
"../browser/ui/views/location_bar/location_icon_view_browsertest.cc",
"../browser/ui/views/location_bar/permission_chip_browsertest.cc",
"../browser/ui/views/location_bar/permission_chip_prompt_browsertest.cc",
"../browser/ui/views/location_bar/zoom_bubble_view_browsertest.cc",
"../browser/ui/views/media_router/cast_dialog_view_browsertest.cc",
"../browser/ui/views/media_router/media_router_dialog_controller_views_browsertest.cc",
......
......@@ -171,6 +171,8 @@ class PermissionRequestManager
view_factory_ = std::move(view_factory);
}
PermissionPrompt* view_for_testing() { return view_.get(); }
private:
friend class test::PermissionRequestManagerTestApi;
friend class content::WebContentsUserData<PermissionRequestManager>;
......
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