Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 2711883003: Change MediaStreamDevicesController tests to use RequestPermissions function (Closed)
Patch Set: Add test delegate Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "chrome/browser/extensions/updater/extension_updater.h" 56 #include "chrome/browser/extensions/updater/extension_updater.h"
57 #include "chrome/browser/infobars/infobar_service.h" 57 #include "chrome/browser/infobars/infobar_service.h"
58 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h" 58 #include "chrome/browser/interstitials/security_interstitial_page_test_utils.h"
59 #include "chrome/browser/io_thread.h" 59 #include "chrome/browser/io_thread.h"
60 #include "chrome/browser/media/router/media_router_feature.h" 60 #include "chrome/browser/media/router/media_router_feature.h"
61 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 61 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
62 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" 62 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h"
63 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h" 63 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h"
64 #include "chrome/browser/net/prediction_options.h" 64 #include "chrome/browser/net/prediction_options.h"
65 #include "chrome/browser/net/url_request_mock_util.h" 65 #include "chrome/browser/net/url_request_mock_util.h"
66 #include "chrome/browser/permissions/permission_request_manager.h"
66 #include "chrome/browser/policy/cloud/test_request_interceptor.h" 67 #include "chrome/browser/policy/cloud/test_request_interceptor.h"
67 #include "chrome/browser/policy/profile_policy_connector.h" 68 #include "chrome/browser/policy/profile_policy_connector.h"
68 #include "chrome/browser/policy/profile_policy_connector_factory.h" 69 #include "chrome/browser/policy/profile_policy_connector_factory.h"
69 #include "chrome/browser/prefs/session_startup_pref.h" 70 #include "chrome/browser/prefs/session_startup_pref.h"
70 #include "chrome/browser/profiles/profile.h" 71 #include "chrome/browser/profiles/profile.h"
71 #include "chrome/browser/search/instant_service.h" 72 #include "chrome/browser/search/instant_service.h"
72 #include "chrome/browser/search/instant_service_factory.h" 73 #include "chrome/browser/search/instant_service_factory.h"
73 #include "chrome/browser/search/search.h" 74 #include "chrome/browser/search/search.h"
74 #include "chrome/browser/search_engines/template_url_service_factory.h" 75 #include "chrome/browser/search_engines/template_url_service_factory.h"
75 #include "chrome/browser/ssl/ssl_blocking_page.h" 76 #include "chrome/browser/ssl/ssl_blocking_page.h"
(...skipping 3006 matching lines...) Expand 10 before | Expand all | Expand 10 after
3082 // ShowHomeButton has policy ID 35. 3083 // ShowHomeButton has policy ID 35.
3083 EXPECT_NE(std::string::npos, text.find("<br>35 ---")); 3084 EXPECT_NE(std::string::npos, text.find("<br>35 ---"));
3084 // BookmarkBarEnabled has policy ID 82. 3085 // BookmarkBarEnabled has policy ID 82.
3085 EXPECT_NE(std::string::npos, text.find("<br>82 ---")); 3086 EXPECT_NE(std::string::npos, text.find("<br>82 ---"));
3086 } 3087 }
3087 3088
3088 class MediaStreamDevicesControllerBrowserTest 3089 class MediaStreamDevicesControllerBrowserTest
3089 : public PolicyTest, 3090 : public PolicyTest,
3090 public testing::WithParamInterface<bool> { 3091 public testing::WithParamInterface<bool> {
3091 public: 3092 public:
3093 // TODO(raymes): When crbug.com/606138 is finished and the
3094 // PermissionRequestManager is used to show all prompts on Android/Desktop
3095 // we should remove PermissionPromptDelegate and just use
3096 // MockPermissionPromptFactory instead. The APIs are the same.
3097 class TestPermissionPromptDelegate
3098 : public MediaStreamDevicesController::PermissionPromptDelegate {
3099 public:
3100 void ShowPrompt(
3101 bool user_gesture,
3102 content::WebContents* web_contents,
3103 std::unique_ptr<MediaStreamDevicesController> controller) override {
3104 if (response_type_ == PermissionRequestManager::ACCEPT_ALL)
3105 controller->PermissionGranted();
3106 else if (response_type_ == PermissionRequestManager::DENY_ALL)
3107 controller->PermissionDenied();
3108 }
3109
3110 void set_response_type(
3111 PermissionRequestManager::AutoResponseType response_type) {
3112 response_type_ = response_type;
3113 }
3114
3115 private:
3116 PermissionRequestManager::AutoResponseType response_type_ =
3117 PermissionRequestManager::NONE;
3118 };
3119
3092 MediaStreamDevicesControllerBrowserTest() 3120 MediaStreamDevicesControllerBrowserTest()
3093 : request_url_allowed_via_whitelist_(false), 3121 : request_url_allowed_via_whitelist_(false),
3094 request_url_("https://www.example.com/foo") { 3122 request_url_("https://www.example.com/foo") {
3095 policy_value_ = GetParam(); 3123 policy_value_ = GetParam();
3124 prompt_delegate_.set_response_type(PermissionRequestManager::ACCEPT_ALL);
3096 } 3125 }
3097 virtual ~MediaStreamDevicesControllerBrowserTest() {} 3126 virtual ~MediaStreamDevicesControllerBrowserTest() {}
3098 3127
3099 // Configure a given policy map. The |policy_name| is the name of either the 3128 // Configure a given policy map. The |policy_name| is the name of either the
3100 // audio or video capture allow policy and must never be NULL. 3129 // audio or video capture allow policy and must never be NULL.
3101 // |whitelist_policy| and |allow_rule| are optional. If NULL, no whitelist 3130 // |whitelist_policy| and |allow_rule| are optional. If NULL, no whitelist
3102 // policy is set. If non-NULL, the whitelist policy is set to contain either 3131 // policy is set. If non-NULL, the whitelist policy is set to contain either
3103 // the |allow_rule| (if non-NULL) or an "allow all" wildcard. 3132 // the |allow_rule| (if non-NULL) or an "allow all" wildcard.
3104 void ConfigurePolicyMap(PolicyMap* policies, const char* policy_name, 3133 void ConfigurePolicyMap(PolicyMap* policies, const char* policy_name,
3105 const char* whitelist_policy, 3134 const char* whitelist_policy,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3139 } 3168 }
3140 } 3169 }
3141 3170
3142 void FinishAudioTest() { 3171 void FinishAudioTest() {
3143 content::MediaStreamRequest request( 3172 content::MediaStreamRequest request(
3144 0, 0, 0, request_url_.GetOrigin(), false, content::MEDIA_DEVICE_ACCESS, 3173 0, 0, 0, request_url_.GetOrigin(), false, content::MEDIA_DEVICE_ACCESS,
3145 std::string(), std::string(), content::MEDIA_DEVICE_AUDIO_CAPTURE, 3174 std::string(), std::string(), content::MEDIA_DEVICE_AUDIO_CAPTURE,
3146 content::MEDIA_NO_SERVICE, false); 3175 content::MEDIA_NO_SERVICE, false);
3147 // TODO(raymes): Test MEDIA_DEVICE_OPEN (Pepper) which grants both webcam 3176 // TODO(raymes): Test MEDIA_DEVICE_OPEN (Pepper) which grants both webcam
3148 // and microphone permissions at the same time. 3177 // and microphone permissions at the same time.
3149 MediaStreamDevicesController controller( 3178 MediaStreamDevicesController::RequestPermissionsWithDelegate(
3150 browser()->tab_strip_model()->GetActiveWebContents(), request, 3179 browser()->tab_strip_model()->GetActiveWebContents(), request,
3151 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, 3180 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept,
3152 base::Unretained(this))); 3181 base::Unretained(this)),
3153 if (controller.IsAskingForAudio()) 3182 &prompt_delegate_);
3154 controller.PermissionGranted();
3155 3183
3156 base::MessageLoop::current()->QuitWhenIdle(); 3184 base::MessageLoop::current()->QuitWhenIdle();
3157 } 3185 }
3158 3186
3159 void FinishVideoTest() { 3187 void FinishVideoTest() {
3160 content::MediaStreamRequest request( 3188 content::MediaStreamRequest request(
3161 0, 0, 0, request_url_.GetOrigin(), false, content::MEDIA_DEVICE_ACCESS, 3189 0, 0, 0, request_url_.GetOrigin(), false, content::MEDIA_DEVICE_ACCESS,
3162 std::string(), std::string(), content::MEDIA_NO_SERVICE, 3190 std::string(), std::string(), content::MEDIA_NO_SERVICE,
3163 content::MEDIA_DEVICE_VIDEO_CAPTURE, false); 3191 content::MEDIA_DEVICE_VIDEO_CAPTURE, false);
3164 // TODO(raymes): Test MEDIA_DEVICE_OPEN (Pepper) which grants both webcam 3192 // TODO(raymes): Test MEDIA_DEVICE_OPEN (Pepper) which grants both webcam
3165 // and microphone permissions at the same time. 3193 // and microphone permissions at the same time.
3166 MediaStreamDevicesController controller( 3194 MediaStreamDevicesController::RequestPermissionsWithDelegate(
3167 browser()->tab_strip_model()->GetActiveWebContents(), request, 3195 browser()->tab_strip_model()->GetActiveWebContents(), request,
3168 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept, 3196 base::Bind(&MediaStreamDevicesControllerBrowserTest::Accept,
3169 base::Unretained(this))); 3197 base::Unretained(this)),
3170 if (controller.IsAskingForVideo()) 3198 &prompt_delegate_);
3171 controller.PermissionGranted();
3172 3199
3173 base::MessageLoop::current()->QuitWhenIdle(); 3200 base::MessageLoop::current()->QuitWhenIdle();
3174 } 3201 }
3175 3202
3203 TestPermissionPromptDelegate prompt_delegate_;
3176 bool policy_value_; 3204 bool policy_value_;
3177 bool request_url_allowed_via_whitelist_; 3205 bool request_url_allowed_via_whitelist_;
3178 GURL request_url_; 3206 GURL request_url_;
3179 static const char kExampleRequestPattern[]; 3207 static const char kExampleRequestPattern[];
3180 }; 3208 };
3181 3209
3182 // static 3210 // static
3183 const char MediaStreamDevicesControllerBrowserTest::kExampleRequestPattern[] = 3211 const char MediaStreamDevicesControllerBrowserTest::kExampleRequestPattern[] =
3184 "https://[*.]example.com/"; 3212 "https://[*.]example.com/";
3185 3213
(...skipping 1224 matching lines...) Expand 10 before | Expand all | Expand 10 after
4410 4438
4411 SetEmptyPolicy(); 4439 SetEmptyPolicy();
4412 // Policy not set. 4440 // Policy not set.
4413 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4441 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4414 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4442 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4415 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4443 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4416 } 4444 }
4417 #endif // defined(OS_CHROMEOS) 4445 #endif // defined(OS_CHROMEOS)
4418 4446
4419 } // namespace policy 4447 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698