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

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: Rename. 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_set.h"
James Cook 2014/08/26 22:01:31 nit: #include warning_service.h also
Xi Han 2014/08/27 13:32:54 Done.
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace extensions { 15 namespace extensions {
16 16
17 namespace { 17 namespace {
18 18
19 class TestExtensionWarningSet : public ExtensionWarningService { 19 class TestExtensionWarningSet : public WarningService {
20 public: 20 public:
21 explicit TestExtensionWarningSet(Profile* profile) 21 explicit TestExtensionWarningSet(Profile* profile) : WarningService(profile) {
22 : ExtensionWarningService(profile) {
23 } 22 }
24 virtual ~TestExtensionWarningSet() {} 23 virtual ~TestExtensionWarningSet() {}
25 24
26 void AddWarning(const ExtensionWarning& warning) { 25 void AddWarning(const Warning& warning) {
27 ExtensionWarningSet warnings; 26 WarningSet warnings;
28 warnings.insert(warning); 27 warnings.insert(warning);
29 AddWarnings(warnings); 28 AddWarnings(warnings);
30 } 29 }
31 }; 30 };
32 31
33 class TestExtensionWarningBadgeService : public ExtensionWarningBadgeService { 32 class TestExtensionWarningBadgeService : public ExtensionWarningBadgeService {
34 public: 33 public:
35 TestExtensionWarningBadgeService(Profile* profile, 34 TestExtensionWarningBadgeService(Profile* profile,
36 ExtensionWarningService* warning_service) 35 WarningService* warning_service)
37 : ExtensionWarningBadgeService(profile), 36 : ExtensionWarningBadgeService(profile),
38 warning_service_(warning_service) {} 37 warning_service_(warning_service) {}
39 virtual ~TestExtensionWarningBadgeService() {} 38 virtual ~TestExtensionWarningBadgeService() {}
40 39
41 virtual const std::set<ExtensionWarning>& 40 virtual const std::set<Warning>&
42 GetCurrentWarnings() const OVERRIDE { 41 GetCurrentWarnings() const OVERRIDE {
43 return warning_service_->warnings(); 42 return warning_service_->warnings();
44 } 43 }
45 44
46 private: 45 private:
47 ExtensionWarningService* warning_service_; 46 WarningService* warning_service_;
48 }; 47 };
49 48
50 bool HasBadge(Profile* profile) { 49 bool HasBadge(Profile* profile) {
51 GlobalErrorService* service = 50 GlobalErrorService* service =
52 GlobalErrorServiceFactory::GetForProfile(profile); 51 GlobalErrorServiceFactory::GetForProfile(profile);
53 return service->GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_ERRORS) != 52 return service->GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_ERRORS) !=
54 NULL; 53 NULL;
55 } 54 }
56 55
57 const char* ext1_id = "extension1"; 56 const char* ext1_id = "extension1";
58 const char* ext2_id = "extension2"; 57 const char* ext2_id = "extension2";
59 58
60 } // namespace 59 } // namespace
61 60
62 // Check that no badge appears if it has been suppressed for a specific 61 // Check that no badge appears if it has been suppressed for a specific
63 // warning. 62 // warning.
64 TEST(ExtensionWarningBadgeServiceTest, SuppressBadgeForCurrentWarnings) { 63 TEST(ExtensionWarningBadgeServiceTest, SuppressBadgeForCurrentWarnings) {
65 TestingProfile profile; 64 TestingProfile profile;
66 TestExtensionWarningSet warnings(&profile); 65 TestExtensionWarningSet warnings(&profile);
67 TestExtensionWarningBadgeService badge_service(&profile, &warnings); 66 TestExtensionWarningBadgeService badge_service(&profile, &warnings);
68 warnings.AddObserver(&badge_service); 67 warnings.AddObserver(&badge_service);
69 68
70 // Insert first warning. 69 // Insert first warning.
71 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id)); 70 warnings.AddWarning(Warning::CreateNetworkDelayWarning(ext1_id));
72 EXPECT_TRUE(HasBadge(&profile)); 71 EXPECT_TRUE(HasBadge(&profile));
73 72
74 // Suppress first warning. 73 // Suppress first warning.
75 badge_service.SuppressCurrentWarnings(); 74 badge_service.SuppressCurrentWarnings();
76 EXPECT_FALSE(HasBadge(&profile)); 75 EXPECT_FALSE(HasBadge(&profile));
77 76
78 // Simulate deinstallation of extension. 77 // Simulate deinstallation of extension.
79 std::set<ExtensionWarning::WarningType> to_clear = 78 std::set<Warning::WarningType> to_clear =
80 warnings.GetWarningTypesAffectingExtension(ext1_id); 79 warnings.GetWarningTypesAffectingExtension(ext1_id);
81 warnings.ClearWarnings(to_clear); 80 warnings.ClearWarnings(to_clear);
82 EXPECT_FALSE(HasBadge(&profile)); 81 EXPECT_FALSE(HasBadge(&profile));
83 82
84 // Set first warning again and verify that not badge is shown this time. 83 // Set first warning again and verify that not badge is shown this time.
85 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id)); 84 warnings.AddWarning(Warning::CreateNetworkDelayWarning(ext1_id));
86 EXPECT_FALSE(HasBadge(&profile)); 85 EXPECT_FALSE(HasBadge(&profile));
87 86
88 // Set second warning and verify that it shows a badge. 87 // Set second warning and verify that it shows a badge.
89 warnings.AddWarning(ExtensionWarning::CreateNetworkConflictWarning(ext2_id)); 88 warnings.AddWarning(Warning::CreateNetworkConflictWarning(ext2_id));
90 EXPECT_TRUE(HasBadge(&profile)); 89 EXPECT_TRUE(HasBadge(&profile));
91 90
92 warnings.RemoveObserver(&badge_service); 91 warnings.RemoveObserver(&badge_service);
93 } 92 }
94 93
95 } // namespace extensions 94 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698