| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/permissions/permission_request_manager.h" | 5 #include "chrome/browser/permissions/permission_request_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 10 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 11 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re
quest.h" | 11 #include "chrome/browser/custom_handlers/register_protocol_handler_permission_re
quest.h" |
| 12 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 12 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
| 13 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" | 13 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
| 14 #include "chrome/browser/permissions/permission_context_base.h" | 14 #include "chrome/browser/permissions/permission_context_base.h" |
| 15 #include "chrome/browser/permissions/permission_request_impl.h" | 15 #include "chrome/browser/permissions/permission_request_impl.h" |
| 16 #include "chrome/browser/permissions/permission_util.h" | 16 #include "chrome/browser/permissions/permission_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" | 19 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/browser/ui/test/test_browser_dialog.h" | 21 #include "chrome/browser/ui/test/test_browser_dialog.h" |
| 22 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "components/content_settings/core/common/content_settings_types.h" | 24 #include "components/content_settings/core/common/content_settings_types.h" |
| 25 #include "components/variations/variations_associated_data.h" | 25 #include "components/variations/variations_associated_data.h" |
| 26 #include "content/public/browser/render_frame_host.h" |
| 27 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 27 #include "content/public/test/test_utils.h" | 29 #include "content/public/test/test_utils.h" |
| 28 #include "net/test/embedded_test_server/embedded_test_server.h" | 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 29 | 31 |
| 30 namespace test { | 32 namespace test { |
| 31 class MediaStreamDevicesControllerTestApi | 33 class MediaStreamDevicesControllerTestApi |
| 32 : public internal::PermissionPromptDelegate { | 34 : public internal::PermissionPromptDelegate { |
| 33 public: | 35 public: |
| 34 static void AddRequestToManager( | 36 static void AddRequestToManager( |
| 35 PermissionRequestManager* manager, | 37 PermissionRequestManager* manager, |
| 36 content::WebContents* web_contents, | 38 content::WebContents* web_contents, |
| 37 const content::MediaStreamRequest& request, | 39 const content::MediaStreamRequest& request, |
| 38 const content::MediaResponseCallback& callback) { | 40 const content::MediaResponseCallback& callback) { |
| 39 MediaStreamDevicesControllerTestApi delegate(manager); | 41 MediaStreamDevicesControllerTestApi delegate(manager); |
| 40 MediaStreamDevicesController::RequestPermissionsWithDelegate( | 42 MediaStreamDevicesController::RequestPermissionsWithDelegate( |
| 41 web_contents, request, callback, &delegate); | 43 request, callback, &delegate); |
| 42 } | 44 } |
| 43 | 45 |
| 44 private: | 46 private: |
| 45 // MediaStreamDevicesController::PermissionPromptDelegate: | 47 // MediaStreamDevicesController::PermissionPromptDelegate: |
| 46 void ShowPrompt( | 48 void ShowPrompt( |
| 47 bool user_gesture, | 49 bool user_gesture, |
| 48 content::WebContents* web_contents, | 50 content::WebContents* web_contents, |
| 49 std::unique_ptr<MediaStreamDevicesController> controller) override { | 51 std::unique_ptr<MediaStreamDevicesController> controller) override { |
| 50 manager_->AddRequest(controller.release()); | 52 manager_->AddRequest(controller.release()); |
| 51 } | 53 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 class PermissionDialogTest | 119 class PermissionDialogTest |
| 118 : public SupportsTestDialog<PermissionRequestManagerBrowserTest> { | 120 : public SupportsTestDialog<PermissionRequestManagerBrowserTest> { |
| 119 public: | 121 public: |
| 120 PermissionDialogTest() {} | 122 PermissionDialogTest() {} |
| 121 | 123 |
| 122 // InProcessBrowserTest: | 124 // InProcessBrowserTest: |
| 123 void SetUpOnMainThread() override { | 125 void SetUpOnMainThread() override { |
| 124 // Skip super: It will install a mock permission UI factory, but for this | 126 // Skip super: It will install a mock permission UI factory, but for this |
| 125 // test we want to show "real" UI. | 127 // test we want to show "real" UI. |
| 126 InProcessBrowserTest::SetUpOnMainThread(); | 128 InProcessBrowserTest::SetUpOnMainThread(); |
| 129 ui_test_utils::NavigateToURL(browser(), GetUrl()); |
| 127 } | 130 } |
| 128 | 131 |
| 129 private: | 132 private: |
| 130 GURL GetUrl() { return GURL("https://example.com"); } | 133 GURL GetUrl() { return GURL("https://example.com"); } |
| 131 | 134 |
| 132 PermissionRequest* MakeRegisterProtocolHandlerRequest(); | 135 PermissionRequest* MakeRegisterProtocolHandlerRequest(); |
| 133 void AddMediaRequest(PermissionRequestManager* manager, | 136 void AddMediaRequest(PermissionRequestManager* manager, |
| 134 ContentSettingsType permission); | 137 ContentSettingsType permission); |
| 135 PermissionRequest* MakePermissionRequest(ContentSettingsType permission); | 138 PermissionRequest* MakePermissionRequest(ContentSettingsType permission); |
| 136 | 139 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 163 content::MediaStreamRequestType request_type = content::MEDIA_DEVICE_ACCESS; | 166 content::MediaStreamRequestType request_type = content::MEDIA_DEVICE_ACCESS; |
| 164 content::MediaStreamType audio_type = content::MEDIA_NO_SERVICE; | 167 content::MediaStreamType audio_type = content::MEDIA_NO_SERVICE; |
| 165 content::MediaStreamType video_type = content::MEDIA_NO_SERVICE; | 168 content::MediaStreamType video_type = content::MEDIA_NO_SERVICE; |
| 166 std::string audio_id = "audio_id"; | 169 std::string audio_id = "audio_id"; |
| 167 std::string video_id = "video_id"; | 170 std::string video_id = "video_id"; |
| 168 | 171 |
| 169 if (permission == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) | 172 if (permission == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) |
| 170 audio_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; | 173 audio_type = content::MEDIA_DEVICE_AUDIO_CAPTURE; |
| 171 else | 174 else |
| 172 video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; | 175 video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| 173 content::MediaStreamRequest request(0, 0, 0, GetUrl(), false, request_type, | 176 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
| 174 audio_id, video_id, audio_type, | 177 int render_frame_id = web_contents->GetMainFrame()->GetRoutingID(); |
| 175 video_type, false); | 178 content::MediaStreamRequest request(render_process_id, render_frame_id, 0, |
| 179 GetUrl(), false, request_type, audio_id, |
| 180 video_id, audio_type, video_type, false); |
| 176 | 181 |
| 177 // Add fake devices, otherwise the request will auto-block. | 182 // Add fake devices, otherwise the request will auto-block. |
| 178 MediaCaptureDevicesDispatcher::GetInstance()->SetTestAudioCaptureDevices( | 183 MediaCaptureDevicesDispatcher::GetInstance()->SetTestAudioCaptureDevices( |
| 179 content::MediaStreamDevices( | 184 content::MediaStreamDevices( |
| 180 1, content::MediaStreamDevice(content::MEDIA_DEVICE_AUDIO_CAPTURE, | 185 1, content::MediaStreamDevice(content::MEDIA_DEVICE_AUDIO_CAPTURE, |
| 181 audio_id, "Fake Audio"))); | 186 audio_id, "Fake Audio"))); |
| 182 MediaCaptureDevicesDispatcher::GetInstance()->SetTestVideoCaptureDevices( | 187 MediaCaptureDevicesDispatcher::GetInstance()->SetTestVideoCaptureDevices( |
| 183 content::MediaStreamDevices( | 188 content::MediaStreamDevices( |
| 184 1, content::MediaStreamDevice(content::MEDIA_DEVICE_VIDEO_CAPTURE, | 189 1, content::MediaStreamDevice(content::MEDIA_DEVICE_VIDEO_CAPTURE, |
| 185 video_id, "Fake Video"))); | 190 video_id, "Fake Video"))); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 #define MAYBE_InvokeDialog_protected_media InvokeDialog_protected_media | 496 #define MAYBE_InvokeDialog_protected_media InvokeDialog_protected_media |
| 492 #else | 497 #else |
| 493 #define MAYBE_InvokeDialog_protected_media DISABLED_InvokeDialog_protected_media | 498 #define MAYBE_InvokeDialog_protected_media DISABLED_InvokeDialog_protected_media |
| 494 #endif | 499 #endif |
| 495 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, | 500 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, |
| 496 MAYBE_InvokeDialog_protected_media) { | 501 MAYBE_InvokeDialog_protected_media) { |
| 497 RunDialog(); | 502 RunDialog(); |
| 498 } | 503 } |
| 499 | 504 |
| 500 } // anonymous namespace | 505 } // anonymous namespace |
| OLD | NEW |