Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4110)

Unified Diff: chrome/browser/ui/views/location_bar/content_setting_bubble_dialog_browsertest.cc

Issue 2668833003: DialogBrowserTest implementation to invoke Content settings bubble dialogs. (Closed)
Patch Set: Fixed Cocoa build Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..913ad14d1c4bfabe5b7bfdaa3384fbd143f1bf06
--- /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.
tapted 2017/02/03 00:35:40 It's unclear what file this is testing (which is u
kylix_rd 2017/02/03 18:55:04 You make a good point, however I think it is testi
tapted 2017/02/03 23:07:02 Hm - I think you are right that this particular lo
+// 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"
tapted 2017/02/03 00:35:40 Then move this include up to the top and put a bla
+#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"
tapted 2017/02/03 00:35:40 hum - this is not cross-platform. So I think we ca
+#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->GetContentType() == content_type)
+ return image_model;
+ }
+ return nullptr;
+ }
+
+ void ShowDialogBubble(ContentSettingsType content_type) {
tapted 2017/02/03 00:35:40 This is too big for an inline method - even in a t
+ 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:
tapted 2017/02/03 00:35:39 nit: indent is off
kylix_rd 2017/02/03 18:55:04 It's odd that 'git cl format' didn't catch this on
+ content_settings->OnGeolocationPermissionSet(
+ GURL::EmptyGURL(), false);
+ break;
+ default:
+ content_settings->OnContentBlocked(content_type);
tapted 2017/02/03 00:35:40 comment about this?
+ }
+ BrowserView* browser_view =
+ BrowserView::GetBrowserViewForBrowser(browser());
+ LocationBarView* location_bar_view = browser_view->GetLocationBarView();
tapted 2017/02/03 00:35:40 huh, actually we have a LocationBarView* here too
kylix_rd 2017/02/03 18:55:03 Yes, I should have commented this code. This bloc
tapted 2017/02/03 23:07:02 hehe - I agree with you on this point - I don't th
+ LocationBar* location_bar = location_bar_view;
+ LocationBarTesting* location_bar_testing =
+ location_bar->GetLocationBarForTesting();
+ location_bar_view->Update(web_contents);
tapted 2017/02/03 00:35:39 this needs more comments/commentary. E.g. is this
+ 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(
tapted 2017/02/03 00:35:40 Why's this necessary? We typically can't rely on
kylix_rd 2017/02/03 18:55:04 This actually invokes the dialog... In, essentiall
+ 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 {
tapted 2017/02/03 00:35:39 the name `_content_settings_values` can just be om
kylix_rd 2017/02/03 18:55:04 My "C" roots are showing ;)
+ std::string name;
+ ContentSettingsType content_type;
+ } content_settings_values[] = {
+ {std::string("cookies"), CONTENT_SETTINGS_TYPE_COOKIES},
tapted 2017/02/03 00:35:40 string has an implicit constructor, so the `std::s
kylix_rd 2017/02/03 18:55:04 I thought so as well, C++11 complains without the
tapted 2017/02/03 23:07:02 och boo ;). I'd suggest making the |name| member a
+ {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) /
tapted 2017/02/03 00:35:39 there is arraysize in base/macros.h for this, but
kylix_rd 2017/02/03 18:55:04 Right... Thanks for the reminder.
+ sizeof(content_settings_values[0]);
+ ++i) {
+ if (name == content_settings_values[i].name) {
+ ShowDialogBubble(content_settings_values[i].content_type);
+ return;
+ }
+ }
+ EXPECT_TRUE(false);
tapted 2017/02/03 00:35:40 NOTREACHED()
kylix_rd 2017/02/03 18:55:04 Won't NOTREACHED() terminated the whole test proce
Peter Kasting 2017/02/03 22:20:41 Right, don't use NOTREACHED() in tests for the sam
+ }
+};
+
+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();
+}

Powered by Google App Engine
This is Rietveld 408576698