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

Side by Side Diff: chrome/browser/protector/protector_service_browsertest.cc

Issue 9500020: ProtectorService supports multiple change instances. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 8 years, 9 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/protector/mock_setting_change.h" 8 #include "chrome/browser/protector/mock_setting_change.h"
9 #include "chrome/browser/protector/protector_service.h" 9 #include "chrome/browser/protector/protector_service.h"
10 #include "chrome/browser/protector/protector_service_factory.h" 10 #include "chrome/browser/protector/protector_service_factory.h"
(...skipping 15 matching lines...) Expand all
26 class ProtectorServiceTest : public InProcessBrowserTest { 26 class ProtectorServiceTest : public InProcessBrowserTest {
27 public: 27 public:
28 virtual void SetUpOnMainThread() { 28 virtual void SetUpOnMainThread() {
29 protector_service_ = 29 protector_service_ =
30 ProtectorServiceFactory::GetForProfile(browser()->profile()); 30 ProtectorServiceFactory::GetForProfile(browser()->profile());
31 // ProtectService will own this change instance. 31 // ProtectService will own this change instance.
32 mock_change_ = new NiceMock<MockSettingChange>(); 32 mock_change_ = new NiceMock<MockSettingChange>();
33 } 33 }
34 34
35 protected: 35 protected:
36 GlobalError* GetGlobalError() { 36 GlobalError* GetGlobalError(BaseSettingChange* change) {
37 return protector_service_->error_.get(); 37 std::vector<ProtectorService::Item>::iterator item =
38 std::find_if(protector_service_->items_.begin(),
39 protector_service_->items_.end(),
40 ProtectorService::MatchItemByChange(change));
41 return item == protector_service_->items_.end() ?
42 NULL : item->error.get();
38 } 43 }
39 44
40 void ExpectGlobalErrorActive(bool active) { 45 // Checks that |protector_service_| has an error instance corresponding to
41 GlobalError* error = 46 // |change| and that GlobalErrorService knows about it.
42 GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> 47 bool IsGlobalErrorActive(BaseSettingChange* change) {
43 GetGlobalErrorByMenuItemCommandID(IDC_SHOW_SETTINGS_CHANGES); 48 GlobalError* error = GetGlobalError(change);
44 EXPECT_EQ(active, error != NULL); 49 if (!error)
45 EXPECT_EQ(active, GetGlobalError() != NULL); 50 return false;
46 EXPECT_EQ(active, protector_service_->IsShowingChange()); 51 if (!GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
52 GetGlobalErrorByMenuItemCommandID(error->MenuItemCommandID())) {
53 return false;
54 }
55 return protector_service_->IsShowingChange();
47 } 56 }
48 57
49 ProtectorService* protector_service_; 58 ProtectorService* protector_service_;
50 MockSettingChange* mock_change_; 59 MockSettingChange* mock_change_;
51 }; 60 };
52 61
53 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) { 62 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) {
54 // Init fails and causes the change to be ignored. 63 // Init fails and causes the change to be ignored.
55 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 64 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
56 WillOnce(Return(false)); 65 WillOnce(Return(false));
57 protector_service_->ShowChange(mock_change_); 66 protector_service_->ShowChange(mock_change_);
58 ExpectGlobalErrorActive(false); 67 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
59 ui_test_utils::RunAllPendingInMessageLoop(); 68 ui_test_utils::RunAllPendingInMessageLoop();
60 ExpectGlobalErrorActive(false); 69 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
61 } 70 }
62 71
63 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) { 72 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
64 // Show the change and immediately dismiss it. 73 // Show the change and immediately dismiss it.
65 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 74 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
66 WillOnce(Return(true)); 75 WillOnce(Return(true));
67 protector_service_->ShowChange(mock_change_); 76 protector_service_->ShowChange(mock_change_);
68 ui_test_utils::RunAllPendingInMessageLoop(); 77 ui_test_utils::RunAllPendingInMessageLoop();
69 ExpectGlobalErrorActive(true); 78 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
70 protector_service_->DismissChange(); 79 protector_service_->DismissChange(mock_change_);
71 ui_test_utils::RunAllPendingInMessageLoop(); 80 ui_test_utils::RunAllPendingInMessageLoop();
72 ExpectGlobalErrorActive(false); 81 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
73 } 82 }
74 83
75 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) { 84 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) {
76 // Show the change and apply it. 85 // Show the change and apply it.
77 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 86 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
78 WillOnce(Return(true)); 87 WillOnce(Return(true));
79 protector_service_->ShowChange(mock_change_); 88 protector_service_->ShowChange(mock_change_);
80 ui_test_utils::RunAllPendingInMessageLoop(); 89 ui_test_utils::RunAllPendingInMessageLoop();
81 ExpectGlobalErrorActive(true); 90 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
82 EXPECT_CALL(*mock_change_, Apply(browser())); 91 EXPECT_CALL(*mock_change_, Apply(browser()));
83 protector_service_->ApplyChange(browser()); 92 protector_service_->ApplyChange(mock_change_, browser());
84 ui_test_utils::RunAllPendingInMessageLoop(); 93 ui_test_utils::RunAllPendingInMessageLoop();
85 ExpectGlobalErrorActive(false); 94 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
86 } 95 }
87 96
88 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApplyManually) { 97 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApplyManually) {
89 // Show the change and apply it, mimicking a button click. 98 // Show the change and apply it, mimicking a button click.
90 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 99 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
91 WillOnce(Return(true)); 100 WillOnce(Return(true));
92 protector_service_->ShowChange(mock_change_); 101 protector_service_->ShowChange(mock_change_);
93 ui_test_utils::RunAllPendingInMessageLoop(); 102 ui_test_utils::RunAllPendingInMessageLoop();
94 ExpectGlobalErrorActive(true); 103 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
95 EXPECT_CALL(*mock_change_, Apply(browser())); 104 EXPECT_CALL(*mock_change_, Apply(browser()));
96 // Pressing Cancel applies the change. 105 // Pressing Cancel applies the change.
97 GlobalError* error = GetGlobalError(); 106 GlobalError* error = GetGlobalError(mock_change_);
107 ASSERT_TRUE(error);
98 error->BubbleViewCancelButtonPressed(browser()); 108 error->BubbleViewCancelButtonPressed(browser());
99 error->GetBubbleView()->CloseBubbleView(); 109 error->GetBubbleView()->CloseBubbleView();
100 ui_test_utils::RunAllPendingInMessageLoop(); 110 ui_test_utils::RunAllPendingInMessageLoop();
101 ExpectGlobalErrorActive(false); 111 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
102 } 112 }
103 113
104 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) { 114 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) {
105 // Show the change and discard it. 115 // Show the change and discard it.
106 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 116 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
107 WillOnce(Return(true)); 117 WillOnce(Return(true));
108 protector_service_->ShowChange(mock_change_); 118 protector_service_->ShowChange(mock_change_);
109 ui_test_utils::RunAllPendingInMessageLoop(); 119 ui_test_utils::RunAllPendingInMessageLoop();
110 ExpectGlobalErrorActive(true); 120 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
111 EXPECT_CALL(*mock_change_, Discard(browser())); 121 EXPECT_CALL(*mock_change_, Discard(browser()));
112 protector_service_->DiscardChange(browser()); 122 protector_service_->DiscardChange(mock_change_, browser());
113 ui_test_utils::RunAllPendingInMessageLoop(); 123 ui_test_utils::RunAllPendingInMessageLoop();
114 ExpectGlobalErrorActive(false); 124 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
115 } 125 }
116 126
117 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscardManually) { 127 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscardManually) {
118 // Show the change and discard it, mimicking a button click. 128 // Show the change and discard it, mimicking a button click.
119 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 129 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
120 WillOnce(Return(true)); 130 WillOnce(Return(true));
121 protector_service_->ShowChange(mock_change_); 131 protector_service_->ShowChange(mock_change_);
122 ui_test_utils::RunAllPendingInMessageLoop(); 132 ui_test_utils::RunAllPendingInMessageLoop();
123 ExpectGlobalErrorActive(true); 133 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
124 EXPECT_CALL(*mock_change_, Discard(browser())); 134 EXPECT_CALL(*mock_change_, Discard(browser()));
125 // Pressing Apply discards the change. 135 // Pressing Apply discards the change.
126 GlobalError* error = GetGlobalError(); 136 GlobalError* error = GetGlobalError(mock_change_);
137 ASSERT_TRUE(error);
127 error->BubbleViewAcceptButtonPressed(browser()); 138 error->BubbleViewAcceptButtonPressed(browser());
128 error->GetBubbleView()->CloseBubbleView(); 139 error->GetBubbleView()->CloseBubbleView();
129 ui_test_utils::RunAllPendingInMessageLoop(); 140 ui_test_utils::RunAllPendingInMessageLoop();
130 ExpectGlobalErrorActive(false); 141 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
131 } 142 }
132 143
133 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) { 144 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) {
134 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 145 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
135 WillOnce(Return(true)); 146 WillOnce(Return(true));
136 protector_service_->ShowChange(mock_change_); 147 protector_service_->ShowChange(mock_change_);
137 ui_test_utils::RunAllPendingInMessageLoop(); 148 ui_test_utils::RunAllPendingInMessageLoop();
138 ExpectGlobalErrorActive(true); 149 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
139 150
140 GlobalError* error = GetGlobalError(); 151 GlobalError* error = GetGlobalError(mock_change_);
152 ASSERT_TRUE(error);
141 GlobalErrorBubbleViewBase* bubble_view = error->GetBubbleView(); 153 GlobalErrorBubbleViewBase* bubble_view = error->GetBubbleView();
142 EXPECT_TRUE(bubble_view); 154 ASSERT_TRUE(bubble_view);
143 EXPECT_CALL(*mock_change_, Apply(browser())).WillOnce(InvokeWithoutArgs( 155 EXPECT_CALL(*mock_change_, Apply(browser())).WillOnce(InvokeWithoutArgs(
144 bubble_view, &GlobalErrorBubbleViewBase::CloseBubbleView)); 156 bubble_view, &GlobalErrorBubbleViewBase::CloseBubbleView));
145 157
146 // Pressing Cancel applies the change. 158 // Pressing Cancel applies the change.
147 error->BubbleViewCancelButtonPressed(browser()); 159 error->BubbleViewCancelButtonPressed(browser());
148 ui_test_utils::RunAllPendingInMessageLoop(); 160 ui_test_utils::RunAllPendingInMessageLoop();
149 ExpectGlobalErrorActive(false); 161 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
162 }
163
164 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) {
165 // Show the first change.
166 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
167 WillOnce(Return(true));
168 protector_service_->ShowChange(mock_change_);
169 ui_test_utils::RunAllPendingInMessageLoop();
170 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
171
172 // ProtectService will own this change instance as well.
173 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
174 // Show the second change.
175 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
176 WillOnce(Return(true));
177 protector_service_->ShowChange(mock_change2);
178 ui_test_utils::RunAllPendingInMessageLoop();
179 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
180 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
181
182 // Apply the first change, the second should still be active.
183 EXPECT_CALL(*mock_change_, Apply(browser()));
184 protector_service_->ApplyChange(mock_change_, browser());
185 ui_test_utils::RunAllPendingInMessageLoop();
186 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
187 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
188
189 // Finally apply the second change.
190 EXPECT_CALL(*mock_change2, Apply(browser()));
191 protector_service_->ApplyChange(mock_change2, browser());
192 ui_test_utils::RunAllPendingInMessageLoop();
193 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
194 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
195 }
196
197 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
198 ShowMultipleChangesDismissAndApply) {
199 // Show the first change.
200 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
201 WillOnce(Return(true));
202 protector_service_->ShowChange(mock_change_);
203 ui_test_utils::RunAllPendingInMessageLoop();
204 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
205
206 // ProtectService will own this change instance as well.
207 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
208 // Show the second change.
209 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
210 WillOnce(Return(true));
211 protector_service_->ShowChange(mock_change2);
212 ui_test_utils::RunAllPendingInMessageLoop();
213 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
214 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
215
216 // Dismiss the first change, the second should still be active.
217 protector_service_->DismissChange(mock_change_);
218 ui_test_utils::RunAllPendingInMessageLoop();
219 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
220 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
221
222 // Finally apply the second change.
223 EXPECT_CALL(*mock_change2, Apply(browser()));
224 protector_service_->ApplyChange(mock_change2, browser());
225 ui_test_utils::RunAllPendingInMessageLoop();
226 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
227 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
228 }
229
230 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
231 ShowMultipleChangesAndApplyManually) {
232 // Show the first change.
233 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
234 WillOnce(Return(true));
235 protector_service_->ShowChange(mock_change_);
236 ui_test_utils::RunAllPendingInMessageLoop();
237 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
238
239 // ProtectService will own this change instance as well.
240 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
241 // Show the second change.
242 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
243 WillOnce(Return(true));
244 protector_service_->ShowChange(mock_change2);
245 ui_test_utils::RunAllPendingInMessageLoop();
246 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
247 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
248
249 // Apply the first change, mimicking a button click; the second should still
250 // be active.
251 EXPECT_CALL(*mock_change_, Apply(browser()));
252 GlobalError* error = GetGlobalError(mock_change_);
253 ASSERT_TRUE(error);
254 error->ShowBubbleView(browser());
255 error->BubbleViewCancelButtonPressed(browser());
256 error->GetBubbleView()->CloseBubbleView();
257 ui_test_utils::RunAllPendingInMessageLoop();
258 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
259 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
260
261 // Finally apply the second change.
262 EXPECT_CALL(*mock_change2, Apply(browser()));
263 GlobalError* error2 = GetGlobalError(mock_change2);
264 ASSERT_TRUE(error);
265 error2->ShowBubbleView(browser());
266 error2->BubbleViewCancelButtonPressed(browser());
267 error2->GetBubbleView()->CloseBubbleView();
268 ui_test_utils::RunAllPendingInMessageLoop();
269 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
270 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
150 } 271 }
151 272
152 // TODO(ivankr): Timeout test. 273 // TODO(ivankr): Timeout test.
153 274
154 } // namespace protector 275 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/protector_service.cc ('k') | chrome/browser/protector/settings_change_global_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698