| OLD | NEW |
| 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 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/test_extension_system.h" | 11 #include "chrome/browser/extensions/test_extension_system.h" |
| 11 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 12 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 12 #include "chrome/browser/notifications/message_center_settings_controller.h" | 13 #include "chrome/browser/notifications/message_center_settings_controller.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | 14 #include "chrome/browser/profiles/profile_info_cache.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
| 17 #include "components/content_settings/core/browser/host_content_settings_map.h" | 18 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 290 |
| 290 GURL origin("https://example.com/"); | 291 GURL origin("https://example.com/"); |
| 291 | 292 |
| 292 message_center::NotifierId notifier_id(origin); | 293 message_center::NotifierId notifier_id(origin); |
| 293 message_center::Notifier enabled_notifier( | 294 message_center::Notifier enabled_notifier( |
| 294 notifier_id, base::string16(), true); | 295 notifier_id, base::string16(), true); |
| 295 message_center::Notifier disabled_notifier( | 296 message_center::Notifier disabled_notifier( |
| 296 notifier_id, base::string16(), false); | 297 notifier_id, base::string16(), false); |
| 297 | 298 |
| 298 ContentSetting default_setting = | 299 ContentSetting default_setting = |
| 299 profile->GetHostContentSettingsMap()->GetDefaultContentSetting( | 300 HostContentSettingsMapFactory::GetForProfile(profile) |
| 300 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); | 301 ->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); |
| 301 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting); | 302 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting); |
| 302 | 303 |
| 303 // (1) Enable the permission when the default is to ask (expected to set). | 304 // (1) Enable the permission when the default is to ask (expected to set). |
| 304 controller()->SetNotifierEnabled(disabled_notifier, true); | 305 controller()->SetNotifierEnabled(disabled_notifier, true); |
| 305 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 306 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 306 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); | 307 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); |
| 307 | 308 |
| 308 // (2) Disable the permission when the default is to ask (expected to clear). | 309 // (2) Disable the permission when the default is to ask (expected to clear). |
| 309 controller()->SetNotifierEnabled(enabled_notifier, false); | 310 controller()->SetNotifierEnabled(enabled_notifier, false); |
| 310 EXPECT_EQ(CONTENT_SETTING_ASK, | 311 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 311 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); | 312 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); |
| 312 | 313 |
| 313 // Change the default content setting vaule for notifications to ALLOW. | 314 // Change the default content setting vaule for notifications to ALLOW. |
| 314 profile->GetHostContentSettingsMap()->SetDefaultContentSetting( | 315 HostContentSettingsMapFactory::GetForProfile(profile) |
| 315 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); | 316 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 317 CONTENT_SETTING_ALLOW); |
| 316 | 318 |
| 317 // (3) Disable the permission when the default is allowed (expected to set). | 319 // (3) Disable the permission when the default is allowed (expected to set). |
| 318 controller()->SetNotifierEnabled(enabled_notifier, false); | 320 controller()->SetNotifierEnabled(enabled_notifier, false); |
| 319 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 321 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 320 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); | 322 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); |
| 321 | 323 |
| 322 // (4) Enable the permission when the default is allowed (expected to clear). | 324 // (4) Enable the permission when the default is allowed (expected to clear). |
| 323 controller()->SetNotifierEnabled(disabled_notifier, true); | 325 controller()->SetNotifierEnabled(disabled_notifier, true); |
| 324 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 326 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 325 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); | 327 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); |
| 326 | 328 |
| 327 // Now change the default content setting value to BLOCK. | 329 // Now change the default content setting value to BLOCK. |
| 328 profile->GetHostContentSettingsMap()->SetDefaultContentSetting( | 330 HostContentSettingsMapFactory::GetForProfile(profile) |
| 329 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK); | 331 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 332 CONTENT_SETTING_BLOCK); |
| 330 | 333 |
| 331 // (5) Enable the permission when the default is blocked (expected to set). | 334 // (5) Enable the permission when the default is blocked (expected to set). |
| 332 controller()->SetNotifierEnabled(disabled_notifier, true); | 335 controller()->SetNotifierEnabled(disabled_notifier, true); |
| 333 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 336 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 334 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); | 337 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); |
| 335 | 338 |
| 336 // (6) Disable the permission when the default is blocked (expected to clear). | 339 // (6) Disable the permission when the default is blocked (expected to clear). |
| 337 controller()->SetNotifierEnabled(enabled_notifier, false); | 340 controller()->SetNotifierEnabled(enabled_notifier, false); |
| 338 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 341 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 339 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); | 342 DesktopNotificationProfileUtil::GetContentSetting(profile, origin)); |
| 340 } | 343 } |
| OLD | NEW |