| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_warning_badge_service.h" |
| 6 |
| 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/extensions/extension_warning_set.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 11 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace extensions { |
| 16 |
| 17 namespace { |
| 18 |
| 19 class TestExtensionWarningSet : public ExtensionWarningSet { |
| 20 public: |
| 21 explicit TestExtensionWarningSet(Profile* profile) |
| 22 : ExtensionWarningSet(profile) { |
| 23 } |
| 24 virtual ~TestExtensionWarningSet() {} |
| 25 |
| 26 void AddWarning(const ExtensionWarning& warning) { |
| 27 std::set<ExtensionWarning> warnings; |
| 28 warnings.insert(warning); |
| 29 AddWarnings(warnings); |
| 30 } |
| 31 }; |
| 32 |
| 33 class TestExtensionWarningBadgeService : public ExtensionWarningBadgeService { |
| 34 public: |
| 35 TestExtensionWarningBadgeService(Profile* profile, |
| 36 ExtensionWarningSet* warnings) |
| 37 : ExtensionWarningBadgeService(profile), warnings_(warnings) {} |
| 38 virtual ~TestExtensionWarningBadgeService() {} |
| 39 |
| 40 virtual const std::set<ExtensionWarning>& GetCurrentWarnings() const { |
| 41 return warnings_->warnings(); |
| 42 } |
| 43 |
| 44 private: |
| 45 ExtensionWarningSet* warnings_; |
| 46 }; |
| 47 |
| 48 bool HasBadge(Profile* profile) { |
| 49 GlobalErrorService* service = |
| 50 GlobalErrorServiceFactory::GetForProfile(profile); |
| 51 return service->GetGlobalErrorByMenuItemCommandID(IDC_EXTENSION_ERRORS) != |
| 52 NULL; |
| 53 } |
| 54 |
| 55 const char* ext1_id = "extension1"; |
| 56 const char* ext2_id = "extension2"; |
| 57 const ExtensionWarning::WarningType warning_1 = |
| 58 ExtensionWarning::kNetworkDelay; |
| 59 const ExtensionWarning::WarningType warning_2 = |
| 60 ExtensionWarning::kNetworkConflict; |
| 61 |
| 62 } // namespace |
| 63 |
| 64 // Check that no badge appears if it has been suppressed for a specific |
| 65 // warning. |
| 66 TEST(ExtensionWarningBadgeServiceTest, SuppressBadgeForCurrentWarnings) { |
| 67 TestingProfile profile; |
| 68 TestExtensionWarningSet warnings(&profile); |
| 69 TestExtensionWarningBadgeService badge_service(&profile, &warnings); |
| 70 warnings.AddObserver(&badge_service); |
| 71 |
| 72 // Insert first warning. |
| 73 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id)); |
| 74 EXPECT_TRUE(HasBadge(&profile)); |
| 75 |
| 76 // Suppress first warning. |
| 77 badge_service.SuppressCurrentWarnings(); |
| 78 EXPECT_FALSE(HasBadge(&profile)); |
| 79 |
| 80 // Simulate deinstallation of extension. |
| 81 std::set<ExtensionWarning::WarningType> to_clear; |
| 82 warnings.GetWarningTypesAffectingExtension(ext1_id, &to_clear); |
| 83 warnings.ClearWarnings(to_clear); |
| 84 EXPECT_FALSE(HasBadge(&profile)); |
| 85 |
| 86 // Set first warning again and verify that not badge is shown this time. |
| 87 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id)); |
| 88 EXPECT_FALSE(HasBadge(&profile)); |
| 89 |
| 90 // Set second warning and verify that it shows a badge. |
| 91 warnings.AddWarning(ExtensionWarning::CreateNetworkConflictWarning(ext2_id)); |
| 92 EXPECT_TRUE(HasBadge(&profile)); |
| 93 |
| 94 warnings.RemoveObserver(&badge_service); |
| 95 } |
| 96 |
| 97 } // namespace extensions |
| OLD | NEW |