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/permissions/permission_result.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_profile_manager.h" | 20 #include "chrome/test/base/testing_profile_manager.h" |
20 #include "components/content_settings/core/browser/host_content_settings_map.h" | 21 #include "components/content_settings/core/browser/host_content_settings_map.h" |
21 #include "components/content_settings/core/common/content_settings_types.h" | 22 #include "components/content_settings/core/common/content_settings_types.h" |
22 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
23 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
24 #include "extensions/common/extension_builder.h" | 25 #include "extensions/common/extension_builder.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "ui/message_center/notifier_settings.h" | 27 #include "ui/message_center/notifier_settings.h" |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 309 |
309 ContentSetting default_setting = | 310 ContentSetting default_setting = |
310 HostContentSettingsMapFactory::GetForProfile(profile) | 311 HostContentSettingsMapFactory::GetForProfile(profile) |
311 ->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); | 312 ->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL); |
312 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting); | 313 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting); |
313 | 314 |
314 PermissionManager* permission_manager = PermissionManager::Get(profile); | 315 PermissionManager* permission_manager = PermissionManager::Get(profile); |
315 | 316 |
316 // (1) Enable the permission when the default is to ask (expected to set). | 317 // (1) Enable the permission when the default is to ask (expected to set). |
317 controller()->SetNotifierEnabled(disabled_notifier, true); | 318 controller()->SetNotifierEnabled(disabled_notifier, true); |
318 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, | 319 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
319 permission_manager->GetPermissionStatus( | 320 permission_manager |
320 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); | 321 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 322 origin, origin) |
| 323 .content_setting); |
321 | 324 |
322 // (2) Disable the permission when the default is to ask (expected to clear). | 325 // (2) Disable the permission when the default is to ask (expected to clear). |
323 controller()->SetNotifierEnabled(enabled_notifier, false); | 326 controller()->SetNotifierEnabled(enabled_notifier, false); |
324 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, | 327 EXPECT_EQ(CONTENT_SETTING_ASK, |
325 permission_manager->GetPermissionStatus( | 328 permission_manager |
326 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); | 329 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 330 origin, origin) |
| 331 .content_setting); |
327 | 332 |
328 // Change the default content setting vaule for notifications to ALLOW. | 333 // Change the default content setting vaule for notifications to ALLOW. |
329 HostContentSettingsMapFactory::GetForProfile(profile) | 334 HostContentSettingsMapFactory::GetForProfile(profile) |
330 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 335 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
331 CONTENT_SETTING_ALLOW); | 336 CONTENT_SETTING_ALLOW); |
332 | 337 |
333 // (3) Disable the permission when the default is allowed (expected to set). | 338 // (3) Disable the permission when the default is allowed (expected to set). |
334 controller()->SetNotifierEnabled(enabled_notifier, false); | 339 controller()->SetNotifierEnabled(enabled_notifier, false); |
335 EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, | 340 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
336 permission_manager->GetPermissionStatus( | 341 permission_manager |
337 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); | 342 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 343 origin, origin) |
| 344 .content_setting); |
338 | 345 |
339 // (4) Enable the permission when the default is allowed (expected to clear). | 346 // (4) Enable the permission when the default is allowed (expected to clear). |
340 controller()->SetNotifierEnabled(disabled_notifier, true); | 347 controller()->SetNotifierEnabled(disabled_notifier, true); |
341 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, | 348 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
342 permission_manager->GetPermissionStatus( | 349 permission_manager |
343 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); | 350 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 351 origin, origin) |
| 352 .content_setting); |
344 | 353 |
345 // Now change the default content setting value to BLOCK. | 354 // Now change the default content setting value to BLOCK. |
346 HostContentSettingsMapFactory::GetForProfile(profile) | 355 HostContentSettingsMapFactory::GetForProfile(profile) |
347 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 356 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
348 CONTENT_SETTING_BLOCK); | 357 CONTENT_SETTING_BLOCK); |
349 | 358 |
350 // (5) Enable the permission when the default is blocked (expected to set). | 359 // (5) Enable the permission when the default is blocked (expected to set). |
351 controller()->SetNotifierEnabled(disabled_notifier, true); | 360 controller()->SetNotifierEnabled(disabled_notifier, true); |
352 EXPECT_EQ(blink::mojom::PermissionStatus::GRANTED, | 361 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
353 permission_manager->GetPermissionStatus( | 362 permission_manager |
354 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); | 363 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 364 origin, origin) |
| 365 .content_setting); |
355 | 366 |
356 // (6) Disable the permission when the default is blocked (expected to clear). | 367 // (6) Disable the permission when the default is blocked (expected to clear). |
357 controller()->SetNotifierEnabled(enabled_notifier, false); | 368 controller()->SetNotifierEnabled(enabled_notifier, false); |
358 EXPECT_EQ(blink::mojom::PermissionStatus::DENIED, | 369 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
359 permission_manager->GetPermissionStatus( | 370 permission_manager |
360 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, origin, origin)); | 371 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 372 origin, origin) |
| 373 .content_setting); |
361 } | 374 } |
OLD | NEW |