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

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

Issue 2675213002: [Mac] DialogBrowserTest implementation to invoke Content settings bubble dialogs. (Closed)
Patch Set: Gets it working on Mac Created 3 years, 10 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..4f7890a1f12106d9ebf074cfe98a10c5ca8e846c
--- /dev/null
+++ b/chrome/browser/ui/views/location_bar/content_setting_bubble_dialog_browsertest.cc
@@ -0,0 +1,187 @@
+// 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/browser_window.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/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"
+
+namespace {
+
+int IndexForContentType(ContentSettingsType content_type) {
+ // See ContentSettingImageModel::GenerateContentSettingImageModels().
+ constexpr ContentSettingsType icon_order[] = {
+ CONTENT_SETTINGS_TYPE_COOKIES,
+ CONTENT_SETTINGS_TYPE_IMAGES,
+ CONTENT_SETTINGS_TYPE_JAVASCRIPT,
+ CONTENT_SETTINGS_TYPE_PPAPI_BROKER,
+ CONTENT_SETTINGS_TYPE_PLUGINS,
+ CONTENT_SETTINGS_TYPE_POPUPS,
+ CONTENT_SETTINGS_TYPE_GEOLOCATION,
+ CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
+ CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS,
+ CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, // Media. Shared with Camera.
+ CONTENT_SETTINGS_TYPE_DEFAULT, // Deceptive content (no content type).
+ CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
+ CONTENT_SETTINGS_TYPE_MIDI_SYSEX};
+ if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)
+ content_type = CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC;
+
+ for (size_t index = 0; index < arraysize(icon_order); ++index) {
+ if (content_type == icon_order[index])
+ return index;
+ }
+
+ return -1;
+}
+
+} // namespace
+
+class ContentSettingBubbleDialogTest : public DialogBrowserTest {
+ public:
+ ContentSettingBubbleDialogTest() {}
+
+ void ShowDialogBubble(ContentSettingsType content_type);
+ void ShowDialog(const std::string& name) override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleDialogTest);
+};
+
+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);
+ }
+ browser()->window()->UpdateToolbar(web_contents);
+ LocationBarTesting* location_bar_testing =
+ browser()->window()->GetLocationBar()->GetLocationBarForTesting();
+ EXPECT_TRUE(location_bar_testing->TestContentSettingImagePressed(
+ IndexForContentType(content_type)));
+}
+
+void ContentSettingBubbleDialogTest::ShowDialog(const std::string& name) {
+ const struct {
+ 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 (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();
+}

Powered by Google App Engine
This is Rietveld 408576698