Cleanup: Remove SupervisedUserService::Delegate::IsChildAccount
[chromium-blink-merge.git] / android_webview / native / permission / media_access_permission_request_unittest.cc
blob32a190665ef978b1f7c9e960c0b7abf77598286a
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
3 // found in the LICENSE file.
5 #include "android_webview/native/permission/media_access_permission_request.h"
6 #include "base/bind.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace android_webview {
11 class TestMediaAccessPermissionRequest : public MediaAccessPermissionRequest {
12 public:
13 TestMediaAccessPermissionRequest(
14 const content::MediaStreamRequest& request,
15 const content::MediaResponseCallback& callback,
16 const content::MediaStreamDevices& audio_devices,
17 const content::MediaStreamDevices& video_devices)
18 : MediaAccessPermissionRequest(request, callback) {
19 audio_test_devices_ = audio_devices;
20 video_test_devices_ = video_devices;
24 class MediaAccessPermissionRequestTest : public testing::Test {
25 protected:
26 virtual void SetUp() {
27 audio_device_id_ = "audio";
28 video_device_id_ = "video";
29 first_audio_device_id_ = "audio1";
30 first_video_device_id_ = "video1";
33 scoped_ptr<TestMediaAccessPermissionRequest> CreateRequest(
34 std::string audio_id,
35 std::string video_id) {
36 content::MediaStreamDevices audio_devices;
37 audio_devices.push_back(
38 content::MediaStreamDevice(content::MEDIA_DEVICE_AUDIO_CAPTURE,
39 first_audio_device_id_, "a2"));
40 audio_devices.push_back(
41 content::MediaStreamDevice(content::MEDIA_DEVICE_AUDIO_CAPTURE,
42 audio_device_id_, "a1"));
44 content::MediaStreamDevices video_devices;
45 video_devices.push_back(
46 content::MediaStreamDevice(content::MEDIA_DEVICE_VIDEO_CAPTURE,
47 first_video_device_id_, "v2"));
48 video_devices.push_back(
49 content::MediaStreamDevice(content::MEDIA_DEVICE_VIDEO_CAPTURE,
50 video_device_id_, "v1"));
52 GURL origin("https://www.google.com");
53 content::MediaStreamRequest request(
54 0, 0, 0, origin, false, content::MEDIA_GENERATE_STREAM, audio_id,
55 video_id, content::MEDIA_DEVICE_AUDIO_CAPTURE,
56 content::MEDIA_DEVICE_VIDEO_CAPTURE);
58 scoped_ptr<TestMediaAccessPermissionRequest> permission_request;
59 permission_request.reset(new TestMediaAccessPermissionRequest(
60 request,
61 base::Bind(&MediaAccessPermissionRequestTest::Callback,
62 base::Unretained(this)),
63 audio_devices, video_devices));
64 return permission_request.Pass();
67 std::string audio_device_id_;
68 std::string video_device_id_;
69 std::string first_audio_device_id_;
70 std::string first_video_device_id_;
71 content::MediaStreamDevices devices_;
72 content::MediaStreamRequestResult result_;
73 private:
74 void Callback(
75 const content::MediaStreamDevices& devices,
76 content::MediaStreamRequestResult result,
77 scoped_ptr<content::MediaStreamUI> ui) {
78 devices_ = devices;
79 result_ = result;
83 TEST_F(MediaAccessPermissionRequestTest, TestGrantPermissionRequest) {
84 scoped_ptr<TestMediaAccessPermissionRequest> request =
85 CreateRequest(audio_device_id_, video_device_id_);
86 request->NotifyRequestResult(true);
88 EXPECT_EQ(2u, devices_.size());
89 EXPECT_EQ(content::MEDIA_DEVICE_OK, result_);
91 bool audio_exist = false;
92 bool video_exist = false;
93 for (content::MediaStreamDevices::iterator i = devices_.begin();
94 i != devices_.end(); ++i) {
95 if (i->type == content::MEDIA_DEVICE_AUDIO_CAPTURE &&
96 i->id == audio_device_id_) {
97 audio_exist = true;
98 } else if (i->type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
99 i->id == video_device_id_) {
100 video_exist = true;
103 EXPECT_TRUE(audio_exist);
104 EXPECT_TRUE(video_exist);
107 TEST_F(MediaAccessPermissionRequestTest, TestGrantPermissionRequestWithoutID) {
108 scoped_ptr<TestMediaAccessPermissionRequest> request =
109 CreateRequest(std::string(), std::string());
110 request->NotifyRequestResult(true);
112 EXPECT_EQ(2u, devices_.size());
113 EXPECT_EQ(content::MEDIA_DEVICE_OK, result_);
115 bool audio_exist = false;
116 bool video_exist = false;
117 for (content::MediaStreamDevices::iterator i = devices_.begin();
118 i != devices_.end(); ++i) {
119 if (i->type == content::MEDIA_DEVICE_AUDIO_CAPTURE &&
120 i->id == first_audio_device_id_) {
121 audio_exist = true;
122 } else if (i->type == content::MEDIA_DEVICE_VIDEO_CAPTURE &&
123 i->id == first_video_device_id_) {
124 video_exist = true;
127 EXPECT_TRUE(audio_exist);
128 EXPECT_TRUE(video_exist);
131 TEST_F(MediaAccessPermissionRequestTest, TestDenyPermissionRequest) {
132 scoped_ptr<TestMediaAccessPermissionRequest> request =
133 CreateRequest(std::string(), std::string());
134 request->NotifyRequestResult(false);
135 EXPECT_TRUE(devices_.empty());
136 EXPECT_EQ(content::MEDIA_DEVICE_PERMISSION_DENIED, result_);
139 } // namespace android_webview