| Index: chrome/browser/ui/views/location_bar/content_setting_bubble_dialog_browsertest.cc
|
| diff --git a/chrome/browser/ui/views/location_bar/content_setting_bubble_dialog_browsertest.cc b/chrome/browser/ui/views/location_bar/content_setting_bubble_dialog_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d209b541952081ffddcc107d3fcf4b2cfe0025e6
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/location_bar/content_setting_bubble_dialog_browsertest.cc
|
| @@ -0,0 +1,180 @@
|
| +// Copyright 2017 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/memory/ptr_util.h"
|
| +#include "base/time/time.h"
|
| +#include "chrome/browser/content_settings/tab_specific_content_settings.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
|
| +#include "chrome/browser/ui/location_bar/location_bar.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/browser/ui/test/test_browser_dialog.h"
|
| +#include "chrome/browser/ui/views/content_setting_bubble_contents.h"
|
| +#include "chrome/browser/ui/views/frame/browser_view.h"
|
| +#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
|
| +#include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
|
| +#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
|
| +#include "chrome/test/base/in_process_browser_test.h"
|
| +#include "components/content_settings/core/common/content_settings_types.h"
|
| +#include "ui/events/event.h"
|
| +#include "ui/events/event_constants.h"
|
| +#include "ui/views/view.h"
|
| +#include "ui/views/widget/widget.h"
|
| +#include "url/gurl.h"
|
| +
|
| +class ContentSettingBubbleDialogTest : public DialogBrowserTest {
|
| + public:
|
| + ContentSettingBubbleDialogTest() {}
|
| +
|
| + ContentSettingImageModel* GetImageModel(ContentSettingsType content_type,
|
| + LocationBarTesting* location_bar) {
|
| + for (int i = 0; i < location_bar->ContentSettingImageModelCount(); i++) {
|
| + ContentSettingImageModel* image_model =
|
| + location_bar->GetContentSettingImageModel(i);
|
| + if (image_model->content_type() == content_type)
|
| + return image_model;
|
| + }
|
| + return nullptr;
|
| + }
|
| +
|
| + void ShowDialogBubble(ContentSettingsType content_type) {
|
| + content::WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + TabSpecificContentSettings* content_settings =
|
| + TabSpecificContentSettings::FromWebContents(web_contents);
|
| + switch (content_type) {
|
| + case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
|
| + case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
|
| + content_settings->OnMediaStreamPermissionSet(
|
| + GURL::EmptyGURL(),
|
| + content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
|
| + ? TabSpecificContentSettings::MICROPHONE_ACCESSED
|
| + : TabSpecificContentSettings::CAMERA_ACCESSED,
|
| + std::string(), std::string(), std::string(), std::string());
|
| + break;
|
| + case CONTENT_SETTINGS_TYPE_GEOLOCATION:
|
| + content_settings->OnGeolocationPermissionSet(
|
| + GURL::EmptyGURL(), false);
|
| + break;
|
| + default:
|
| + content_settings->OnContentBlocked(content_type);
|
| + }
|
| + BrowserView* browser_view =
|
| + BrowserView::GetBrowserViewForBrowser(browser());
|
| + LocationBarView* location_bar_view = browser_view->GetLocationBarView();
|
| + LocationBar* location_bar = location_bar_view;
|
| + LocationBarTesting* location_bar_testing =
|
| + location_bar->GetLocationBarForTesting();
|
| + location_bar_view->Update(web_contents);
|
| + ContentSettingImageModel* image_model =
|
| + GetImageModel(content_type, location_bar_testing);
|
| + EXPECT_NE(image_model, nullptr);
|
| + ContentSettingImageView* image_view =
|
| + location_bar_view->GetContentSettingImageViewFromImageModel(
|
| + image_model);
|
| + EXPECT_NE(image_view, nullptr);
|
| + image_view->OnActivate(ui::MouseEvent(
|
| + ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0),
|
| + base::TimeTicks::Now(), ui::EF_LEFT_MOUSE_BUTTON, 0));
|
| + EXPECT_NE(image_view->bubble_view(), nullptr);
|
| + EXPECT_TRUE(image_view->bubble_view()->visible());
|
| + views::Widget* widget = image_view->bubble_view()->GetWidget();
|
| + EXPECT_TRUE(widget->IsVisible());
|
| + }
|
| +
|
| + void ShowDialog(const std::string& name) override {
|
| + const struct _content_settings_values {
|
| + std::string name;
|
| + ContentSettingsType content_type;
|
| + } content_settings_values[] = {
|
| + {std::string("cookies"), CONTENT_SETTINGS_TYPE_COOKIES},
|
| + {std::string("images"), CONTENT_SETTINGS_TYPE_IMAGES},
|
| + {std::string("javascript"), CONTENT_SETTINGS_TYPE_JAVASCRIPT},
|
| + {std::string("plugins"), CONTENT_SETTINGS_TYPE_PLUGINS},
|
| + {std::string("popups"), CONTENT_SETTINGS_TYPE_POPUPS},
|
| + {std::string("geolocation"), CONTENT_SETTINGS_TYPE_GEOLOCATION},
|
| + {std::string("ppapi_broker"), CONTENT_SETTINGS_TYPE_PPAPI_BROKER},
|
| + {std::string("mixed_script"), CONTENT_SETTINGS_TYPE_MIXEDSCRIPT},
|
| + {std::string("mediastream_mic"), CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC},
|
| + {std::string("mediastream_camera"),
|
| + CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA},
|
| + {std::string("protocol_handlers"),
|
| + CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS},
|
| + {std::string("automatic_downloads"),
|
| + CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS},
|
| + {std::string("midi_sysex"), CONTENT_SETTINGS_TYPE_MIDI_SYSEX},
|
| + };
|
| + for (size_t i = 0; i < sizeof(content_settings_values) /
|
| + sizeof(content_settings_values[0]);
|
| + ++i) {
|
| + if (name == content_settings_values[i].name) {
|
| + ShowDialogBubble(content_settings_values[i].content_type);
|
| + return;
|
| + }
|
| + }
|
| + EXPECT_TRUE(false);
|
| + }
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_cookies) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_images) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_javascript) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_plugins) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_popups) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_geolocation) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_ppapi_broker) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_mixed_script) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_mediastream_mic) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_mediastream_camera) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_protocol_handlers) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_automatic_downloads) {
|
| + RunDialog();
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
|
| + InvokeDialog_midi_sysex) {
|
| + RunDialog();
|
| +}
|
|
|