Chromium Code Reviews| Index: chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc |
| diff --git a/chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc b/chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc |
| index 263f7532fabd2c75835c2dd9f51d59c38ebd4a78..9955043f6d5f80b7fbecae5f4bcafc33c82d14c4 100644 |
| --- a/chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc |
| +++ b/chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc |
| @@ -14,6 +14,7 @@ |
| #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
| #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" |
| #include "chrome/browser/permissions/permission_context_base.h" |
| +#include "chrome/browser/permissions/permission_request_manager.h" |
| #include "chrome/browser/permissions/permission_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| @@ -27,25 +28,45 @@ |
| #include "content/public/test/mock_render_process_host.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -namespace { |
| - |
| -// Causes the controller to update the TabSpecificContentSettings associated |
| -// with the same WebContents with the current permissions. This should be the |
| -// last change made to the controller in the test. |
| -void NotifyTabSpecificContentSettings( |
| - MediaStreamDevicesController* controller) { |
| - // Note that calling Deny() would have the same effect of passing the current |
| - // permissions state to the TabSpecificContentSettings. Deny() and Accept() |
| - // differ in their effect on the controller itself, but that is not important |
| - // in the tests calling this. |
| - if (controller->IsAskingForAudio() || controller->IsAskingForVideo()) |
| - controller->PermissionGranted(); |
| -} |
| - |
| -} // namespace |
| - |
| class MediaStreamDevicesControllerTest : public WebRtcTestBase { |
| public: |
| + // TODO(raymes): When crbug.com/606138 is finished and the |
| + // PermissionRequestManager is used to show all prompts on Android/Desktop |
| + // we should remove PermissionPromptDelegate and just use |
| + // MockPermissionPromptFactory instead. The APIs are the same. |
| + class TestPermissionPromptDelegate |
| + : public MediaStreamDevicesController::PermissionPromptDelegate { |
| + public: |
| + void ShowPrompt( |
| + bool user_gesture, |
| + content::WebContents* web_contents, |
| + std::unique_ptr<MediaStreamDevicesController> controller) override { |
| + if (controller->IsAskingForAudio()) |
| + ++total_request_count_; |
| + if (controller->IsAskingForVideo()) |
| + ++total_request_count_; |
| + |
| + if (response_type_ == PermissionRequestManager::ACCEPT_ALL) |
| + controller->PermissionGranted(); |
| + else if (response_type_ == PermissionRequestManager::DENY_ALL) |
| + controller->PermissionDenied(); |
| + } |
| + |
| + void set_response_type( |
| + PermissionRequestManager::AutoResponseType response_type) { |
| + response_type_ = response_type; |
| + } |
| + |
| + int total_request_count() { return total_request_count_; } |
| + |
| + void ResetCounts() { total_request_count_ = 0; } |
| + |
| + private: |
| + PermissionRequestManager::AutoResponseType response_type_ = |
| + PermissionRequestManager::NONE; |
| + int total_request_count_ = 0; |
| + }; |
| + |
| MediaStreamDevicesControllerTest() |
| : example_audio_id_("fake_audio_dev"), |
| example_video_id_("fake_video_dev"), |
| @@ -76,30 +97,14 @@ class MediaStreamDevicesControllerTest : public WebRtcTestBase { |
| return media_stream_result_; |
| } |
| - std::unique_ptr<MediaStreamDevicesController> |
| - CreateMediaStreamDevicesController( |
| - content::WebContents* web_contents, |
| - const content::MediaStreamRequest& request, |
| - const content::MediaResponseCallback& callback) { |
| - return base::WrapUnique( |
| - new MediaStreamDevicesController(web_contents, request, callback)); |
| + void RequestPermissions(content::WebContents* web_contents, |
| + const content::MediaStreamRequest& request, |
| + const content::MediaResponseCallback& callback) { |
| + MediaStreamDevicesController::RequestPermissionsWithDelegate( |
| + web_contents, request, callback, &prompt_delegate_); |
| } |
| - bool IsAskingForAudio(const MediaStreamDevicesController* controller) { |
| - return controller->IsAskingForAudio(); |
| - } |
| - |
| - bool IsAskingForVideo(const MediaStreamDevicesController* controller) { |
| - return controller->IsAskingForVideo(); |
| - } |
| - |
| - void PermissionGranted(MediaStreamDevicesController* controller) { |
| - return controller->PermissionGranted(); |
| - } |
| - |
| - void PermissionDenied(MediaStreamDevicesController* controller) { |
| - return controller->PermissionDenied(); |
| - } |
| + TestPermissionPromptDelegate* prompt_delegate() { return &prompt_delegate_; } |
| // Sets the device policy-controlled |access| for |example_url_| to be for the |
| // selected |device_type|. |
| @@ -209,18 +214,21 @@ class MediaStreamDevicesControllerTest : public WebRtcTestBase { |
| content::MediaStreamDevices media_stream_devices_; |
| content::MediaStreamRequestResult media_stream_result_; |
| + |
| + TestPermissionPromptDelegate prompt_delegate_; |
| }; |
| // Request and allow microphone access. |
| IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowMic) { |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| @@ -242,12 +250,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowMic) { |
| IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowCam) { |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| @@ -269,12 +278,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowCam) { |
| IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockMic) { |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| @@ -297,12 +307,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockMic) { |
| IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndBlockCam) { |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| @@ -327,13 +338,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequest(example_audio_id(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| @@ -362,13 +373,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequest(example_audio_id(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| @@ -399,13 +410,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_DENIED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequest(example_audio_id(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| @@ -435,13 +446,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequest(example_audio_id(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| @@ -472,12 +483,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| InitWithUrl(GURL("https://www.example.com")); |
| // Request mic and deny. |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| - std::unique_ptr<MediaStreamDevicesController> mic_controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(mic_controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| @@ -489,12 +501,10 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| // Request cam and allow |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| - std::unique_ptr<MediaStreamDevicesController> cam_controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(cam_controller.get()); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| @@ -521,12 +531,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| InitWithUrl(GURL("https://www.example.com")); |
| // Request cam and allow |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| - std::unique_ptr<MediaStreamDevicesController> cam_controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(cam_controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_TRUE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); |
| EXPECT_FALSE(GetContentSettings()->IsContentBlocked( |
| @@ -553,12 +564,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| // Request mic and deny. |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_DENIED); |
| - std::unique_ptr<MediaStreamDevicesController> mic_controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - NotifyTabSpecificContentSettings(mic_controller.get()); |
| + // Ensure the prompt is accepted if necessary such that tab specific content |
| + // settings are updated. |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), std::string()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| EXPECT_FALSE(GetContentSettings()->IsContentAllowed( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC)); |
| EXPECT_TRUE(GetContentSettings()->IsContentBlocked( |
| @@ -601,8 +613,14 @@ struct ContentSettingsTestData { |
| // Whether the infobar should be displayed to request mic/cam for the given |
| // content settings inputs. |
| - bool ExpectMicInfobar() const { return mic == CONTENT_SETTING_ASK; } |
| - bool ExpectCamInfobar() const { return cam == CONTENT_SETTING_ASK; } |
| + int NumExpectedPrompts() const { |
| + int result = 0; |
| + if (mic == CONTENT_SETTING_ASK) |
| + ++result; |
| + if (cam == CONTENT_SETTING_ASK) |
| + ++result; |
| + return result; |
| + } |
| // Whether or not the mic/cam should be allowed after clicking accept/deny for |
| // the given inputs. |
| @@ -654,24 +672,29 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, ContentSettings) { |
| for (auto& test : tests) { |
| SetContentSettings(test.mic, test.cam); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequest(example_audio_id(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - // Check that the infobar is requesting the expected cam/mic values. |
| - ASSERT_EQ(test.ExpectMicInfobar(), IsAskingForAudio(controller.get())); |
| - ASSERT_EQ(test.ExpectCamInfobar(), IsAskingForVideo(controller.get())); |
| + prompt_delegate()->ResetCounts(); |
| // Accept or deny the infobar if it's showing. |
| - if (test.ExpectMicInfobar() || test.ExpectCamInfobar()) { |
| - if (test.accept_infobar) |
| - PermissionGranted(controller.get()); |
| - else |
| - PermissionDenied(controller.get()); |
| + if (test.NumExpectedPrompts() > 0) { |
| + if (test.accept_infobar) { |
| + prompt_delegate()->set_response_type( |
| + PermissionRequestManager::ACCEPT_ALL); |
| + } else { |
| + prompt_delegate()->set_response_type( |
| + PermissionRequestManager::DENY_ALL); |
| + } |
| + } else { |
| + prompt_delegate()->set_response_type(PermissionRequestManager::NONE); |
| } |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| + |
| + // Check that the infobar is requesting the expected cam/mic values. |
| + ASSERT_EQ(test.NumExpectedPrompts(), |
|
Timothy Loh
2017/02/28 00:39:20
This makes the test a bit less thorough, can we re
raymes
2017/03/01 02:08:01
That's true. I kept the checks back in by storing
|
| + prompt_delegate()->total_request_count()); |
| // Check the media stream result is expected and the devices returned are |
| // expected; |
| @@ -687,14 +710,12 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, ContentSettings) { |
| IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| WebUIRequestAndAllowCam) { |
| InitWithUrl(GURL("chrome://test-page")); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(std::string(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| - ASSERT_FALSE(IsAskingForAudio(controller.get())); |
| - ASSERT_FALSE(IsAskingForVideo(controller.get())); |
| + ASSERT_EQ(0, prompt_delegate()->total_request_count()); |
| ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); |
| ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); |
| @@ -705,30 +726,25 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| ExtensionRequestMicCam) { |
| InitWithUrl(GURL("chrome-extension://test-page")); |
| // Test that a prompt is required. |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequest(example_audio_id(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - ASSERT_TRUE(IsAskingForAudio(controller.get())); |
| - ASSERT_TRUE(IsAskingForVideo(controller.get())); |
| + prompt_delegate()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| + ASSERT_EQ(2, prompt_delegate()->total_request_count()); |
| // Accept the prompt. |
| - PermissionGranted(controller.get()); |
| ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); |
| ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); |
| ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); |
| // Check that re-requesting allows without prompting. |
| - std::unique_ptr<MediaStreamDevicesController> controller2( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequest(example_audio_id(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - ASSERT_FALSE(IsAskingForAudio(controller2.get())); |
| - ASSERT_FALSE(IsAskingForVideo(controller2.get())); |
| + prompt_delegate()->ResetCounts(); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| + ASSERT_EQ(0, prompt_delegate()->total_request_count()); |
| ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); |
| ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); |
| @@ -742,15 +758,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| InitWithUrl(GURL("http://www.example.com")); |
| SetContentSettings(CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequestWithType(example_audio_id(), std::string(), |
| - content::MEDIA_OPEN_DEVICE_PEPPER_ONLY), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - ASSERT_FALSE(IsAskingForAudio(controller.get())); |
| - ASSERT_FALSE(IsAskingForVideo(controller.get())); |
| + RequestPermissions( |
| + GetWebContents(), |
| + CreateRequestWithType(example_audio_id(), std::string(), |
| + content::MEDIA_OPEN_DEVICE_PEPPER_ONLY), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| + ASSERT_EQ(0, prompt_delegate()->total_request_count()); |
| } |
| // Request and block microphone and camera access with kill switch. |
| @@ -772,15 +786,12 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, |
| InitWithUrl(GURL("https://www.example.com")); |
| SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
| SetDevicePolicy(DEVICE_TYPE_VIDEO, ACCESS_ALLOWED); |
| - std::unique_ptr<MediaStreamDevicesController> controller( |
| - CreateMediaStreamDevicesController( |
| - GetWebContents(), |
| - CreateRequest(example_audio_id(), example_video_id()), |
| - base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| - base::Unretained(this)))); |
| - |
| - EXPECT_FALSE(IsAskingForAudio(controller.get())); |
| - EXPECT_FALSE(IsAskingForVideo(controller.get())); |
| + RequestPermissions( |
| + GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| + base::Unretained(this))); |
| + |
| + ASSERT_EQ(0, prompt_delegate()->total_request_count()); |
| ASSERT_EQ(content::MEDIA_DEVICE_KILL_SWITCH_ON, media_stream_result()); |
| ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); |