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

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc

Issue 588153003: Remove MediaSettingChangedInfobar and show latest state in bubble (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: switch -> if Created 6 years, 2 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
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 "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/content_settings/host_content_settings_map.h" 8 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
11 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 12 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
13 #include "chrome/browser/media/media_stream_capture_indicator.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 15 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
18 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
19 #include "components/content_settings/core/common/content_settings.h" 20 #include "components/content_settings/core/common/content_settings.h"
20 #include "components/infobars/core/infobar_delegate.h" 21 #include "components/infobars/core/infobar_delegate.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/web_contents_tester.h" 23 #include "content/public/test/web_contents_tester.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 url, 227 url,
227 url, 228 url,
228 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, 229 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
229 std::string())); 230 std::string()));
230 EXPECT_EQ(CONTENT_SETTING_ALLOW, 231 EXPECT_EQ(CONTENT_SETTING_ALLOW,
231 host_content_settings_map->GetContentSetting( 232 host_content_settings_map->GetContentSetting(
232 url, 233 url,
233 url, 234 url,
234 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, 235 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
235 std::string())); 236 std::string()));
236
237 InfoBarService* infobar_service =
238 InfoBarService::FromWebContents(web_contents());
239 infobar_service->RemoveInfoBar(infobar_service->infobar_at(0));
240 } 237 }
241 238
239 // Tests whether a changed setting in the setting bubble is displayed again when
240 // the bubble is re-opened.
241 TEST_F(ContentSettingBubbleModelTest, MediastreamContentBubble) {
242 // Required to break dependency on BrowserMainLoop.
243 MediaCaptureDevicesDispatcher::GetInstance()->
244 DisableDeviceEnumerationForTesting();
245
246 WebContentsTester::For(web_contents())->
247 NavigateAndCommit(GURL("https://www.example.com"));
248 GURL url = web_contents()->GetURL();
249
250 HostContentSettingsMap* host_content_settings_map =
251 profile()->GetHostContentSettingsMap();
252 ContentSettingsPattern primary_pattern =
253 ContentSettingsPattern::FromURL(url);
254 ContentSetting setting = CONTENT_SETTING_BLOCK;
255 host_content_settings_map->SetContentSetting(
256 primary_pattern,
257 ContentSettingsPattern::Wildcard(),
258 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
259 std::string(),
260 setting);
261
262 TabSpecificContentSettings* content_settings =
263 TabSpecificContentSettings::FromWebContents(web_contents());
264 MediaStreamDevicesController::MediaStreamTypeSettingsMap
265 request_permissions;
266 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
267 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER;
268 content_settings->OnMediaStreamPermissionSet(url, request_permissions);
269 {
270 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
271 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
272 NULL, web_contents(), profile(),
273 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
274 const ContentSettingBubbleModel::BubbleContent& bubble_content =
275 content_setting_bubble_model->bubble_content();
276 // Test if the correct radio item is selected for the blocked mediastream
277 // setting.
278 EXPECT_EQ(1, bubble_content.radio_group.default_item);
279 // Change the radio setting.
280 content_setting_bubble_model->OnRadioClicked(0);
281 }
282 // Test that the setting was changed.
283 EXPECT_EQ(CONTENT_SETTING_ALLOW,
284 host_content_settings_map->GetContentSetting(
285 url,
286 url,
287 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
288 std::string()));
289
290 {
291 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
292 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
293 NULL, web_contents(), profile(),
294 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
295 const ContentSettingBubbleModel::BubbleContent& bubble_content =
296 content_setting_bubble_model->bubble_content();
297 // Test that the reload hint is displayed.
298 EXPECT_FALSE(bubble_content.custom_link_enabled);
299 EXPECT_EQ(bubble_content.custom_link, l10n_util::GetStringUTF8(
300 IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE));
301
302 EXPECT_EQ(0, bubble_content.radio_group.default_item);
303 // Restore the radio setting (to block).
304 content_setting_bubble_model->OnRadioClicked(1);
305 }
306 // Test that the media settings were changed again.
307 EXPECT_EQ(CONTENT_SETTING_BLOCK,
308 host_content_settings_map->GetContentSetting(
309 url,
310 url,
311 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
312 std::string()));
313
314 {
315 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
316 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
317 NULL, web_contents(), profile(),
318 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
319 const ContentSettingBubbleModel::BubbleContent& bubble_content =
320 content_setting_bubble_model->bubble_content();
321 // Test that the reload hint is not displayed any more.
322 EXPECT_FALSE(bubble_content.custom_link_enabled);
323 EXPECT_TRUE(bubble_content.custom_link.empty());
324
325 EXPECT_EQ(1, bubble_content.radio_group.default_item);
326 }
327 }
328
329 // Tests whether the media menu settings are correctly persisted in the bubble.
330 TEST_F(ContentSettingBubbleModelTest, MediastreamContentBubbleMediaMenus) {
331 // Required to break dependency on BrowserMainLoop.
332 MediaCaptureDevicesDispatcher::GetInstance()->
333 DisableDeviceEnumerationForTesting();
334
335 WebContentsTester::For(web_contents())->
336 NavigateAndCommit(GURL("https://www.example.com"));
337 GURL url = web_contents()->GetURL();
338
339 content::MediaStreamDevices audio_devices;
340 content::MediaStreamDevice fake_audio_device1(
341 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev1", "Fake Audio Device 1");
342 content::MediaStreamDevice fake_audio_device2(
343 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev2", "Fake Audio Device 2");
344 content::MediaStreamDevice fake_audio_device3(
345 content::MEDIA_DEVICE_AUDIO_CAPTURE, "fake_dev3", "Fake Audio Device 3");
346 audio_devices.push_back(fake_audio_device1);
347 audio_devices.push_back(fake_audio_device2);
348 audio_devices.push_back(fake_audio_device3);
349 MediaCaptureDevicesDispatcher::GetInstance()->SetTestAudioCaptureDevices(
350 audio_devices);
351
352 TabSpecificContentSettings* content_settings =
353 TabSpecificContentSettings::FromWebContents(web_contents());
354 MediaStreamDevicesController::MediaStreamTypeSettingsMap
355 request_permissions;
356 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
357 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER;
358 content_settings->OnMediaStreamPermissionSet(url, request_permissions);
359 {
360 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
361 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
362 NULL, web_contents(), profile(),
363 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
364 const ContentSettingBubbleModel::BubbleContent& bubble_content =
365 content_setting_bubble_model->bubble_content();
366 EXPECT_TRUE(bubble_content.custom_link.empty());
367
368 EXPECT_EQ(1U, bubble_content.media_menus.size());
369 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE,
370 bubble_content.media_menus.begin()->first);
371 EXPECT_FALSE(bubble_content.media_menus.begin()->second.disabled);
372 // The first audio device should be selected by default.
373 EXPECT_TRUE(fake_audio_device1.IsEqual(
374 bubble_content.media_menus.begin()->second.selected_device));
375
376 // Select a different (the second) device.
377 content_setting_bubble_model->OnMediaMenuClicked(
378 content::MEDIA_DEVICE_AUDIO_CAPTURE,
379 fake_audio_device2.id);
380 }
381 {
382 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
383 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
384 NULL, web_contents(), profile(),
385 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
386 const ContentSettingBubbleModel::BubbleContent& bubble_content =
387 content_setting_bubble_model->bubble_content();
388 EXPECT_EQ(1U, bubble_content.media_menus.size());
389 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE,
390 bubble_content.media_menus.begin()->first);
391 EXPECT_FALSE(bubble_content.media_menus.begin()->second.disabled);
392 // The second audio device should be selected.
393 EXPECT_TRUE(fake_audio_device2.IsEqual(
394 bubble_content.media_menus.begin()->second.selected_device));
395 // The "settings changed" message should not be displayed when there is no
396 // active capture.
397 EXPECT_FALSE(bubble_content.custom_link_enabled);
398 EXPECT_TRUE(bubble_content.custom_link.empty());
399 }
400
401 // Simulate that an audio stream is being captured.
402 scoped_refptr<MediaStreamCaptureIndicator> indicator =
403 MediaCaptureDevicesDispatcher::GetInstance()->
404 GetMediaStreamCaptureIndicator();
405 scoped_ptr<content::MediaStreamUI> media_stream_ui =
406 indicator->RegisterMediaStream(web_contents(), audio_devices);
407 media_stream_ui->OnStarted(base::Closure());
408 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
409 MediaStreamDevicesController::MEDIA_ALLOWED;
410 content_settings->OnMediaStreamPermissionSet(url, request_permissions);
411
412 {
413 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
414 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
415 NULL, web_contents(), profile(),
416 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
417 const ContentSettingBubbleModel::BubbleContent& bubble_content =
418 content_setting_bubble_model->bubble_content();
419 // Settings not changed yet, so the "settings changed" message should not be
420 // shown.
421 EXPECT_TRUE(bubble_content.custom_link.empty());
422
423 EXPECT_EQ(1U, bubble_content.media_menus.size());
424 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE,
425 bubble_content.media_menus.begin()->first);
426 EXPECT_FALSE(bubble_content.media_menus.begin()->second.disabled);
427 EXPECT_TRUE(fake_audio_device2.IsEqual(
428 bubble_content.media_menus.begin()->second.selected_device));
429
430 // Select a different different device.
431 content_setting_bubble_model->OnMediaMenuClicked(
432 content::MEDIA_DEVICE_AUDIO_CAPTURE,
433 fake_audio_device3.id);
434 }
435
436 {
437 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
438 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
439 NULL, web_contents(), profile(),
440 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
441 const ContentSettingBubbleModel::BubbleContent& bubble_content =
442 content_setting_bubble_model->bubble_content();
443 // Test that the reload hint is displayed.
444 EXPECT_FALSE(bubble_content.custom_link_enabled);
445 EXPECT_EQ(bubble_content.custom_link, l10n_util::GetStringUTF8(
446 IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE));
447 }
448
449 // Simulate that yet another audio stream capture request was initiated.
450 request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
451 MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER;
452 content_settings->OnMediaStreamPermissionSet(url, request_permissions);
453
454 {
455 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
456 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
457 NULL, web_contents(), profile(),
458 CONTENT_SETTINGS_TYPE_MEDIASTREAM));
459 const ContentSettingBubbleModel::BubbleContent& bubble_content =
460 content_setting_bubble_model->bubble_content();
461 // Test that the reload hint is not displayed any more, because this is a
462 // new permission request.
463 EXPECT_FALSE(bubble_content.custom_link_enabled);
464 EXPECT_TRUE(bubble_content.custom_link.empty());
465
466 // Though the audio menu setting should have persisted.
467 EXPECT_EQ(1U, bubble_content.media_menus.size());
468 EXPECT_EQ(content::MEDIA_DEVICE_AUDIO_CAPTURE,
469 bubble_content.media_menus.begin()->first);
470 EXPECT_FALSE(bubble_content.media_menus.begin()->second.disabled);
471 EXPECT_TRUE(fake_audio_device3.IsEqual(
472 bubble_content.media_menus.begin()->second.selected_device));
473 }
474 }
475
242 TEST_F(ContentSettingBubbleModelTest, MediastreamMic) { 476 TEST_F(ContentSettingBubbleModelTest, MediastreamMic) {
243 // Required to break dependency on BrowserMainLoop. 477 // Required to break dependency on BrowserMainLoop.
244 MediaCaptureDevicesDispatcher::GetInstance()-> 478 MediaCaptureDevicesDispatcher::GetInstance()->
245 DisableDeviceEnumerationForTesting(); 479 DisableDeviceEnumerationForTesting();
246 480
247 TabSpecificContentSettings* content_settings = 481 TabSpecificContentSettings* content_settings =
248 TabSpecificContentSettings::FromWebContents(web_contents()); 482 TabSpecificContentSettings::FromWebContents(web_contents());
249 std::string request_host = "google.com"; 483 std::string request_host = "google.com";
250 GURL security_origin("http://" + request_host); 484 GURL security_origin("http://" + request_host);
251 MediaStreamDevicesController::MediaStreamTypeSettingsMap 485 MediaStreamDevicesController::MediaStreamTypeSettingsMap
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 { 895 {
662 ProtocolHandler handler = registry.GetHandlerFor("mailto"); 896 ProtocolHandler handler = registry.GetHandlerFor("mailto");
663 ASSERT_FALSE(handler.IsEmpty()); 897 ASSERT_FALSE(handler.IsEmpty());
664 EXPECT_EQ(CONTENT_SETTING_ALLOW, 898 EXPECT_EQ(CONTENT_SETTING_ALLOW,
665 content_settings->pending_protocol_handler_setting()); 899 content_settings->pending_protocol_handler_setting());
666 EXPECT_FALSE(registry.IsIgnored(test_handler)); 900 EXPECT_FALSE(registry.IsIgnored(test_handler));
667 } 901 }
668 902
669 registry.Shutdown(); 903 registry.Shutdown();
670 } 904 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698