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

Side by Side Diff: chrome/browser/notifications/message_center_settings_controller_unittest.cc

Issue 2020063003: Use GetPermissionStatus instead of DesktopNotificationProfileUtil::GetContentSetting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove embber param for notifications Created 4 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/test_extension_system.h" 14 #include "chrome/browser/extensions/test_extension_system.h"
15 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
16 #include "chrome/browser/notifications/message_center_settings_controller.h" 15 #include "chrome/browser/notifications/message_center_settings_controller.h"
16 #include "chrome/browser/permissions/permission_manager.h"
17 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/test/base/testing_browser_process.h" 18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_profile_manager.h" 19 #include "chrome/test/base/testing_profile_manager.h"
20 #include "components/content_settings/core/browser/host_content_settings_map.h" 20 #include "components/content_settings/core/browser/host_content_settings_map.h"
21 #include "content/public/browser/permission_type.h"
21 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
23 #include "extensions/common/extension_builder.h" 24 #include "extensions/common/extension_builder.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/message_center/notifier_settings.h" 26 #include "ui/message_center/notifier_settings.h"
26 27
27 #if defined(OS_CHROMEOS) 28 #if defined(OS_CHROMEOS)
28 #include "ash/system/system_notifier.h" 29 #include "ash/system/system_notifier.h"
29 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 30 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
30 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 message_center::Notifier enabled_notifier( 306 message_center::Notifier enabled_notifier(
306 notifier_id, base::string16(), true); 307 notifier_id, base::string16(), true);
307 message_center::Notifier disabled_notifier( 308 message_center::Notifier disabled_notifier(
308 notifier_id, base::string16(), false); 309 notifier_id, base::string16(), false);
309 310
310 ContentSetting default_setting = 311 ContentSetting default_setting =
311 HostContentSettingsMapFactory::GetForProfile(profile) 312 HostContentSettingsMapFactory::GetForProfile(profile)
312 ->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); 313 ->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL);
313 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting); 314 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting);
314 315
316 PermissionManager* permission_manager = PermissionManager::Get(profile);
317
315 // (1) Enable the permission when the default is to ask (expected to set). 318 // (1) Enable the permission when the default is to ask (expected to set).
316 controller()->SetNotifierEnabled(disabled_notifier, true); 319 controller()->SetNotifierEnabled(disabled_notifier, true);
317 EXPECT_EQ(CONTENT_SETTING_ALLOW, 320 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED,
318 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); 321 permission_manager->GetPermissionStatus(
322 content::PermissionType::NOTIFICATIONS, origin, origin));
319 323
320 // (2) Disable the permission when the default is to ask (expected to clear). 324 // (2) Disable the permission when the default is to ask (expected to clear).
321 controller()->SetNotifierEnabled(enabled_notifier, false); 325 controller()->SetNotifierEnabled(enabled_notifier, false);
322 EXPECT_EQ(CONTENT_SETTING_ASK, 326 EXPECT_EQ(blink::mojom::PermissionStatus::ASK,
323 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); 327 permission_manager->GetPermissionStatus(
328 content::PermissionType::NOTIFICATIONS, origin, origin));
324 329
325 // Change the default content setting vaule for notifications to ALLOW. 330 // Change the default content setting vaule for notifications to ALLOW.
326 HostContentSettingsMapFactory::GetForProfile(profile) 331 HostContentSettingsMapFactory::GetForProfile(profile)
327 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 332 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
328 CONTENT_SETTING_ALLOW); 333 CONTENT_SETTING_ALLOW);
329 334
330 // (3) Disable the permission when the default is allowed (expected to set). 335 // (3) Disable the permission when the default is allowed (expected to set).
331 controller()->SetNotifierEnabled(enabled_notifier, false); 336 controller()->SetNotifierEnabled(enabled_notifier, false);
332 EXPECT_EQ(CONTENT_SETTING_BLOCK, 337 EXPECT_EQ(blink::mojom::PermissionStatus::DENIED,
333 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); 338 permission_manager->GetPermissionStatus(
339 content::PermissionType::NOTIFICATIONS, origin, origin));
334 340
335 // (4) Enable the permission when the default is allowed (expected to clear). 341 // (4) Enable the permission when the default is allowed (expected to clear).
336 controller()->SetNotifierEnabled(disabled_notifier, true); 342 controller()->SetNotifierEnabled(disabled_notifier, true);
337 EXPECT_EQ(CONTENT_SETTING_ALLOW, 343 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED,
338 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); 344 permission_manager->GetPermissionStatus(
345 content::PermissionType::NOTIFICATIONS, origin, origin));
339 346
340 // Now change the default content setting value to BLOCK. 347 // Now change the default content setting value to BLOCK.
341 HostContentSettingsMapFactory::GetForProfile(profile) 348 HostContentSettingsMapFactory::GetForProfile(profile)
342 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 349 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
343 CONTENT_SETTING_BLOCK); 350 CONTENT_SETTING_BLOCK);
344 351
345 // (5) Enable the permission when the default is blocked (expected to set). 352 // (5) Enable the permission when the default is blocked (expected to set).
346 controller()->SetNotifierEnabled(disabled_notifier, true); 353 controller()->SetNotifierEnabled(disabled_notifier, true);
347 EXPECT_EQ(CONTENT_SETTING_ALLOW, 354 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED,
348 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); 355 permission_manager->GetPermissionStatus(
356 content::PermissionType::NOTIFICATIONS, origin, origin));
349 357
350 // (6) Disable the permission when the default is blocked (expected to clear). 358 // (6) Disable the permission when the default is blocked (expected to clear).
351 controller()->SetNotifierEnabled(enabled_notifier, false); 359 controller()->SetNotifierEnabled(enabled_notifier, false);
352 EXPECT_EQ(CONTENT_SETTING_BLOCK, 360 EXPECT_EQ(blink::mojom::PermissionStatus::DENIED,
353 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); 361 permission_manager->GetPermissionStatus(
362 content::PermissionType::NOTIFICATIONS, origin, origin));
354 } 363 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698