| 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 "android_webview/native/permission/media_access_permission_request.h" | 5 #include "android_webview/native/permission/media_access_permission_request.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace android_webview { | 9 namespace android_webview { |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 class MediaAccessPermissionRequestTest : public testing::Test { | 24 class MediaAccessPermissionRequestTest : public testing::Test { |
| 25 protected: | 25 protected: |
| 26 void SetUp() override { | 26 void SetUp() override { |
| 27 audio_device_id_ = "audio"; | 27 audio_device_id_ = "audio"; |
| 28 video_device_id_ = "video"; | 28 video_device_id_ = "video"; |
| 29 first_audio_device_id_ = "audio1"; | 29 first_audio_device_id_ = "audio1"; |
| 30 first_video_device_id_ = "video1"; | 30 first_video_device_id_ = "video1"; |
| 31 } | 31 } |
| 32 | 32 |
| 33 scoped_ptr<TestMediaAccessPermissionRequest> CreateRequest( | 33 std::unique_ptr<TestMediaAccessPermissionRequest> CreateRequest( |
| 34 std::string audio_id, | 34 std::string audio_id, |
| 35 std::string video_id) { | 35 std::string video_id) { |
| 36 content::MediaStreamDevices audio_devices; | 36 content::MediaStreamDevices audio_devices; |
| 37 audio_devices.push_back( | 37 audio_devices.push_back( |
| 38 content::MediaStreamDevice(content::MEDIA_DEVICE_AUDIO_CAPTURE, | 38 content::MediaStreamDevice(content::MEDIA_DEVICE_AUDIO_CAPTURE, |
| 39 first_audio_device_id_, "a2")); | 39 first_audio_device_id_, "a2")); |
| 40 audio_devices.push_back( | 40 audio_devices.push_back( |
| 41 content::MediaStreamDevice(content::MEDIA_DEVICE_AUDIO_CAPTURE, | 41 content::MediaStreamDevice(content::MEDIA_DEVICE_AUDIO_CAPTURE, |
| 42 audio_device_id_, "a1")); | 42 audio_device_id_, "a1")); |
| 43 | 43 |
| 44 content::MediaStreamDevices video_devices; | 44 content::MediaStreamDevices video_devices; |
| 45 video_devices.push_back( | 45 video_devices.push_back( |
| 46 content::MediaStreamDevice(content::MEDIA_DEVICE_VIDEO_CAPTURE, | 46 content::MediaStreamDevice(content::MEDIA_DEVICE_VIDEO_CAPTURE, |
| 47 first_video_device_id_, "v2")); | 47 first_video_device_id_, "v2")); |
| 48 video_devices.push_back( | 48 video_devices.push_back( |
| 49 content::MediaStreamDevice(content::MEDIA_DEVICE_VIDEO_CAPTURE, | 49 content::MediaStreamDevice(content::MEDIA_DEVICE_VIDEO_CAPTURE, |
| 50 video_device_id_, "v1")); | 50 video_device_id_, "v1")); |
| 51 | 51 |
| 52 GURL origin("https://www.google.com"); | 52 GURL origin("https://www.google.com"); |
| 53 content::MediaStreamRequest request( | 53 content::MediaStreamRequest request( |
| 54 0, 0, 0, origin, false, content::MEDIA_GENERATE_STREAM, audio_id, | 54 0, 0, 0, origin, false, content::MEDIA_GENERATE_STREAM, audio_id, |
| 55 video_id, content::MEDIA_DEVICE_AUDIO_CAPTURE, | 55 video_id, content::MEDIA_DEVICE_AUDIO_CAPTURE, |
| 56 content::MEDIA_DEVICE_VIDEO_CAPTURE); | 56 content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 57 | 57 |
| 58 scoped_ptr<TestMediaAccessPermissionRequest> permission_request; | 58 std::unique_ptr<TestMediaAccessPermissionRequest> permission_request; |
| 59 permission_request.reset(new TestMediaAccessPermissionRequest( | 59 permission_request.reset(new TestMediaAccessPermissionRequest( |
| 60 request, | 60 request, |
| 61 base::Bind(&MediaAccessPermissionRequestTest::Callback, | 61 base::Bind(&MediaAccessPermissionRequestTest::Callback, |
| 62 base::Unretained(this)), | 62 base::Unretained(this)), |
| 63 audio_devices, video_devices)); | 63 audio_devices, video_devices)); |
| 64 return permission_request; | 64 return permission_request; |
| 65 } | 65 } |
| 66 | 66 |
| 67 std::string audio_device_id_; | 67 std::string audio_device_id_; |
| 68 std::string video_device_id_; | 68 std::string video_device_id_; |
| 69 std::string first_audio_device_id_; | 69 std::string first_audio_device_id_; |
| 70 std::string first_video_device_id_; | 70 std::string first_video_device_id_; |
| 71 content::MediaStreamDevices devices_; | 71 content::MediaStreamDevices devices_; |
| 72 content::MediaStreamRequestResult result_; | 72 content::MediaStreamRequestResult result_; |
| 73 private: | 73 private: |
| 74 void Callback( | 74 void Callback(const content::MediaStreamDevices& devices, |
| 75 const content::MediaStreamDevices& devices, | 75 content::MediaStreamRequestResult result, |
| 76 content::MediaStreamRequestResult result, | 76 std::unique_ptr<content::MediaStreamUI> ui) { |
| 77 scoped_ptr<content::MediaStreamUI> ui) { | |
| 78 devices_ = devices; | 77 devices_ = devices; |
| 79 result_ = result; | 78 result_ = result; |
| 80 } | 79 } |
| 81 }; | 80 }; |
| 82 | 81 |
| 83 TEST_F(MediaAccessPermissionRequestTest, TestGrantPermissionRequest) { | 82 TEST_F(MediaAccessPermissionRequestTest, TestGrantPermissionRequest) { |
| 84 scoped_ptr<TestMediaAccessPermissionRequest> request = | 83 std::unique_ptr<TestMediaAccessPermissionRequest> request = |
| 85 CreateRequest(audio_device_id_, video_device_id_); | 84 CreateRequest(audio_device_id_, video_device_id_); |
| 86 request->NotifyRequestResult(true); | 85 request->NotifyRequestResult(true); |
| 87 | 86 |
| 88 EXPECT_EQ(2u, devices_.size()); | 87 EXPECT_EQ(2u, devices_.size()); |
| 89 EXPECT_EQ(content::MEDIA_DEVICE_OK, result_); | 88 EXPECT_EQ(content::MEDIA_DEVICE_OK, result_); |
| 90 | 89 |
| 91 bool audio_exist = false; | 90 bool audio_exist = false; |
| 92 bool video_exist = false; | 91 bool video_exist = false; |
| 93 for (content::MediaStreamDevices::iterator i = devices_.begin(); | 92 for (content::MediaStreamDevices::iterator i = devices_.begin(); |
| 94 i != devices_.end(); ++i) { | 93 i != devices_.end(); ++i) { |
| 95 if (i->type == content::MEDIA_DEVICE_AUDIO_CAPTURE && | 94 if (i->type == content::MEDIA_DEVICE_AUDIO_CAPTURE && |
| 96 i->id == audio_device_id_) { | 95 i->id == audio_device_id_) { |
| 97 audio_exist = true; | 96 audio_exist = true; |
| 98 } else if (i->type == content::MEDIA_DEVICE_VIDEO_CAPTURE && | 97 } else if (i->type == content::MEDIA_DEVICE_VIDEO_CAPTURE && |
| 99 i->id == video_device_id_) { | 98 i->id == video_device_id_) { |
| 100 video_exist = true; | 99 video_exist = true; |
| 101 } | 100 } |
| 102 } | 101 } |
| 103 EXPECT_TRUE(audio_exist); | 102 EXPECT_TRUE(audio_exist); |
| 104 EXPECT_TRUE(video_exist); | 103 EXPECT_TRUE(video_exist); |
| 105 } | 104 } |
| 106 | 105 |
| 107 TEST_F(MediaAccessPermissionRequestTest, TestGrantPermissionRequestWithoutID) { | 106 TEST_F(MediaAccessPermissionRequestTest, TestGrantPermissionRequestWithoutID) { |
| 108 scoped_ptr<TestMediaAccessPermissionRequest> request = | 107 std::unique_ptr<TestMediaAccessPermissionRequest> request = |
| 109 CreateRequest(std::string(), std::string()); | 108 CreateRequest(std::string(), std::string()); |
| 110 request->NotifyRequestResult(true); | 109 request->NotifyRequestResult(true); |
| 111 | 110 |
| 112 EXPECT_EQ(2u, devices_.size()); | 111 EXPECT_EQ(2u, devices_.size()); |
| 113 EXPECT_EQ(content::MEDIA_DEVICE_OK, result_); | 112 EXPECT_EQ(content::MEDIA_DEVICE_OK, result_); |
| 114 | 113 |
| 115 bool audio_exist = false; | 114 bool audio_exist = false; |
| 116 bool video_exist = false; | 115 bool video_exist = false; |
| 117 for (content::MediaStreamDevices::iterator i = devices_.begin(); | 116 for (content::MediaStreamDevices::iterator i = devices_.begin(); |
| 118 i != devices_.end(); ++i) { | 117 i != devices_.end(); ++i) { |
| 119 if (i->type == content::MEDIA_DEVICE_AUDIO_CAPTURE && | 118 if (i->type == content::MEDIA_DEVICE_AUDIO_CAPTURE && |
| 120 i->id == first_audio_device_id_) { | 119 i->id == first_audio_device_id_) { |
| 121 audio_exist = true; | 120 audio_exist = true; |
| 122 } else if (i->type == content::MEDIA_DEVICE_VIDEO_CAPTURE && | 121 } else if (i->type == content::MEDIA_DEVICE_VIDEO_CAPTURE && |
| 123 i->id == first_video_device_id_) { | 122 i->id == first_video_device_id_) { |
| 124 video_exist = true; | 123 video_exist = true; |
| 125 } | 124 } |
| 126 } | 125 } |
| 127 EXPECT_TRUE(audio_exist); | 126 EXPECT_TRUE(audio_exist); |
| 128 EXPECT_TRUE(video_exist); | 127 EXPECT_TRUE(video_exist); |
| 129 } | 128 } |
| 130 | 129 |
| 131 TEST_F(MediaAccessPermissionRequestTest, TestDenyPermissionRequest) { | 130 TEST_F(MediaAccessPermissionRequestTest, TestDenyPermissionRequest) { |
| 132 scoped_ptr<TestMediaAccessPermissionRequest> request = | 131 std::unique_ptr<TestMediaAccessPermissionRequest> request = |
| 133 CreateRequest(std::string(), std::string()); | 132 CreateRequest(std::string(), std::string()); |
| 134 request->NotifyRequestResult(false); | 133 request->NotifyRequestResult(false); |
| 135 EXPECT_TRUE(devices_.empty()); | 134 EXPECT_TRUE(devices_.empty()); |
| 136 EXPECT_EQ(content::MEDIA_DEVICE_PERMISSION_DENIED, result_); | 135 EXPECT_EQ(content::MEDIA_DEVICE_PERMISSION_DENIED, result_); |
| 137 } | 136 } |
| 138 | 137 |
| 139 } // namespace android_webview | 138 } // namespace android_webview |
| OLD | NEW |