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

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

Issue 10407105: Improve error messaging of webRequest API in case of conflicts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Store ExtensionWarnings as values in set rather than pointers Created 8 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 | Annotate | Revision Log
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_set.h" 5 #include "chrome/browser/extensions/extension_warning_set.h"
6 6
7 #include "chrome/browser/extensions/extension_global_error_badge.h" 7 #include "chrome/browser/extensions/extension_global_error_badge.h"
8 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/global_error/global_error_service.h" 9 #include "chrome/browser/ui/global_error/global_error_service.h"
9 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 10 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
10 #include "chrome/test/base/testing_profile.h" 11 #include "chrome/test/base/testing_profile.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
15 namespace extensions {
16
14 namespace { 17 namespace {
15 18
16 class MockExtensionWarningSet : public ExtensionWarningSet { 19 class MockExtensionWarningService : public ExtensionWarningService {
17 public: 20 public:
18 explicit MockExtensionWarningSet(Profile* profile) 21 explicit MockExtensionWarningService(Profile* profile)
19 : ExtensionWarningSet(profile) { 22 : ExtensionWarningService(profile) {
20 } 23 }
21 virtual ~MockExtensionWarningSet() {} 24 virtual ~MockExtensionWarningService() {}
25
26 void AddWarning(const ExtensionWarning& warning) {
27 ExtensionWarningSet warnings;
28 warnings.insert(warning);
29 AddWarnings(warnings);
30 }
22 31
23 MOCK_METHOD0(NotifyWarningsChanged, void()); 32 MOCK_METHOD0(NotifyWarningsChanged, void());
24 }; 33 };
25 34
26 bool HasBadge(Profile* profile) { 35 bool HasBadge(Profile* profile) {
27 GlobalErrorService* service = 36 GlobalErrorService* service =
28 GlobalErrorServiceFactory::GetForProfile(profile); 37 GlobalErrorServiceFactory::GetForProfile(profile);
29 return service->GetGlobalErrorByMenuItemCommandID( 38 return service->GetGlobalErrorByMenuItemCommandID(
30 ExtensionGlobalErrorBadge::GetMenuItemCommandID()) != NULL; 39 ExtensionGlobalErrorBadge::GetMenuItemCommandID()) != NULL;
31 } 40 }
32 41
33 const char* ext1_id = "extension1"; 42 const char* ext1_id = "extension1";
34 const char* ext2_id = "extension2"; 43 const char* ext2_id = "extension2";
35 const ExtensionWarningSet::WarningType warning_1 = 44 const ExtensionWarning::WarningType warning_1 =
36 ExtensionWarningSet::kNetworkDelay; 45 ExtensionWarning::kNetworkDelay;
37 const ExtensionWarningSet::WarningType warning_2 = 46 const ExtensionWarning::WarningType warning_2 =
38 ExtensionWarningSet::kNetworkConflict; 47 ExtensionWarning::kNetworkConflict;
39 48
40 } // namespace 49 } // namespace
41 50
42 // Check that inserting a warning triggers notifications, whereas inserting 51 // Check that inserting a warning triggers notifications, whereas inserting
43 // the same warning again is silent. 52 // the same warning again is silent.
44 TEST(ExtensionWarningSetTest, SetWarning) { 53 TEST(ExtensionWarningServiceTest, SetWarning) {
45 TestingProfile profile; 54 TestingProfile profile;
46 MockExtensionWarningSet warnings(&profile); 55 MockExtensionWarningService warnings(&profile);
47 56
48 // Insert warning for the first time. 57 // Insert warning for the first time.
49 EXPECT_CALL(warnings, NotifyWarningsChanged()); 58 EXPECT_CALL(warnings, NotifyWarningsChanged());
50 warnings.SetWarning(warning_1, ext1_id); 59 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id));
51 testing::Mock::VerifyAndClearExpectations(&warnings); 60 testing::Mock::VerifyAndClearExpectations(&warnings);
52 EXPECT_TRUE(HasBadge(&profile)); 61 EXPECT_TRUE(HasBadge(&profile));
53 62
54 // Second insertion of same warning does not trigger anything. 63 // Second insertion of same warning does not trigger anything.
55 warnings.SetWarning(warning_1, ext1_id); 64 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id));
56 testing::Mock::VerifyAndClearExpectations(&warnings); 65 testing::Mock::VerifyAndClearExpectations(&warnings);
57 } 66 }
58 67
59 // Check that ClearWarnings deletes exactly the specified warnings and 68 // Check that ClearWarnings deletes exactly the specified warnings and
60 // triggers notifications where appropriate. 69 // triggers notifications where appropriate.
61 TEST(ExtensionWarningSetTest, ClearWarnings) { 70 TEST(ExtensionWarningServiceTest, ClearWarnings) {
62 TestingProfile profile; 71 TestingProfile profile;
63 MockExtensionWarningSet warnings(&profile); 72 MockExtensionWarningService warnings(&profile);
64 73
65 // Insert two unique warnings. 74 // Insert two unique warnings in one batch.
66 EXPECT_CALL(warnings, NotifyWarningsChanged()).Times(2); 75 EXPECT_CALL(warnings, NotifyWarningsChanged()).Times(1);
67 warnings.SetWarning(warning_1, ext1_id); 76 ExtensionWarningSet warning_set;
68 warnings.SetWarning(warning_2, ext2_id); 77 warning_set.insert(ExtensionWarning::CreateNetworkDelayWarning(ext1_id));
78 warning_set.insert(ExtensionWarning::CreateNetworkConflictWarning(ext2_id));
79 warnings.AddWarnings(warning_set);
69 testing::Mock::VerifyAndClearExpectations(&warnings); 80 testing::Mock::VerifyAndClearExpectations(&warnings);
70 EXPECT_TRUE(HasBadge(&profile)); 81 EXPECT_TRUE(HasBadge(&profile));
71 82
72 // Remove one warning and check that the badge remains. 83 // Remove one warning and check that the badge remains.
73 EXPECT_CALL(warnings, NotifyWarningsChanged()); 84 EXPECT_CALL(warnings, NotifyWarningsChanged());
74 std::set<ExtensionWarningSet::WarningType> to_clear; 85 std::set<ExtensionWarning::WarningType> to_clear;
75 to_clear.insert(warning_2); 86 to_clear.insert(warning_2);
76 warnings.ClearWarnings(to_clear); 87 warnings.ClearWarnings(to_clear);
77 testing::Mock::VerifyAndClearExpectations(&warnings); 88 testing::Mock::VerifyAndClearExpectations(&warnings);
78 EXPECT_TRUE(HasBadge(&profile)); 89 EXPECT_TRUE(HasBadge(&profile));
79 90
80 // Check that the correct warnings appear in |warnings|. 91 // Check that the correct warnings appear in |warnings|.
81 std::set<ExtensionWarningSet::WarningType> existing_warnings; 92 std::set<ExtensionWarning::WarningType> existing_warnings;
82 warnings.GetWarningsAffectingExtension(ext1_id, &existing_warnings); 93 warnings.GetWarningTypesAffectingExtension(ext1_id, &existing_warnings);
83 EXPECT_EQ(1u, existing_warnings.size()); 94 EXPECT_EQ(1u, existing_warnings.size());
84 warnings.GetWarningsAffectingExtension(ext2_id, &existing_warnings); 95 warnings.GetWarningTypesAffectingExtension(ext2_id, &existing_warnings);
85 EXPECT_EQ(0u, existing_warnings.size()); 96 EXPECT_EQ(0u, existing_warnings.size());
86 97
87 // Remove the other one warning and check that badge disappears. 98 // Remove the other one warning and check that badge disappears.
88 EXPECT_CALL(warnings, NotifyWarningsChanged()); 99 EXPECT_CALL(warnings, NotifyWarningsChanged());
89 to_clear.insert(warning_1); 100 to_clear.insert(warning_1);
90 warnings.ClearWarnings(to_clear); 101 warnings.ClearWarnings(to_clear);
91 testing::Mock::VerifyAndClearExpectations(&warnings); 102 testing::Mock::VerifyAndClearExpectations(&warnings);
92 EXPECT_FALSE(HasBadge(&profile)); 103 EXPECT_FALSE(HasBadge(&profile));
93 104
94 // Check that not warnings remain. 105 // Check that not warnings remain.
95 warnings.GetWarningsAffectingExtension(ext1_id, &existing_warnings); 106 warnings.GetWarningTypesAffectingExtension(ext1_id, &existing_warnings);
96 EXPECT_EQ(0u, existing_warnings.size()); 107 EXPECT_EQ(0u, existing_warnings.size());
97 warnings.GetWarningsAffectingExtension(ext2_id, &existing_warnings); 108 warnings.GetWarningTypesAffectingExtension(ext2_id, &existing_warnings);
98 EXPECT_EQ(0u, existing_warnings.size()); 109 EXPECT_EQ(0u, existing_warnings.size());
99 } 110 }
100 111
101 // Check that no badge appears if it has been suppressed for a specific 112 // Check that no badge appears if it has been suppressed for a specific
102 // warning. 113 // warning.
103 TEST(ExtensionWarningSetTest, SuppressBadgeForCurrentWarnings) { 114 TEST(ExtensionWarningServiceTest, SuppressBadgeForCurrentWarnings) {
104 TestingProfile profile; 115 TestingProfile profile;
105 MockExtensionWarningSet warnings(&profile); 116 MockExtensionWarningService warnings(&profile);
106 117
107 // Insert first warning. 118 // Insert first warning.
108 EXPECT_CALL(warnings, NotifyWarningsChanged()); 119 EXPECT_CALL(warnings, NotifyWarningsChanged());
109 warnings.SetWarning(warning_1, ext1_id); 120 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id));
110 testing::Mock::VerifyAndClearExpectations(&warnings); 121 testing::Mock::VerifyAndClearExpectations(&warnings);
111 EXPECT_TRUE(HasBadge(&profile)); 122 EXPECT_TRUE(HasBadge(&profile));
112 123
113 // Suppress first warning. 124 // Suppress first warning.
114 warnings.SuppressBadgeForCurrentWarnings(); 125 warnings.SuppressBadgeForCurrentWarnings();
115 testing::Mock::VerifyAndClearExpectations(&warnings); 126 testing::Mock::VerifyAndClearExpectations(&warnings);
116 EXPECT_FALSE(HasBadge(&profile)); 127 EXPECT_FALSE(HasBadge(&profile));
117 128
118 // Simulate deinstallation of extension. 129 // Simulate deinstallation of extension.
119 std::set<ExtensionWarningSet::WarningType> to_clear; 130 std::set<ExtensionWarning::WarningType> to_clear;
120 warnings.GetWarningsAffectingExtension(ext1_id, &to_clear); 131 warnings.GetWarningTypesAffectingExtension(ext1_id, &to_clear);
121 EXPECT_CALL(warnings, NotifyWarningsChanged()); 132 EXPECT_CALL(warnings, NotifyWarningsChanged());
122 warnings.ClearWarnings(to_clear); 133 warnings.ClearWarnings(to_clear);
123 testing::Mock::VerifyAndClearExpectations(&warnings); 134 testing::Mock::VerifyAndClearExpectations(&warnings);
124 135
125 // Set first warning again and verify that not badge is shown this time. 136 // Set first warning again and verify that not badge is shown this time.
126 EXPECT_CALL(warnings, NotifyWarningsChanged()); 137 EXPECT_CALL(warnings, NotifyWarningsChanged());
127 warnings.SetWarning(warning_1, ext1_id); 138 warnings.AddWarning(ExtensionWarning::CreateNetworkDelayWarning(ext1_id));
128 testing::Mock::VerifyAndClearExpectations(&warnings); 139 testing::Mock::VerifyAndClearExpectations(&warnings);
129 EXPECT_FALSE(HasBadge(&profile)); 140 EXPECT_FALSE(HasBadge(&profile));
130 141
131 // Set second warning and verify that it shows a badge. 142 // Set second warning and verify that it shows a badge.
132 EXPECT_CALL(warnings, NotifyWarningsChanged()); 143 EXPECT_CALL(warnings, NotifyWarningsChanged());
133 warnings.SetWarning(warning_2, ext2_id); 144 warnings.AddWarning(ExtensionWarning::CreateNetworkConflictWarning(ext2_id));
134 testing::Mock::VerifyAndClearExpectations(&warnings); 145 testing::Mock::VerifyAndClearExpectations(&warnings);
135 EXPECT_TRUE(HasBadge(&profile)); 146 EXPECT_TRUE(HasBadge(&profile));
136 } 147 }
148
149 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698