Commit dd6b5482 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Improve contents settings bubble tests.

TestContentSettingImagePressed() wasn't actually verifying that the
image in question was visible before "pressing" it.  Fixing this
caused several different tests to start failing because they weren't
actually triggering the permission requests they thought they were
(but didn't previously detect it).  Fix these tests and improve the
InvokeUi cases to all show a requesting URL (of "example.com").

Bug: none
Change-Id: Ic64e233163d82d71e88cbb09e3da9a26ed2aede5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067745Reviewed-by: default avatarOrin Jaworski <orinj@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744046}
parent 94d3ced1
......@@ -13,12 +13,13 @@
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/permissions/permission_request_manager.h"
#include "components/permissions/test/permission_request_observer.h"
#include "content/public/test/browser_test_utils.h"
class ContentSettingBubbleContentsBrowserTest : public InProcessBrowserTest {
public:
ContentSettingBubbleContentsBrowserTest() = default;
~ContentSettingBubbleContentsBrowserTest() override {}
~ContentSettingBubbleContentsBrowserTest() override = default;
protected:
GURL GetTestPageUrl(const std::string& name) {
......@@ -30,13 +31,6 @@ class ContentSettingBubbleContentsBrowserTest : public InProcessBrowserTest {
content::WebContents* GetWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
bool ExecuteScript(const std::string& script) {
return content::ExecuteScript(GetWebContents(), script);
}
private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleContentsBrowserTest);
};
IN_PROC_BROWSER_TEST_F(ContentSettingBubbleContentsBrowserTest,
......@@ -46,11 +40,13 @@ IN_PROC_BROWSER_TEST_F(ContentSettingBubbleContentsBrowserTest,
// Navigate to the test page, and have it request and be denied geolocation
// permissions.
ui_test_utils::NavigateToURL(browser(), GetTestPageUrl("geolocation.html"));
ASSERT_TRUE(content::NavigateToURL(GetWebContents(),
GetTestPageUrl("geolocation.html")));
permissions::PermissionRequestManager::FromWebContents(GetWebContents())
->set_auto_response_for_test(
permissions::PermissionRequestManager::DISMISS);
ExecuteScript("geolocate();");
ASSERT_TRUE(content::ExecJs(GetWebContents(), "geolocate();"));
permissions::PermissionRequestObserver(GetWebContents()).Wait();
// Press the geolocation icon and make sure its content setting bubble shows.
LocationBarTesting* bar =
......
......@@ -102,7 +102,7 @@ void ContentSettingBubbleDialogTest::ApplyMediastreamSettings(
TabSpecificContentSettings::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents());
content_settings->OnMediaStreamPermissionSet(
GURL::EmptyGURL(), mic_setting | camera_setting, std::string(),
GURL("https://example.com/"), mic_setting | camera_setting, std::string(),
std::string(), std::string(), std::string());
}
......@@ -113,9 +113,6 @@ void ContentSettingBubbleDialogTest::ApplyContentSettingsForType(
TabSpecificContentSettings* content_settings =
TabSpecificContentSettings::FromWebContents(web_contents);
switch (content_type) {
case ContentSettingsType::GEOLOCATION:
content_settings->OnGeolocationPermissionSet(GURL::EmptyGURL(), false);
break;
case ContentSettingsType::AUTOMATIC_DOWNLOADS: {
// Automatic downloads are handled by DownloadRequestLimiter.
DownloadRequestLimiter::TabDownloadState* tab_download_state =
......@@ -127,20 +124,28 @@ void ContentSettingBubbleDialogTest::ApplyContentSettingsForType(
DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED);
break;
}
case ContentSettingsType::GEOLOCATION:
content_settings->OnGeolocationPermissionSet(GURL("https://example.com/"),
false);
break;
case ContentSettingsType::MIDI_SYSEX:
content_settings->OnMidiSysExAccessBlocked(GURL("https://example.com/"));
break;
case ContentSettingsType::POPUPS: {
GURL url(
ui_test_utils::NavigateToURL(
browser(),
embedded_test_server()->GetURL("/popup_blocker/popup-many-10.html"));
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_TRUE(content::ExecuteScript(web_contents, std::string()));
auto* helper = PopupBlockerTabHelper::FromWebContents(web_contents);
// popup-many-10.html should generate 10 blocked popups.
EXPECT_EQ(10u, helper->GetBlockedPopupsCount());
break;
}
case ContentSettingsType::PLUGINS: {
content_settings->OnContentBlocked(content_type);
case ContentSettingsType::PROTOCOL_HANDLERS:
content_settings->set_pending_protocol_handler(
ProtocolHandler::CreateProtocolHandler("mailto",
GURL("https://example.com/")));
break;
}
default:
// For all other content_types passed in, mark them as blocked.
......
......@@ -929,7 +929,9 @@ bool LocationBarView::TestContentSettingImagePressed(size_t index) {
return false;
views::View* image_view = content_setting_views_[index];
image_view->SetSize(gfx::Size(24, 24));
if (!image_view->GetVisible())
return false;
image_view->OnKeyPressed(
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE));
image_view->OnKeyReleased(
......
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