| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" | 11 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 13 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "components/content_settings/core/common/content_settings_types.h" | 17 #include "components/content_settings/core/common/content_settings_types.h" |
| 17 #include "content/public/test/test_navigation_observer.h" | 18 #include "content/public/test/test_navigation_observer.h" |
| 18 #include "net/test/spawned_test_server/spawned_test_server.h" | 19 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 const base::FilePath::CharType kDocRoot[] = | 22 const base::FilePath::CharType kDocRoot[] = |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 92 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); |
| 92 model->OnCustomLinkClicked(); | 93 model->OnCustomLinkClicked(); |
| 93 | 94 |
| 94 content::TestNavigationObserver observer( | 95 content::TestNavigationObserver observer( |
| 95 browser()->tab_strip_model()->GetActiveWebContents()); | 96 browser()->tab_strip_model()->GetActiveWebContents()); |
| 96 observer.Wait(); | 97 observer.Wait(); |
| 97 | 98 |
| 98 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked( | 99 EXPECT_FALSE(GetActiveTabSpecificContentSettings()->IsContentBlocked( |
| 99 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); | 100 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)); |
| 100 } | 101 } |
| 102 |
| 103 class ContentSettingBubbleModelMediaStreamTest : public InProcessBrowserTest { |
| 104 public: |
| 105 void ManageMediaStreamSettings( |
| 106 TabSpecificContentSettings::MicrophoneCameraState state) { |
| 107 // Open a tab for which we will invoke the media bubble. |
| 108 GURL url(ui_test_utils::GetTestUrl( |
| 109 base::FilePath().AppendASCII("content_setting_bubble"), |
| 110 base::FilePath().AppendASCII("mixed_script.html"))); |
| 111 ui_test_utils::NavigateToURL(browser(), url); |
| 112 content::WebContents* original_tab = GetActiveTab(); |
| 113 |
| 114 // Create a bubble with the given camera and microphone access state. |
| 115 TabSpecificContentSettings::FromWebContents(original_tab)-> |
| 116 OnMediaStreamPermissionSet( |
| 117 original_tab->GetLastCommittedURL(), |
| 118 state, std::string(), std::string(), std::string(), std::string()); |
| 119 scoped_ptr<ContentSettingBubbleModel> bubble( |
| 120 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 121 browser()->content_setting_bubble_model_delegate(), |
| 122 original_tab, |
| 123 browser()->profile(), |
| 124 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); |
| 125 |
| 126 // Click the management link, which opens in a new tab or window. |
| 127 // Wait until it loads. |
| 128 bubble->OnManageLinkClicked(); |
| 129 ASSERT_NE(GetActiveTab(), original_tab); |
| 130 content::TestNavigationObserver observer(GetActiveTab()); |
| 131 observer.Wait(); |
| 132 } |
| 133 |
| 134 content::WebContents* GetActiveTab() { |
| 135 // First, we need to find the active browser window. It should be at |
| 136 // the same desktop as the browser in which we invoked the bubble. |
| 137 Browser* active_browser = chrome::FindLastActiveWithHostDesktopType( |
| 138 browser()->host_desktop_type()); |
| 139 return active_browser->tab_strip_model()->GetActiveWebContents(); |
| 140 } |
| 141 }; |
| 142 |
| 143 // Tests that clicking on the management link in the media bubble opens |
| 144 // the correct section of the settings UI. |
| 145 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMediaStreamTest, ManageLink) { |
| 146 // For each of the three options, we click the management link and check if |
| 147 // the active tab loads the correct internal url. |
| 148 |
| 149 // The microphone bubble links to microphone exceptions. |
| 150 ManageMediaStreamSettings(TabSpecificContentSettings::MICROPHONE_ACCESSED); |
| 151 EXPECT_EQ(GURL("chrome://settings/contentExceptions#media-stream-mic"), |
| 152 GetActiveTab()->GetLastCommittedURL()); |
| 153 |
| 154 // The camera bubble links to camera exceptions. |
| 155 ManageMediaStreamSettings(TabSpecificContentSettings::CAMERA_ACCESSED); |
| 156 EXPECT_EQ(GURL("chrome://settings/contentExceptions#media-stream-camera"), |
| 157 GetActiveTab()->GetLastCommittedURL()); |
| 158 |
| 159 // The bubble for both media devices links to the the first section of the |
| 160 // default media content settings, which is the microphone section. |
| 161 ManageMediaStreamSettings(TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 162 TabSpecificContentSettings::CAMERA_ACCESSED); |
| 163 EXPECT_EQ(GURL("chrome://settings/content#media-stream-mic"), |
| 164 GetActiveTab()->GetLastCommittedURL()); |
| 165 } |
| OLD | NEW |