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" |
|
msw
2015/08/06 18:23:20
nit: remove if not needed.
msramek
2015/08/06 18:32:11
It's still used by ContentSettingBubbleModelMixedS
| |
| 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[] = |
| 22 FILE_PATH_LITERAL("chrome/test/data"); | 23 FILE_PATH_LITERAL("chrome/test/data"); |
| 23 | 24 |
| 24 class ContentSettingBubbleModelMixedScriptTest : public InProcessBrowserTest { | 25 class ContentSettingBubbleModelMixedScriptTest : public InProcessBrowserTest { |
| 25 protected: | 26 protected: |
| 26 void SetUpInProcessBrowserTestFixture() override { | 27 void SetUpInProcessBrowserTestFixture() override { |
| 27 https_server_.reset( | 28 https_server_.reset( |
| (...skipping 63 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 // Create a bubble with the given camera and microphone access state. | |
| 108 TabSpecificContentSettings::FromWebContents(GetFirstTab())-> | |
| 109 OnMediaStreamPermissionSet( | |
| 110 GetFirstTab()->GetLastCommittedURL(), | |
| 111 state, std::string(), std::string(), std::string(), std::string()); | |
| 112 scoped_ptr<ContentSettingBubbleModel> bubble( | |
| 113 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | |
| 114 browser()->content_setting_bubble_model_delegate(), | |
| 115 GetFirstTab(), | |
| 116 browser()->profile(), | |
| 117 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); | |
| 118 | |
| 119 // Click the management link. | |
|
msw
2015/08/06 18:23:20
nit "Click the management link, which opens in a n
msramek
2015/08/06 18:32:11
Done.
| |
| 120 bubble->OnManageLinkClicked(); | |
| 121 } | |
| 122 | |
| 123 content::WebContents* GetActiveTab() { | |
| 124 // First, we need to find the active browser window. It should be at | |
| 125 // the same desktop as the browser in which we invoked the bubble. | |
| 126 Browser* active_browser = chrome::FindLastActiveWithHostDesktopType( | |
| 127 browser()->host_desktop_type()); | |
| 128 return active_browser->tab_strip_model()->GetActiveWebContents(); | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 content::WebContents* GetFirstTab() { | |
| 133 return browser()->tab_strip_model()->GetWebContentsAt(0); | |
| 134 } | |
| 135 }; | |
| 136 | |
| 137 // Tests that clicking on the management link in the media bubble opens | |
| 138 // the correct section of the settings UI. | |
| 139 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleModelMediaStreamTest, ManageLink) { | |
| 140 // For each of the three options, we click the management link and check if | |
| 141 // the active tab starts loading the correct internal url. We don't need to | |
| 142 // wait until the navigation finishes. | |
| 143 | |
| 144 // The microphone bubble links to microphone exceptions. | |
| 145 ManageMediaStreamSettings(TabSpecificContentSettings::MICROPHONE_ACCESSED); | |
| 146 EXPECT_EQ(GURL("chrome://settings/contentExceptions#media-stream-mic"), | |
| 147 GetActiveTab()->GetVisibleURL()); | |
| 148 | |
| 149 // The camera bubble links to camera exceptions. | |
| 150 ManageMediaStreamSettings(TabSpecificContentSettings::CAMERA_ACCESSED); | |
| 151 EXPECT_EQ(GURL("chrome://settings/contentExceptions#media-stream-camera"), | |
| 152 GetActiveTab()->GetVisibleURL()); | |
| 153 | |
| 154 // The bubble for both media devices links to the the first section of the | |
| 155 // default media content settings, which is the microphone section. | |
| 156 ManageMediaStreamSettings(TabSpecificContentSettings::MICROPHONE_ACCESSED | | |
| 157 TabSpecificContentSettings::CAMERA_ACCESSED); | |
| 158 EXPECT_EQ(GURL("chrome://settings/content#media-stream-mic"), | |
| 159 GetActiveTab()->GetVisibleURL()); | |
| 160 } | |
| OLD | NEW |