Chromium Code Reviews| 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 ui_test_utils::NavigateToURL( | |
|
msw
2015/08/11 17:03:14
nit: follow the pattern of the other tests:
GURL u
msramek
2015/08/12 08:41:58
Well, I can separate the construction of the URL f
| |
| 109 browser(), | |
| 110 ui_test_utils::GetTestUrl( | |
| 111 base::FilePath().AppendASCII("content_setting_bubble"), | |
| 112 base::FilePath().AppendASCII("mixed_script.html"))); | |
| 113 content::WebContents* original_tab = GetActiveTab(); | |
| 114 | |
| 115 // Create a bubble with the given camera and microphone access state. | |
| 116 TabSpecificContentSettings::FromWebContents(original_tab)-> | |
| 117 OnMediaStreamPermissionSet( | |
| 118 original_tab->GetLastCommittedURL(), | |
| 119 state, std::string(), std::string(), std::string(), std::string()); | |
| 120 scoped_ptr<ContentSettingBubbleModel> bubble( | |
| 121 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | |
| 122 browser()->content_setting_bubble_model_delegate(), | |
| 123 original_tab, | |
| 124 browser()->profile(), | |
| 125 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); | |
| 126 | |
| 127 // Click the management link, which opens in a new tab or window. | |
| 128 // Wait until it loads. | |
| 129 bubble->OnManageLinkClicked(); | |
| 130 ASSERT_NE(GetActiveTab(), original_tab); | |
| 131 content::TestNavigationObserver observer(GetActiveTab()); | |
| 132 observer.Wait(); | |
| 133 } | |
| 134 | |
| 135 content::WebContents* GetActiveTab() { | |
| 136 // First, we need to find the active browser window. It should be at | |
| 137 // the same desktop as the browser in which we invoked the bubble. | |
| 138 Browser* active_browser = chrome::FindLastActiveWithHostDesktopType( | |
| 139 browser()->host_desktop_type()); | |
| 140 return active_browser->tab_strip_model()->GetActiveWebContents(); | |
| 141 } | |
| 142 }; | |
| 143 | |
| 144 // Tests that clicking on the management link in the media bubble opens | |
| 145 // the correct section of the settings UI. | |
| 146 // TODO(msramek): This test can fail if the settings UI opens in a separate | |
|
msw
2015/08/11 17:03:14
nit: put this in the CL description, not the code.
msramek
2015/08/12 08:41:58
Done.
| |
| 147 // window, but BrowserList does not recognize the window as active yet. | |
| 148 // Several rounds of testing on trybots suggest that this does not happen. | |
| 149 // If it in fact does happen, disable this test, restrict it to the same-window | |
| 150 // case, or fix it to wait for the new window to be focused. | |
| 151 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMediaStreamTest, ManageLink) { | |
| 152 // For each of the three options, we click the management link and check if | |
| 153 // the active tab loads the correct internal url. | |
| 154 | |
| 155 // The microphone bubble links to microphone exceptions. | |
| 156 ManageMediaStreamSettings(TabSpecificContentSettings::MICROPHONE_ACCESSED); | |
| 157 EXPECT_EQ(GURL("chrome://settings/contentExceptions#media-stream-mic"), | |
| 158 GetActiveTab()->GetLastCommittedURL()); | |
| 159 | |
| 160 // The camera bubble links to camera exceptions. | |
| 161 ManageMediaStreamSettings(TabSpecificContentSettings::CAMERA_ACCESSED); | |
| 162 EXPECT_EQ(GURL("chrome://settings/contentExceptions#media-stream-camera"), | |
| 163 GetActiveTab()->GetLastCommittedURL()); | |
| 164 | |
| 165 // The bubble for both media devices links to the the first section of the | |
| 166 // default media content settings, which is the microphone section. | |
| 167 ManageMediaStreamSettings(TabSpecificContentSettings::MICROPHONE_ACCESSED | | |
| 168 TabSpecificContentSettings::CAMERA_ACCESSED); | |
| 169 EXPECT_EQ(GURL("chrome://settings/content#media-stream-mic"), | |
| 170 GetActiveTab()->GetLastCommittedURL()); | |
| 171 } | |
| OLD | NEW |