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 #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/message_center_settings_controller.h" | 15 #include "chrome/browser/notifications/message_center_settings_controller.h" |
16 #include "chrome/browser/permissions/permission_manager.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 "components/content_settings/core/common/content_settings_types.h" |
22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
24 #include "extensions/common/extension_builder.h" | 24 #include "extensions/common/extension_builder.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "ui/message_center/notifier_settings.h" | 26 #include "ui/message_center/notifier_settings.h" |
27 | 27 |
28 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
29 #include "ash/common/system/system_notifier.h" | 29 #include "ash/common/system/system_notifier.h" |
30 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 30 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 31 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 HostContentSettingsMapFactory::GetForProfile(profile) | 310 HostContentSettingsMapFactory::GetForProfile(profile) |
311 ->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); | 311 ->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); |
312 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting); | 312 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting); |
313 | 313 |
314 PermissionManager* permission_manager = PermissionManager::Get(profile); | 314 PermissionManager* permission_manager = PermissionManager::Get(profile); |
315 | 315 |
316 // (1) Enable the permission when the default is to ask (expected to set). | 316 // (1) Enable the permission when the default is to ask (expected to set). |
317 controller()->SetNotifierEnabled(disabled_notifier, true); | 317 controller()->SetNotifierEnabled(disabled_notifier, true); |
318 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, | 318 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, |
319 permission_manager->GetPermissionStatus( | 319 permission_manager->GetPermissionStatus( |
320 content::PermissionType::NOTIFICATIONS, origin, origin)); | 320 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); |
321 | 321 |
322 // (2) Disable the permission when the default is to ask (expected to clear). | 322 // (2) Disable the permission when the default is to ask (expected to clear). |
323 controller()->SetNotifierEnabled(enabled_notifier, false); | 323 controller()->SetNotifierEnabled(enabled_notifier, false); |
324 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, | 324 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, |
325 permission_manager->GetPermissionStatus( | 325 permission_manager->GetPermissionStatus( |
326 content::PermissionType::NOTIFICATIONS, origin, origin)); | 326 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); |
327 | 327 |
328 // Change the default content setting vaule for notifications to ALLOW. | 328 // Change the default content setting vaule for notifications to ALLOW. |
329 HostContentSettingsMapFactory::GetForProfile(profile) | 329 HostContentSettingsMapFactory::GetForProfile(profile) |
330 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 330 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
331 CONTENT_SETTING_ALLOW); | 331 CONTENT_SETTING_ALLOW); |
332 | 332 |
333 // (3) Disable the permission when the default is allowed (expected to set). | 333 // (3) Disable the permission when the default is allowed (expected to set). |
334 controller()->SetNotifierEnabled(enabled_notifier, false); | 334 controller()->SetNotifierEnabled(enabled_notifier, false); |
335 EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, | 335 EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, |
336 permission_manager->GetPermissionStatus( | 336 permission_manager->GetPermissionStatus( |
337 content::PermissionType::NOTIFICATIONS, origin, origin)); | 337 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); |
338 | 338 |
339 // (4) Enable the permission when the default is allowed (expected to clear). | 339 // (4) Enable the permission when the default is allowed (expected to clear). |
340 controller()->SetNotifierEnabled(disabled_notifier, true); | 340 controller()->SetNotifierEnabled(disabled_notifier, true); |
341 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, | 341 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, |
342 permission_manager->GetPermissionStatus( | 342 permission_manager->GetPermissionStatus( |
343 content::PermissionType::NOTIFICATIONS, origin, origin)); | 343 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); |
344 | 344 |
345 // Now change the default content setting value to BLOCK. | 345 // Now change the default content setting value to BLOCK. |
346 HostContentSettingsMapFactory::GetForProfile(profile) | 346 HostContentSettingsMapFactory::GetForProfile(profile) |
347 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 347 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
348 CONTENT_SETTING_BLOCK); | 348 CONTENT_SETTING_BLOCK); |
349 | 349 |
350 // (5) Enable the permission when the default is blocked (expected to set). | 350 // (5) Enable the permission when the default is blocked (expected to set). |
351 controller()->SetNotifierEnabled(disabled_notifier, true); | 351 controller()->SetNotifierEnabled(disabled_notifier, true); |
352 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, | 352 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, |
353 permission_manager->GetPermissionStatus( | 353 permission_manager->GetPermissionStatus( |
354 content::PermissionType::NOTIFICATIONS, origin, origin)); | 354 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); |
355 | 355 |
356 // (6) Disable the permission when the default is blocked (expected to clear). | 356 // (6) Disable the permission when the default is blocked (expected to clear). |
357 controller()->SetNotifierEnabled(enabled_notifier, false); | 357 controller()->SetNotifierEnabled(enabled_notifier, false); |
358 EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, | 358 EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, |
359 permission_manager->GetPermissionStatus( | 359 permission_manager->GetPermissionStatus( |
360 content::PermissionType::NOTIFICATIONS, origin, origin)); | 360 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); |
361 } | 361 } |
OLD | NEW |