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

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

Issue 1103203002: Allow resetting Notification permission from the toast's context menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a test Created 5 years, 8 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 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/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/test_extension_system.h" 10 #include "chrome/browser/extensions/test_extension_system.h"
11 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
11 #include "chrome/browser/notifications/message_center_settings_controller.h" 12 #include "chrome/browser/notifications/message_center_settings_controller.h"
12 #include "chrome/browser/profiles/profile_info_cache.h" 13 #include "chrome/browser/profiles/profile_info_cache.h"
13 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/test/base/testing_browser_process.h" 15 #include "chrome/test/base/testing_browser_process.h"
15 #include "chrome/test/base/testing_profile_manager.h" 16 #include "chrome/test/base/testing_profile_manager.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
18 #include "extensions/common/extension_builder.h" 20 #include "extensions/common/extension_builder.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/message_center/notifier_settings.h" 22 #include "ui/message_center/notifier_settings.h"
21 23
22 #if defined(OS_CHROMEOS) 24 #if defined(OS_CHROMEOS)
23 #include "ash/system/system_notifier.h" 25 #include "ash/system/system_notifier.h"
24 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 26 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
25 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 27 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
26 #endif 28 #endif
27 29
28 class MessageCenterSettingsControllerBaseTest : public testing::Test { 30 class MessageCenterSettingsControllerBaseTest : public testing::Test {
29 protected: 31 protected:
30 MessageCenterSettingsControllerBaseTest() 32 MessageCenterSettingsControllerBaseTest()
31 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()){}; 33 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {}
32 34
33 ~MessageCenterSettingsControllerBaseTest() override{}; 35 ~MessageCenterSettingsControllerBaseTest() override{};
34 36
35 base::FilePath GetProfilePath(const std::string& base_name) { 37 base::FilePath GetProfilePath(const std::string& base_name) {
36 return testing_profile_manager_.profile_manager()->user_data_dir() 38 return testing_profile_manager_.profile_manager()->user_data_dir()
37 .AppendASCII(base_name); 39 .AppendASCII(base_name);
38 } 40 }
39 41
40 void SetUp() override { ASSERT_TRUE(testing_profile_manager_.SetUp()); } 42 void SetUp() override { ASSERT_TRUE(testing_profile_manager_.SetUp()); }
41 43
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 EXPECT_EQ(3u, notifiers.size()); 252 EXPECT_EQ(3u, notifiers.size());
251 EXPECT_EQ(ash::system_notifier::kNotifierScreenshot, 253 EXPECT_EQ(ash::system_notifier::kNotifierScreenshot,
252 notifiers[2]->notifier_id.id); 254 notifiers[2]->notifier_id.id);
253 #endif 255 #endif
254 256
255 EXPECT_EQ(kBarId, notifiers[0]->notifier_id.id); 257 EXPECT_EQ(kBarId, notifiers[0]->notifier_id.id);
256 EXPECT_EQ(kFooId, notifiers[1]->notifier_id.id); 258 EXPECT_EQ(kFooId, notifiers[1]->notifier_id.id);
257 259
258 STLDeleteElements(&notifiers); 260 STLDeleteElements(&notifiers);
259 } 261 }
262
263 TEST_F(MessageCenterSettingsControllerTest, SetWebPageNotifierEnabled) {
264 Profile* profile = CreateProfile("MyProfile");
265 CreateController();
266
267 GURL origin("https://example.com/");
268
269 message_center::NotifierId notifier_id(origin);
270 message_center::Notifier enabled_notifier(
271 notifier_id, base::string16(), true);
272 message_center::Notifier disabled_notifier(
273 notifier_id, base::string16(), false);
274
275 ContentSetting default_setting =
276 profile->GetHostContentSettingsMap()->GetDefaultContentSetting(
277 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL);
278 ASSERT_EQ(CONTENT_SETTING_ASK, default_setting);
279
280 // (1) Enable the permission when the default is to ask (expected to set).
281 controller()->SetNotifierEnabled(disabled_notifier, true);
282 EXPECT_EQ(CONTENT_SETTING_ALLOW,
283 DesktopNotificationProfileUtil::GetContentSetting(profile, origin));
284
285 // (2) Disable the permission when the default is to ask (expected to clear).
dewittj 2015/04/27 16:48:51 Is this true? I would expect an explicit disable b
Peter Beverloo 2015/04/28 12:14:45 I noticed this (default allowed -> disable does BL
286 controller()->SetNotifierEnabled(enabled_notifier, false);
287 EXPECT_EQ(CONTENT_SETTING_ASK,
288 DesktopNotificationProfileUtil::GetContentSetting(profile, origin));
289
290 // Change the default content setting vaule for notifications to ALLOW.
291 profile->GetHostContentSettingsMap()->SetDefaultContentSetting(
292 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
293
294 // (3) Disable the permission when the default is allowed (expected to set).
295 controller()->SetNotifierEnabled(enabled_notifier, false);
296 EXPECT_EQ(CONTENT_SETTING_BLOCK,
297 DesktopNotificationProfileUtil::GetContentSetting(profile, origin));
298
299 // (4) Enable the permission when the default is allowed (expected to clear).
300 controller()->SetNotifierEnabled(disabled_notifier, true);
301 EXPECT_EQ(CONTENT_SETTING_ALLOW,
302 DesktopNotificationProfileUtil::GetContentSetting(profile, origin));
303 }
dewittj 2015/04/27 16:48:51 what about default is block?
Peter Beverloo 2015/04/28 12:14:45 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698