Chromium Code Reviews| 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..0dec866355e88135472288f9da8d4fa33de5ea20 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/location_bar/content_setting_bubble_dialog_browsertest.cc |
| @@ -0,0 +1,185 @@ |
| +// 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" |
|
tapted
2017/02/03 23:07:02
We need to drop this include -- it isn't compiled
|
| +#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" |
|
tapted
2017/02/03 23:07:02
I think all these location_bar includes won't work
|
| +#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() {} |
| + |
| + void ShowDialogBubble(ContentSettingsType content_type); |
| + void ShowDialog(const std::string& name) override; |
| +}; |
|
Peter Kasting
2017/02/06 21:14:25
Nit: I think you still want DISALLOW_COPY_AND_ASSI
kylix_rd
2017/02/06 21:42:50
Done.
|
| + |
| +static ContentSettingImageModel* GetImageModel(ContentSettingsType content_type, |
| + LocationBarTesting* location_bar) { |
|
Peter Kasting
2017/02/06 21:14:25
Nit: All lines of args should be aligned (git cl f
|
| + for (int i = 0; i < location_bar->ContentSettingImageModelCount(); i++) { |
| + ContentSettingImageModel* image_model = |
| + location_bar->GetContentSettingImageModel(i); |
|
Peter Kasting
2017/02/06 21:14:24
Nit: Wrong indentation (should be 4)
You're passi
|
| + if (image_model->GetContentType() == content_type) |
| + return image_model; |
| + } |
| + return nullptr; |
| +} |
| + |
| +void ContentSettingBubbleDialogTest::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: |
| + // For all other content_types passed in, mark them as blocked. |
| + content_settings->OnContentBlocked(content_type); |
|
Peter Kasting
2017/02/06 21:14:25
Nit: It would make me more comfortable to have a b
kylix_rd
2017/02/06 21:42:50
Done.
|
| + } |
| + BrowserView* browser_view = |
| + BrowserView::GetBrowserViewForBrowser(browser()); |
|
Peter Kasting
2017/02/06 21:14:24
Nit: Nit: Could just inline into next line
|
| + LocationBarView* location_bar_view = browser_view->GetLocationBarView(); |
| + LocationBarTesting* location_bar_testing = |
| + location_bar_view->GetLocationBarForTesting(); |
|
Peter Kasting
2017/02/06 21:14:25
Nit: Declare temps as close to first use as possib
|
| + // Update the LocationBarView to ensure the image view icon is visible in |
| + // the Omnibar. |
|
Peter Kasting
2017/02/06 21:14:25
Nit: omnibox
|
| + location_bar_view->Update(web_contents); |
| + ContentSettingImageModel* image_model = |
| + GetImageModel(content_type, location_bar_testing); |
| + EXPECT_NE(image_model, nullptr); |
|
Peter Kasting
2017/02/06 21:14:24
Nit: ([un]expected, actual) for EQ/NE (several pla
|
| + ContentSettingImageView* image_view = |
| + location_bar_view->GetContentSettingImageViewFromImageModel( |
| + image_model); |
| + EXPECT_NE(image_view, nullptr); |
| + // This will invoke the bubble view and make it visible. |
| + image_view->OnActivate(ui::MouseEvent( |
| + ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), |
|
Peter Kasting
2017/02/06 21:14:24
Nit: Just gfx::Point()
|
| + 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(); |
|
Peter Kasting
2017/02/06 21:14:25
Nit: Could just inline into next line
|
| + EXPECT_TRUE(widget->IsVisible()); |
| +} |
| + |
| +void ContentSettingBubbleDialogTest::ShowDialog(const std::string& name) { |
| + const struct { |
| + std::string name; |
|
Peter Kasting
2017/02/06 21:14:24
Nit: Use const char*. This also allows you to dec
kylix_rd
2017/02/06 21:42:50
Done.
|
| + 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 (auto content_settings : content_settings_values) { |
| + if (name == content_settings.name) { |
| + ShowDialogBubble(content_settings.content_type); |
| + return; |
| + } |
| + } |
| + NOTREACHED(); |
| +} |
| + |
| +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(); |
| +} |