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

Side by Side Diff: chrome/browser/extensions/extension_warning_badge_service_unittest.cc

Issue 503033002: Move ExtensionWarningService and ExtensionsWarningSet to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@3_web_view_internal
Patch Set: rebase Created 6 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_warning_badge_service.h" 5 #include "chrome/browser/extensions/extension_warning_badge_service.h"
6 6
7 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/extensions/extension_warning_set.h"
9 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/global_error/global_error_service.h" 9 #include "chrome/browser/ui/global_error/global_error_service.h"
11 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 10 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
12 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
12 #include "extensions/browser/warning_service.h"
13 #include "extensions/browser/warning_set.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 namespace { 18 namespace {
18 19
19 class TestExtensionWarningSet : public ExtensionWarningService { 20 class TestExtensionWarningSet : public WarningService {
20 public: 21 public:
21 explicit TestExtensionWarningSet(Profile* profile) 22 explicit TestExtensionWarningSet(Profile* profile) : WarningService(profile) {
22 : ExtensionWarningService(profile) {
23 } 23 }
24 virtual ~TestExtensionWarningSet() {} 24 virtual ~TestExtensionWarningSet() {}
25 25
26 void AddWarning(const ExtensionWarning& warning) { 26 void AddWarning(const Warning& warning) {
27 ExtensionWarningSet warnings; 27 WarningSet warnings;
28 warnings.insert(warning); 28 warnings.insert(warning);
29 AddWarnings(warnings); 29 AddWarnings(warnings);
30 } 30 }
31 }; 31 };
32 32
33 class TestExtensionWarningBadgeService : public ExtensionWarningBadgeService { 33 class TestExtensionWarningBadgeService : public ExtensionWarningBadgeService {
34 public: 34 public:
35 TestExtensionWarningBadgeService(Profile* profile, 35 TestExtensionWarningBadgeService(Profile* profile,
36 ExtensionWarningService* warning_service) 36 WarningService* warning_service)
37 : ExtensionWarningBadgeService(profile), 37 : ExtensionWarningBadgeService(profile),
38 warning_service_(warning_service) {} 38 warning_service_(warning_service) {}
39 virtual ~TestExtensionWarningBadgeService() {} 39 virtual ~TestExtensionWarningBadgeService() {}
40 40
41 virtual const std::set<ExtensionWarning>& 41 virtual const std::set<Warning>&
42 GetCurrentWarnings() const OVERRIDE { 42 GetCurrentWarnings() const OVERRIDE {
43 return warning_service_->warnings(); 43 return warning_service_->warnings();
44 } 44 }
45 45
46 private: 46 private:
47 ExtensionWarningService* warning_service_; 47 WarningService* warning_service_;
48 }; 48 };
49 49
50 bool HasBadge(Profile* profile) { 50 bool HasBadge(Profile* profile) {
51 GlobalErrorService* service = 51 GlobalErrorService* service =
52 GlobalErrorServiceFactory::GetForProfile(profile); 52 GlobalErrorServiceFactory::GetForProfile(profile);
53 return service->GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_ERRORS) != 53 return service->GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_ERRORS) !=
54 NULL; 54 NULL;
55 } 55 }
56 56
57 const char* ext1_id = "extension1"; 57 const char* ext1_id = "extension1";
58 const char* ext2_id = "extension2"; 58 const char* ext2_id = "extension2";
59 59
60 } // namespace 60 } // namespace
61 61
62 // Check that no badge appears if it has been suppressed for a specific 62 // Check that no badge appears if it has been suppressed for a specific
63 // warning. 63 // warning.
64 TEST(ExtensionWarningBadgeServiceTest, SuppressBadgeForCurrentWarnings) { 64 TEST(ExtensionWarningBadgeServiceTest, SuppressBadgeForCurrentWarnings) {
65 TestingProfile profile; 65 TestingProfile profile;
66 TestExtensionWarningSet warnings(&profile); 66 TestExtensionWarningSet warnings(&profile);
67 TestExtensionWarningBadgeService badge_service(&profile, &warnings); 67 TestExtensionWarningBadgeService badge_service(&profile, &warnings);
68 warnings.AddObserver(&badge_service); 68 warnings.AddObserver(&badge_service);
69 69
70 // Insert first warning. 70 // Insert first warning.
71 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id)); 71 warnings.AddWarning(Warning::CreateNetworkDelayWarning(ext1_id));
72 EXPECT_TRUE(HasBadge(&profile)); 72 EXPECT_TRUE(HasBadge(&profile));
73 73
74 // Suppress first warning. 74 // Suppress first warning.
75 badge_service.SuppressCurrentWarnings(); 75 badge_service.SuppressCurrentWarnings();
76 EXPECT_FALSE(HasBadge(&profile)); 76 EXPECT_FALSE(HasBadge(&profile));
77 77
78 // Simulate deinstallation of extension. 78 // Simulate deinstallation of extension.
79 std::set<ExtensionWarning::WarningType> to_clear = 79 std::set<Warning::WarningType> to_clear =
80 warnings.GetWarningTypesAffectingExtension(ext1_id); 80 warnings.GetWarningTypesAffectingExtension(ext1_id);
81 warnings.ClearWarnings(to_clear); 81 warnings.ClearWarnings(to_clear);
82 EXPECT_FALSE(HasBadge(&profile)); 82 EXPECT_FALSE(HasBadge(&profile));
83 83
84 // Set first warning again and verify that not badge is shown this time. 84 // Set first warning again and verify that not badge is shown this time.
85 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id)); 85 warnings.AddWarning(Warning::CreateNetworkDelayWarning(ext1_id));
86 EXPECT_FALSE(HasBadge(&profile)); 86 EXPECT_FALSE(HasBadge(&profile));
87 87
88 // Set second warning and verify that it shows a badge. 88 // Set second warning and verify that it shows a badge.
89 warnings.AddWarning(ExtensionWarning::CreateNetworkConflictWarning(ext2_id)); 89 warnings.AddWarning(Warning::CreateNetworkConflictWarning(ext2_id));
90 EXPECT_TRUE(HasBadge(&profile)); 90 EXPECT_TRUE(HasBadge(&profile));
91 91
92 warnings.RemoveObserver(&badge_service); 92 warnings.RemoveObserver(&badge_service);
93 } 93 }
94 94
95 } // namespace extensions 95 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_warning_badge_service.cc ('k') | chrome/browser/extensions/extension_warning_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698