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

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

Issue 10825085: Move RunAllPendingInMessageLoop from ui_test_utils.h to test_utils.h, so that it can be reused by c… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/protector/mock_setting_change.h" 9 #include "chrome/browser/protector/mock_setting_change.h"
10 #include "chrome/browser/protector/protector_service.h" 10 #include "chrome/browser/protector/protector_service.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 ProtectorService* protector_service_; 66 ProtectorService* protector_service_;
67 MockSettingChange* mock_change_; 67 MockSettingChange* mock_change_;
68 }; 68 };
69 69
70 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) { 70 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) {
71 // Init fails and causes the change to be ignored. 71 // Init fails and causes the change to be ignored.
72 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 72 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
73 WillOnce(Return(false)); 73 WillOnce(Return(false));
74 protector_service_->ShowChange(mock_change_); 74 protector_service_->ShowChange(mock_change_);
75 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 75 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
76 ui_test_utils::RunAllPendingInMessageLoop(); 76 content::RunAllPendingInMessageLoop();
77 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 77 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
78 EXPECT_FALSE(protector_service_->GetLastChange()); 78 EXPECT_FALSE(protector_service_->GetLastChange());
79 } 79 }
80 80
81 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) { 81 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
82 // Show the change and immediately dismiss it. 82 // Show the change and immediately dismiss it.
83 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 83 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
84 WillOnce(Return(true)); 84 WillOnce(Return(true));
85 protector_service_->ShowChange(mock_change_); 85 protector_service_->ShowChange(mock_change_);
86 ui_test_utils::RunAllPendingInMessageLoop(); 86 content::RunAllPendingInMessageLoop();
87 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 87 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
88 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); 88 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
89 protector_service_->DismissChange(mock_change_); 89 protector_service_->DismissChange(mock_change_);
90 ui_test_utils::RunAllPendingInMessageLoop(); 90 content::RunAllPendingInMessageLoop();
91 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 91 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
92 EXPECT_FALSE(protector_service_->GetLastChange()); 92 EXPECT_FALSE(protector_service_->GetLastChange());
93 } 93 }
94 94
95 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) { 95 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) {
96 // Show the change and apply it. 96 // Show the change and apply it.
97 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 97 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
98 WillOnce(Return(true)); 98 WillOnce(Return(true));
99 protector_service_->ShowChange(mock_change_); 99 protector_service_->ShowChange(mock_change_);
100 ui_test_utils::RunAllPendingInMessageLoop(); 100 content::RunAllPendingInMessageLoop();
101 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 101 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
102 EXPECT_CALL(*mock_change_, Apply(browser())); 102 EXPECT_CALL(*mock_change_, Apply(browser()));
103 protector_service_->ApplyChange(mock_change_, browser()); 103 protector_service_->ApplyChange(mock_change_, browser());
104 ui_test_utils::RunAllPendingInMessageLoop(); 104 content::RunAllPendingInMessageLoop();
105 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 105 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
106 } 106 }
107 107
108 // ProtectorServiceTest.ShowAndApplyManually is timing out frequently on Win 108 // ProtectorServiceTest.ShowAndApplyManually is timing out frequently on Win
109 // bots. http://crbug.com/130590 109 // bots. http://crbug.com/130590
110 #if defined(OS_WIN) 110 #if defined(OS_WIN)
111 #define MAYBE_ShowAndApplyManually DISABLED_ShowAndApplyManually 111 #define MAYBE_ShowAndApplyManually DISABLED_ShowAndApplyManually
112 #else 112 #else
113 #define MAYBE_ShowAndApplyManually ShowAndApplyManually 113 #define MAYBE_ShowAndApplyManually ShowAndApplyManually
114 #endif 114 #endif
115 115
116 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, MAYBE_ShowAndApplyManually) { 116 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, MAYBE_ShowAndApplyManually) {
117 // Show the change and apply it, mimicking a button click. 117 // Show the change and apply it, mimicking a button click.
118 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 118 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
119 WillOnce(Return(true)); 119 WillOnce(Return(true));
120 protector_service_->ShowChange(mock_change_); 120 protector_service_->ShowChange(mock_change_);
121 ui_test_utils::RunAllPendingInMessageLoop(); 121 content::RunAllPendingInMessageLoop();
122 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 122 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
123 EXPECT_CALL(*mock_change_, Apply(browser())); 123 EXPECT_CALL(*mock_change_, Apply(browser()));
124 // Pressing Cancel applies the change. 124 // Pressing Cancel applies the change.
125 GlobalError* error = GetGlobalError(mock_change_); 125 GlobalError* error = GetGlobalError(mock_change_);
126 ASSERT_TRUE(error); 126 ASSERT_TRUE(error);
127 error->BubbleViewCancelButtonPressed(browser()); 127 error->BubbleViewCancelButtonPressed(browser());
128 error->GetBubbleView()->CloseBubbleView(); 128 error->GetBubbleView()->CloseBubbleView();
129 ui_test_utils::RunAllPendingInMessageLoop(); 129 content::RunAllPendingInMessageLoop();
130 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 130 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
131 } 131 }
132 132
133 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) { 133 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscard) {
134 // Show the change and discard it. 134 // Show the change and discard it.
135 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 135 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
136 WillOnce(Return(true)); 136 WillOnce(Return(true));
137 protector_service_->ShowChange(mock_change_); 137 protector_service_->ShowChange(mock_change_);
138 ui_test_utils::RunAllPendingInMessageLoop(); 138 content::RunAllPendingInMessageLoop();
139 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 139 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
140 EXPECT_CALL(*mock_change_, Discard(browser())); 140 EXPECT_CALL(*mock_change_, Discard(browser()));
141 protector_service_->DiscardChange(mock_change_, browser()); 141 protector_service_->DiscardChange(mock_change_, browser());
142 ui_test_utils::RunAllPendingInMessageLoop(); 142 content::RunAllPendingInMessageLoop();
143 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 143 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
144 } 144 }
145 145
146 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscardManually) { 146 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDiscardManually) {
147 // Show the change and discard it, mimicking a button click. 147 // Show the change and discard it, mimicking a button click.
148 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 148 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
149 WillOnce(Return(true)); 149 WillOnce(Return(true));
150 protector_service_->ShowChange(mock_change_); 150 protector_service_->ShowChange(mock_change_);
151 ui_test_utils::RunAllPendingInMessageLoop(); 151 content::RunAllPendingInMessageLoop();
152 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 152 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
153 EXPECT_CALL(*mock_change_, Discard(browser())); 153 EXPECT_CALL(*mock_change_, Discard(browser()));
154 // Pressing Apply discards the change. 154 // Pressing Apply discards the change.
155 GlobalError* error = GetGlobalError(mock_change_); 155 GlobalError* error = GetGlobalError(mock_change_);
156 ASSERT_TRUE(error); 156 ASSERT_TRUE(error);
157 error->BubbleViewAcceptButtonPressed(browser()); 157 error->BubbleViewAcceptButtonPressed(browser());
158 error->GetBubbleView()->CloseBubbleView(); 158 error->GetBubbleView()->CloseBubbleView();
159 ui_test_utils::RunAllPendingInMessageLoop(); 159 content::RunAllPendingInMessageLoop();
160 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 160 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
161 } 161 }
162 162
163 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) { 163 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, BubbleClosedInsideApply) {
164 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 164 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
165 WillOnce(Return(true)); 165 WillOnce(Return(true));
166 protector_service_->ShowChange(mock_change_); 166 protector_service_->ShowChange(mock_change_);
167 ui_test_utils::RunAllPendingInMessageLoop(); 167 content::RunAllPendingInMessageLoop();
168 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 168 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
169 169
170 GlobalError* error = GetGlobalError(mock_change_); 170 GlobalError* error = GetGlobalError(mock_change_);
171 ASSERT_TRUE(error); 171 ASSERT_TRUE(error);
172 GlobalErrorBubbleViewBase* bubble_view = error->GetBubbleView(); 172 GlobalErrorBubbleViewBase* bubble_view = error->GetBubbleView();
173 ASSERT_TRUE(bubble_view); 173 ASSERT_TRUE(bubble_view);
174 EXPECT_CALL(*mock_change_, Apply(browser())).WillOnce(InvokeWithoutArgs( 174 EXPECT_CALL(*mock_change_, Apply(browser())).WillOnce(InvokeWithoutArgs(
175 bubble_view, &GlobalErrorBubbleViewBase::CloseBubbleView)); 175 bubble_view, &GlobalErrorBubbleViewBase::CloseBubbleView));
176 // Pressing Cancel applies the change. 176 // Pressing Cancel applies the change.
177 error->BubbleViewCancelButtonPressed(browser()); 177 error->BubbleViewCancelButtonPressed(browser());
178 ui_test_utils::RunAllPendingInMessageLoop(); 178 content::RunAllPendingInMessageLoop();
179 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 179 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
180 } 180 }
181 181
182 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) { 182 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) {
183 // Show the first change. 183 // Show the first change.
184 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 184 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
185 WillOnce(Return(true)); 185 WillOnce(Return(true));
186 protector_service_->ShowChange(mock_change_); 186 protector_service_->ShowChange(mock_change_);
187 ui_test_utils::RunAllPendingInMessageLoop(); 187 content::RunAllPendingInMessageLoop();
188 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 188 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
189 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); 189 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
190 190
191 // ProtectService will own this change instance as well. 191 // ProtectService will own this change instance as well.
192 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 192 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
193 // Show the second change. 193 // Show the second change.
194 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 194 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
195 WillOnce(Return(true)); 195 WillOnce(Return(true));
196 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false)); 196 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
197 protector_service_->ShowChange(mock_change2); 197 protector_service_->ShowChange(mock_change2);
198 ui_test_utils::RunAllPendingInMessageLoop(); 198 content::RunAllPendingInMessageLoop();
199 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 199 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
200 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 200 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
201 EXPECT_EQ(mock_change2, protector_service_->GetLastChange()); 201 EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
202 202
203 // Apply the first change, the second should still be active. 203 // Apply the first change, the second should still be active.
204 EXPECT_CALL(*mock_change_, Apply(browser())); 204 EXPECT_CALL(*mock_change_, Apply(browser()));
205 protector_service_->ApplyChange(mock_change_, browser()); 205 protector_service_->ApplyChange(mock_change_, browser());
206 ui_test_utils::RunAllPendingInMessageLoop(); 206 content::RunAllPendingInMessageLoop();
207 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 207 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
208 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 208 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
209 EXPECT_EQ(mock_change2, protector_service_->GetLastChange()); 209 EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
210 210
211 // Finally apply the second change. 211 // Finally apply the second change.
212 EXPECT_CALL(*mock_change2, Apply(browser())); 212 EXPECT_CALL(*mock_change2, Apply(browser()));
213 protector_service_->ApplyChange(mock_change2, browser()); 213 protector_service_->ApplyChange(mock_change2, browser());
214 ui_test_utils::RunAllPendingInMessageLoop(); 214 content::RunAllPendingInMessageLoop();
215 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 215 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
216 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 216 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
217 EXPECT_FALSE(protector_service_->GetLastChange()); 217 EXPECT_FALSE(protector_service_->GetLastChange());
218 } 218 }
219 219
220 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, 220 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
221 ShowMultipleChangesDismissAndApply) { 221 ShowMultipleChangesDismissAndApply) {
222 // Show the first change. 222 // Show the first change.
223 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 223 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
224 WillOnce(Return(true)); 224 WillOnce(Return(true));
225 protector_service_->ShowChange(mock_change_); 225 protector_service_->ShowChange(mock_change_);
226 ui_test_utils::RunAllPendingInMessageLoop(); 226 content::RunAllPendingInMessageLoop();
227 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 227 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
228 228
229 // ProtectService will own this change instance as well. 229 // ProtectService will own this change instance as well.
230 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 230 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
231 // Show the second change. 231 // Show the second change.
232 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 232 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
233 WillOnce(Return(true)); 233 WillOnce(Return(true));
234 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false)); 234 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
235 protector_service_->ShowChange(mock_change2); 235 protector_service_->ShowChange(mock_change2);
236 ui_test_utils::RunAllPendingInMessageLoop(); 236 content::RunAllPendingInMessageLoop();
237 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 237 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
238 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 238 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
239 239
240 // Dismiss the first change, the second should still be active. 240 // Dismiss the first change, the second should still be active.
241 protector_service_->DismissChange(mock_change_); 241 protector_service_->DismissChange(mock_change_);
242 ui_test_utils::RunAllPendingInMessageLoop(); 242 content::RunAllPendingInMessageLoop();
243 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 243 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
244 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 244 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
245 245
246 // Finally apply the second change. 246 // Finally apply the second change.
247 EXPECT_CALL(*mock_change2, Apply(browser())); 247 EXPECT_CALL(*mock_change2, Apply(browser()));
248 protector_service_->ApplyChange(mock_change2, browser()); 248 protector_service_->ApplyChange(mock_change2, browser());
249 ui_test_utils::RunAllPendingInMessageLoop(); 249 content::RunAllPendingInMessageLoop();
250 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 250 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
251 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 251 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
252 } 252 }
253 253
254 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, 254 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
255 ShowMultipleChangesAndApplyManually) { 255 ShowMultipleChangesAndApplyManually) {
256 // Show the first change. 256 // Show the first change.
257 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 257 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
258 WillOnce(Return(true)); 258 WillOnce(Return(true));
259 protector_service_->ShowChange(mock_change_); 259 protector_service_->ShowChange(mock_change_);
260 ui_test_utils::RunAllPendingInMessageLoop(); 260 content::RunAllPendingInMessageLoop();
261 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 261 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
262 262
263 // The first bubble view has been displayed. 263 // The first bubble view has been displayed.
264 GlobalError* error = GetGlobalError(mock_change_); 264 GlobalError* error = GetGlobalError(mock_change_);
265 ASSERT_TRUE(error); 265 ASSERT_TRUE(error);
266 ASSERT_TRUE(error->HasShownBubbleView()); 266 ASSERT_TRUE(error->HasShownBubbleView());
267 267
268 // ProtectService will own this change instance as well. 268 // ProtectService will own this change instance as well.
269 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 269 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
270 // Show the second change. 270 // Show the second change.
271 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 271 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
272 WillOnce(Return(true)); 272 WillOnce(Return(true));
273 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false)); 273 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
274 protector_service_->ShowChange(mock_change2); 274 protector_service_->ShowChange(mock_change2);
275 ui_test_utils::RunAllPendingInMessageLoop(); 275 content::RunAllPendingInMessageLoop();
276 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 276 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
277 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 277 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
278 278
279 // The second bubble view hasn't been displayed because the first is still 279 // The second bubble view hasn't been displayed because the first is still
280 // shown. 280 // shown.
281 GlobalError* error2 = GetGlobalError(mock_change2); 281 GlobalError* error2 = GetGlobalError(mock_change2);
282 ASSERT_TRUE(error2); 282 ASSERT_TRUE(error2);
283 EXPECT_FALSE(error2->HasShownBubbleView()); 283 EXPECT_FALSE(error2->HasShownBubbleView());
284 284
285 // Apply the first change, mimicking a button click; the second should still 285 // Apply the first change, mimicking a button click; the second should still
286 // be active. 286 // be active.
287 EXPECT_CALL(*mock_change_, Apply(browser())); 287 EXPECT_CALL(*mock_change_, Apply(browser()));
288 error->BubbleViewCancelButtonPressed(browser()); 288 error->BubbleViewCancelButtonPressed(browser());
289 error->GetBubbleView()->CloseBubbleView(); 289 error->GetBubbleView()->CloseBubbleView();
290 ui_test_utils::RunAllPendingInMessageLoop(); 290 content::RunAllPendingInMessageLoop();
291 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 291 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
292 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 292 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
293 293
294 // Now the second bubble view should be shown. 294 // Now the second bubble view should be shown.
295 ASSERT_TRUE(error2->HasShownBubbleView()); 295 ASSERT_TRUE(error2->HasShownBubbleView());
296 296
297 // Finally apply the second change. 297 // Finally apply the second change.
298 EXPECT_CALL(*mock_change2, Apply(browser())); 298 EXPECT_CALL(*mock_change2, Apply(browser()));
299 error2->BubbleViewCancelButtonPressed(browser()); 299 error2->BubbleViewCancelButtonPressed(browser());
300 error2->GetBubbleView()->CloseBubbleView(); 300 error2->GetBubbleView()->CloseBubbleView();
301 ui_test_utils::RunAllPendingInMessageLoop(); 301 content::RunAllPendingInMessageLoop();
302 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 302 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
303 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 303 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
304 } 304 }
305 305
306 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, 306 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
307 ShowMultipleChangesAndApplyManuallyBeforeOther) { 307 ShowMultipleChangesAndApplyManuallyBeforeOther) {
308 // Show the first change. 308 // Show the first change.
309 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 309 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
310 WillOnce(Return(true)); 310 WillOnce(Return(true));
311 protector_service_->ShowChange(mock_change_); 311 protector_service_->ShowChange(mock_change_);
312 ui_test_utils::RunAllPendingInMessageLoop(); 312 content::RunAllPendingInMessageLoop();
313 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 313 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
314 314
315 // The first bubble view has been displayed. 315 // The first bubble view has been displayed.
316 GlobalError* error = GetGlobalError(mock_change_); 316 GlobalError* error = GetGlobalError(mock_change_);
317 ASSERT_TRUE(error); 317 ASSERT_TRUE(error);
318 ASSERT_TRUE(error->HasShownBubbleView()); 318 ASSERT_TRUE(error->HasShownBubbleView());
319 319
320 // Apply the first change, mimicking a button click. 320 // Apply the first change, mimicking a button click.
321 EXPECT_CALL(*mock_change_, Apply(browser())); 321 EXPECT_CALL(*mock_change_, Apply(browser()));
322 error->BubbleViewCancelButtonPressed(browser()); 322 error->BubbleViewCancelButtonPressed(browser());
323 error->GetBubbleView()->CloseBubbleView(); 323 error->GetBubbleView()->CloseBubbleView();
324 ui_test_utils::RunAllPendingInMessageLoop(); 324 content::RunAllPendingInMessageLoop();
325 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 325 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
326 326
327 // ProtectService will own this change instance as well. 327 // ProtectService will own this change instance as well.
328 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 328 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
329 // Show the second change. 329 // Show the second change.
330 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 330 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
331 WillOnce(Return(true)); 331 WillOnce(Return(true));
332 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false)); 332 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
333 protector_service_->ShowChange(mock_change2); 333 protector_service_->ShowChange(mock_change2);
334 ui_test_utils::RunAllPendingInMessageLoop(); 334 content::RunAllPendingInMessageLoop();
335 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 335 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
336 336
337 // The second bubble view has been displayed. 337 // The second bubble view has been displayed.
338 GlobalError* error2 = GetGlobalError(mock_change2); 338 GlobalError* error2 = GetGlobalError(mock_change2);
339 ASSERT_TRUE(error2); 339 ASSERT_TRUE(error2);
340 ASSERT_TRUE(error2->HasShownBubbleView()); 340 ASSERT_TRUE(error2->HasShownBubbleView());
341 341
342 // Finally apply the second change. 342 // Finally apply the second change.
343 EXPECT_CALL(*mock_change2, Apply(browser())); 343 EXPECT_CALL(*mock_change2, Apply(browser()));
344 error2->BubbleViewCancelButtonPressed(browser()); 344 error2->BubbleViewCancelButtonPressed(browser());
345 error2->GetBubbleView()->CloseBubbleView(); 345 error2->GetBubbleView()->CloseBubbleView();
346 ui_test_utils::RunAllPendingInMessageLoop(); 346 content::RunAllPendingInMessageLoop();
347 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 347 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
348 } 348 }
349 349
350 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleDifferentURLs) { 350 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleDifferentURLs) {
351 GURL url1("http://example.com/"); 351 GURL url1("http://example.com/");
352 GURL url2("http://example.net/"); 352 GURL url2("http://example.net/");
353 353
354 // Show the first change with some non-empty URL. 354 // Show the first change with some non-empty URL.
355 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 355 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
356 WillOnce(Return(true)); 356 WillOnce(Return(true));
357 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1)); 357 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
358 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true)); 358 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
359 protector_service_->ShowChange(mock_change_); 359 protector_service_->ShowChange(mock_change_);
360 ui_test_utils::RunAllPendingInMessageLoop(); 360 content::RunAllPendingInMessageLoop();
361 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 361 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
362 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); 362 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
363 363
364 // ProtectService will own this change instance as well. 364 // ProtectService will own this change instance as well.
365 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 365 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
366 // Show the second change with another non-empty URL. 366 // Show the second change with another non-empty URL.
367 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 367 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
368 WillOnce(Return(true)); 368 WillOnce(Return(true));
369 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2)); 369 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
370 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true)); 370 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
371 protector_service_->ShowChange(mock_change2); 371 protector_service_->ShowChange(mock_change2);
372 ui_test_utils::RunAllPendingInMessageLoop(); 372 content::RunAllPendingInMessageLoop();
373 373
374 // Both changes are shown separately, not composited. 374 // Both changes are shown separately, not composited.
375 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 375 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
376 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 376 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
377 EXPECT_EQ(mock_change2, protector_service_->GetLastChange()); 377 EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
378 378
379 protector_service_->DismissChange(mock_change_); 379 protector_service_->DismissChange(mock_change_);
380 protector_service_->DismissChange(mock_change2); 380 protector_service_->DismissChange(mock_change2);
381 ui_test_utils::RunAllPendingInMessageLoop(); 381 content::RunAllPendingInMessageLoop();
382 EXPECT_FALSE(protector_service_->GetLastChange()); 382 EXPECT_FALSE(protector_service_->GetLastChange());
383 } 383 }
384 384
385 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismiss) { 385 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismiss) {
386 GURL url1("http://example.com/"); 386 GURL url1("http://example.com/");
387 387
388 // Show the first change. 388 // Show the first change.
389 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 389 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
390 WillOnce(Return(true)); 390 WillOnce(Return(true));
391 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1)); 391 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
392 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true)); 392 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
393 protector_service_->ShowChange(mock_change_); 393 protector_service_->ShowChange(mock_change_);
394 ui_test_utils::RunAllPendingInMessageLoop(); 394 content::RunAllPendingInMessageLoop();
395 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 395 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
396 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); 396 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
397 397
398 // The first bubble view has been displayed. 398 // The first bubble view has been displayed.
399 GlobalError* error = GetGlobalError(mock_change_); 399 GlobalError* error = GetGlobalError(mock_change_);
400 ASSERT_TRUE(error); 400 ASSERT_TRUE(error);
401 EXPECT_TRUE(error->HasShownBubbleView()); 401 EXPECT_TRUE(error->HasShownBubbleView());
402 402
403 // ProtectService will own this change instance as well. 403 // ProtectService will own this change instance as well.
404 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 404 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
405 // Show the second change. 405 // Show the second change.
406 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 406 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
407 WillOnce(Return(true)); 407 WillOnce(Return(true));
408 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1)); 408 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
409 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true)); 409 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
410 protector_service_->ShowChange(mock_change2); 410 protector_service_->ShowChange(mock_change2);
411 ui_test_utils::RunAllPendingInMessageLoop(); 411 content::RunAllPendingInMessageLoop();
412 412
413 // Now ProtectorService should be showing a single composite change. 413 // Now ProtectorService should be showing a single composite change.
414 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 414 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
415 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 415 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
416 416
417 BaseSettingChange* composite_change = protector_service_->GetLastChange(); 417 BaseSettingChange* composite_change = protector_service_->GetLastChange();
418 ASSERT_TRUE(composite_change); 418 ASSERT_TRUE(composite_change);
419 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); 419 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
420 420
421 // The second (composite) bubble view has been displayed. 421 // The second (composite) bubble view has been displayed.
422 GlobalError* error2 = GetGlobalError(composite_change); 422 GlobalError* error2 = GetGlobalError(composite_change);
423 ASSERT_TRUE(error2); 423 ASSERT_TRUE(error2);
424 EXPECT_TRUE(error2->HasShownBubbleView()); 424 EXPECT_TRUE(error2->HasShownBubbleView());
425 425
426 protector_service_->DismissChange(composite_change); 426 protector_service_->DismissChange(composite_change);
427 ui_test_utils::RunAllPendingInMessageLoop(); 427 content::RunAllPendingInMessageLoop();
428 EXPECT_FALSE(IsGlobalErrorActive(composite_change)); 428 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
429 EXPECT_FALSE(protector_service_->GetLastChange()); 429 EXPECT_FALSE(protector_service_->GetLastChange());
430 430
431 // Show the third change. 431 // Show the third change.
432 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>(); 432 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
433 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())). 433 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
434 WillOnce(Return(true)); 434 WillOnce(Return(true));
435 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url1)); 435 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url1));
436 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true)); 436 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
437 protector_service_->ShowChange(mock_change3); 437 protector_service_->ShowChange(mock_change3);
438 ui_test_utils::RunAllPendingInMessageLoop(); 438 content::RunAllPendingInMessageLoop();
439 439
440 // The third change should not be composed with the previous. 440 // The third change should not be composed with the previous.
441 EXPECT_TRUE(IsGlobalErrorActive(mock_change3)); 441 EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
442 EXPECT_EQ(mock_change3, protector_service_->GetLastChange()); 442 EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
443 443
444 protector_service_->DismissChange(mock_change3); 444 protector_service_->DismissChange(mock_change3);
445 ui_test_utils::RunAllPendingInMessageLoop(); 445 content::RunAllPendingInMessageLoop();
446 EXPECT_FALSE(IsGlobalErrorActive(mock_change3)); 446 EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
447 EXPECT_FALSE(protector_service_->GetLastChange()); 447 EXPECT_FALSE(protector_service_->GetLastChange());
448 } 448 }
449 449
450 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndOther) { 450 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndOther) {
451 GURL url1("http://example.com/"); 451 GURL url1("http://example.com/");
452 GURL url2("http://example.net/"); 452 GURL url2("http://example.net/");
453 453
454 // Show the first change. 454 // Show the first change.
455 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 455 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
456 WillOnce(Return(true)); 456 WillOnce(Return(true));
457 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1)); 457 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
458 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true)); 458 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
459 protector_service_->ShowChange(mock_change_); 459 protector_service_->ShowChange(mock_change_);
460 ui_test_utils::RunAllPendingInMessageLoop(); 460 content::RunAllPendingInMessageLoop();
461 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 461 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
462 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); 462 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
463 463
464 // ProtectService will own this change instance as well. 464 // ProtectService will own this change instance as well.
465 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 465 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
466 // Show the second change. 466 // Show the second change.
467 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 467 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
468 WillOnce(Return(true)); 468 WillOnce(Return(true));
469 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1)); 469 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
470 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true)); 470 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
471 protector_service_->ShowChange(mock_change2); 471 protector_service_->ShowChange(mock_change2);
472 ui_test_utils::RunAllPendingInMessageLoop(); 472 content::RunAllPendingInMessageLoop();
473 473
474 // Now ProtectorService should be showing a single composite change. 474 // Now ProtectorService should be showing a single composite change.
475 BaseSettingChange* composite_change = protector_service_->GetLastChange(); 475 BaseSettingChange* composite_change = protector_service_->GetLastChange();
476 ASSERT_TRUE(composite_change); 476 ASSERT_TRUE(composite_change);
477 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); 477 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
478 478
479 // Show the third change, with the same URL as 1st and 2nd. 479 // Show the third change, with the same URL as 1st and 2nd.
480 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>(); 480 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
481 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())). 481 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
482 WillOnce(Return(true)); 482 WillOnce(Return(true));
483 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url1)); 483 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url1));
484 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true)); 484 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
485 protector_service_->ShowChange(mock_change3); 485 protector_service_->ShowChange(mock_change3);
486 ui_test_utils::RunAllPendingInMessageLoop(); 486 content::RunAllPendingInMessageLoop();
487 487
488 // The third change should be composed with the previous. 488 // The third change should be composed with the previous.
489 EXPECT_FALSE(IsGlobalErrorActive(mock_change3)); 489 EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
490 EXPECT_EQ(composite_change, protector_service_->GetLastChange()); 490 EXPECT_EQ(composite_change, protector_service_->GetLastChange());
491 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); 491 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
492 492
493 // Show the 4th change, now with a different URL. 493 // Show the 4th change, now with a different URL.
494 MockSettingChange* mock_change4 = new NiceMock<MockSettingChange>(); 494 MockSettingChange* mock_change4 = new NiceMock<MockSettingChange>();
495 EXPECT_CALL(*mock_change4, MockInit(browser()->profile())). 495 EXPECT_CALL(*mock_change4, MockInit(browser()->profile())).
496 WillOnce(Return(true)); 496 WillOnce(Return(true));
497 EXPECT_CALL(*mock_change4, GetNewSettingURL()).WillRepeatedly(Return(url2)); 497 EXPECT_CALL(*mock_change4, GetNewSettingURL()).WillRepeatedly(Return(url2));
498 EXPECT_CALL(*mock_change4, CanBeMerged()).WillRepeatedly(Return(true)); 498 EXPECT_CALL(*mock_change4, CanBeMerged()).WillRepeatedly(Return(true));
499 protector_service_->ShowChange(mock_change4); 499 protector_service_->ShowChange(mock_change4);
500 ui_test_utils::RunAllPendingInMessageLoop(); 500 content::RunAllPendingInMessageLoop();
501 501
502 // The 4th change is shown independently. 502 // The 4th change is shown independently.
503 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); 503 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
504 EXPECT_TRUE(IsGlobalErrorActive(mock_change4)); 504 EXPECT_TRUE(IsGlobalErrorActive(mock_change4));
505 EXPECT_EQ(mock_change4, protector_service_->GetLastChange()); 505 EXPECT_EQ(mock_change4, protector_service_->GetLastChange());
506 506
507 protector_service_->DismissChange(composite_change); 507 protector_service_->DismissChange(composite_change);
508 protector_service_->DismissChange(mock_change4); 508 protector_service_->DismissChange(mock_change4);
509 ui_test_utils::RunAllPendingInMessageLoop(); 509 content::RunAllPendingInMessageLoop();
510 EXPECT_FALSE(IsGlobalErrorActive(composite_change)); 510 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
511 EXPECT_FALSE(IsGlobalErrorActive(mock_change4)); 511 EXPECT_FALSE(IsGlobalErrorActive(mock_change4));
512 EXPECT_FALSE(protector_service_->GetLastChange()); 512 EXPECT_FALSE(protector_service_->GetLastChange());
513 } 513 }
514 514
515 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismissSingle) { 515 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismissSingle) {
516 GURL url1("http://example.com/"); 516 GURL url1("http://example.com/");
517 GURL url2("http://example.net/"); 517 GURL url2("http://example.net/");
518 518
519 // Show the first change. 519 // Show the first change.
520 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 520 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
521 WillOnce(Return(true)); 521 WillOnce(Return(true));
522 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1)); 522 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
523 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true)); 523 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
524 protector_service_->ShowChange(mock_change_); 524 protector_service_->ShowChange(mock_change_);
525 ui_test_utils::RunAllPendingInMessageLoop(); 525 content::RunAllPendingInMessageLoop();
526 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 526 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
527 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); 527 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
528 528
529 // ProtectService will own this change instance as well. 529 // ProtectService will own this change instance as well.
530 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 530 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
531 // Show the second change. 531 // Show the second change.
532 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 532 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
533 WillOnce(Return(true)); 533 WillOnce(Return(true));
534 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1)); 534 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
535 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true)); 535 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
536 protector_service_->ShowChange(mock_change2); 536 protector_service_->ShowChange(mock_change2);
537 ui_test_utils::RunAllPendingInMessageLoop(); 537 content::RunAllPendingInMessageLoop();
538 538
539 // Now ProtectorService should be showing a single composite change. 539 // Now ProtectorService should be showing a single composite change.
540 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 540 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
541 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 541 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
542 542
543 BaseSettingChange* composite_change = protector_service_->GetLastChange(); 543 BaseSettingChange* composite_change = protector_service_->GetLastChange();
544 ASSERT_TRUE(composite_change); 544 ASSERT_TRUE(composite_change);
545 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); 545 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
546 546
547 // Show the third change with a different URL. 547 // Show the third change with a different URL.
548 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>(); 548 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
549 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())). 549 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
550 WillOnce(Return(true)); 550 WillOnce(Return(true));
551 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url2)); 551 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url2));
552 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true)); 552 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
553 protector_service_->ShowChange(mock_change3); 553 protector_service_->ShowChange(mock_change3);
554 ui_test_utils::RunAllPendingInMessageLoop(); 554 content::RunAllPendingInMessageLoop();
555 555
556 // The third change should not be composed with the previous. 556 // The third change should not be composed with the previous.
557 EXPECT_TRUE(IsGlobalErrorActive(mock_change3)); 557 EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
558 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); 558 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
559 EXPECT_EQ(mock_change3, protector_service_->GetLastChange()); 559 EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
560 560
561 // Now dismiss the first change. 561 // Now dismiss the first change.
562 protector_service_->DismissChange(mock_change_); 562 protector_service_->DismissChange(mock_change_);
563 ui_test_utils::RunAllPendingInMessageLoop(); 563 content::RunAllPendingInMessageLoop();
564 564
565 // This should effectively dismiss the whole composite change. 565 // This should effectively dismiss the whole composite change.
566 EXPECT_FALSE(IsGlobalErrorActive(composite_change)); 566 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
567 EXPECT_TRUE(IsGlobalErrorActive(mock_change3)); 567 EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
568 EXPECT_EQ(mock_change3, protector_service_->GetLastChange()); 568 EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
569 569
570 protector_service_->DismissChange(mock_change3); 570 protector_service_->DismissChange(mock_change3);
571 ui_test_utils::RunAllPendingInMessageLoop(); 571 content::RunAllPendingInMessageLoop();
572 EXPECT_FALSE(IsGlobalErrorActive(mock_change3)); 572 EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
573 EXPECT_FALSE(protector_service_->GetLastChange()); 573 EXPECT_FALSE(protector_service_->GetLastChange());
574 } 574 }
575 575
576 // Verifies that changes with different URLs but same domain are merged. 576 // Verifies that changes with different URLs but same domain are merged.
577 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, SameDomainDifferentURLs) { 577 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, SameDomainDifferentURLs) {
578 GURL url1("http://www.example.com/abc"); 578 GURL url1("http://www.example.com/abc");
579 GURL url2("http://example.com/def"); 579 GURL url2("http://example.com/def");
580 580
581 // Show the first change with some non-empty URL. 581 // Show the first change with some non-empty URL.
582 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 582 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
583 WillOnce(Return(true)); 583 WillOnce(Return(true));
584 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1)); 584 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
585 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true)); 585 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
586 protector_service_->ShowChange(mock_change_); 586 protector_service_->ShowChange(mock_change_);
587 ui_test_utils::RunAllPendingInMessageLoop(); 587 content::RunAllPendingInMessageLoop();
588 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 588 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
589 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); 589 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
590 590
591 // ProtectService will own this change instance as well. 591 // ProtectService will own this change instance as well.
592 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 592 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
593 // Show the second change with another non-empty URL having same domain. 593 // Show the second change with another non-empty URL having same domain.
594 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 594 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
595 WillOnce(Return(true)); 595 WillOnce(Return(true));
596 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2)); 596 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
597 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true)); 597 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
598 protector_service_->ShowChange(mock_change2); 598 protector_service_->ShowChange(mock_change2);
599 ui_test_utils::RunAllPendingInMessageLoop(); 599 content::RunAllPendingInMessageLoop();
600 600
601 // Changes should be merged. 601 // Changes should be merged.
602 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 602 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
603 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 603 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
604 604
605 BaseSettingChange* composite_change = protector_service_->GetLastChange(); 605 BaseSettingChange* composite_change = protector_service_->GetLastChange();
606 ASSERT_TRUE(composite_change); 606 ASSERT_TRUE(composite_change);
607 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); 607 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
608 608
609 protector_service_->DismissChange(composite_change); 609 protector_service_->DismissChange(composite_change);
610 ui_test_utils::RunAllPendingInMessageLoop(); 610 content::RunAllPendingInMessageLoop();
611 EXPECT_FALSE(IsGlobalErrorActive(composite_change)); 611 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
612 EXPECT_FALSE(protector_service_->GetLastChange()); 612 EXPECT_FALSE(protector_service_->GetLastChange());
613 } 613 }
614 614
615 // Verifies that changes with different Google URLs are merged. 615 // Verifies that changes with different Google URLs are merged.
616 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, DifferentGoogleDomains) { 616 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, DifferentGoogleDomains) {
617 GURL url1("http://www.google.com/search?q="); 617 GURL url1("http://www.google.com/search?q=");
618 GURL url2("http://google.ru/search?q="); 618 GURL url2("http://google.ru/search?q=");
619 619
620 // Show the first change with some non-empty URL. 620 // Show the first change with some non-empty URL.
621 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 621 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
622 WillOnce(Return(true)); 622 WillOnce(Return(true));
623 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1)); 623 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
624 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true)); 624 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
625 protector_service_->ShowChange(mock_change_); 625 protector_service_->ShowChange(mock_change_);
626 ui_test_utils::RunAllPendingInMessageLoop(); 626 content::RunAllPendingInMessageLoop();
627 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 627 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
628 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); 628 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
629 629
630 // ProtectService will own this change instance as well. 630 // ProtectService will own this change instance as well.
631 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 631 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
632 // Show the second change with another non-empty URL having same domain. 632 // Show the second change with another non-empty URL having same domain.
633 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 633 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
634 WillOnce(Return(true)); 634 WillOnce(Return(true));
635 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2)); 635 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
636 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true)); 636 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
637 protector_service_->ShowChange(mock_change2); 637 protector_service_->ShowChange(mock_change2);
638 ui_test_utils::RunAllPendingInMessageLoop(); 638 content::RunAllPendingInMessageLoop();
639 639
640 // Changes should be merged. 640 // Changes should be merged.
641 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 641 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
642 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 642 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
643 643
644 BaseSettingChange* composite_change = protector_service_->GetLastChange(); 644 BaseSettingChange* composite_change = protector_service_->GetLastChange();
645 ASSERT_TRUE(composite_change); 645 ASSERT_TRUE(composite_change);
646 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); 646 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
647 647
648 protector_service_->DismissChange(composite_change); 648 protector_service_->DismissChange(composite_change);
649 ui_test_utils::RunAllPendingInMessageLoop(); 649 content::RunAllPendingInMessageLoop();
650 EXPECT_FALSE(IsGlobalErrorActive(composite_change)); 650 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
651 EXPECT_FALSE(protector_service_->GetLastChange()); 651 EXPECT_FALSE(protector_service_->GetLastChange());
652 } 652 }
653 653
654 // TODO(ivankr): Timeout test. 654 // TODO(ivankr): Timeout test.
655 655
656 } // namespace protector 656 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager_browsertest.cc ('k') | chrome/browser/sync/test/integration/sessions_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698