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

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

Issue 9968007: [protector] Support for collapsing multiple changes into a single one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 8 years, 8 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 16 matching lines...) Expand all
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(BaseSettingChange* change) { 36 GlobalError* GetGlobalError(BaseSettingChange* change) {
37 std::vector<ProtectorService::Item>::iterator item = 37 for (ProtectorService::Items::iterator item =
38 std::find_if(protector_service_->items_.begin(), 38 protector_service_->items_.begin();
39 protector_service_->items_.end(), 39 item != protector_service_->items_.end(); item++) {
40 ProtectorService::MatchItemByChange(change)); 40 if (item->change.get() == change)
41 return item == protector_service_->items_.end() ? 41 return item->error.get();
42 NULL : item->error.get(); 42 }
43 return NULL;
43 } 44 }
44 45
45 // Checks that |protector_service_| has an error instance corresponding to 46 // Checks that |protector_service_| has an error instance corresponding to
46 // |change| and that GlobalErrorService knows about it. 47 // |change| and that GlobalErrorService knows about it.
47 bool IsGlobalErrorActive(BaseSettingChange* change) { 48 bool IsGlobalErrorActive(BaseSettingChange* change) {
48 GlobalError* error = GetGlobalError(change); 49 GlobalError* error = GetGlobalError(change);
49 if (!error) 50 if (!error)
50 return false; 51 return false;
51 if (!GlobalErrorServiceFactory::GetForProfile(browser()->profile())-> 52 if (!GlobalErrorServiceFactory::GetForProfile(browser()->profile())->
52 GetGlobalErrorByMenuItemCommandID(error->MenuItemCommandID())) { 53 GetGlobalErrorByMenuItemCommandID(error->MenuItemCommandID())) {
53 return false; 54 return false;
54 } 55 }
55 return protector_service_->IsShowingChange(); 56 return protector_service_->IsShowingChange();
56 } 57 }
57 58
58 ProtectorService* protector_service_; 59 ProtectorService* protector_service_;
59 MockSettingChange* mock_change_; 60 MockSettingChange* mock_change_;
60 }; 61 };
61 62
62 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) { 63 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ChangeInitError) {
63 // Init fails and causes the change to be ignored. 64 // Init fails and causes the change to be ignored.
64 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 65 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
65 WillOnce(Return(false)); 66 WillOnce(Return(false));
66 protector_service_->ShowChange(mock_change_); 67 protector_service_->ShowChange(mock_change_);
67 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 68 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
68 ui_test_utils::RunAllPendingInMessageLoop(); 69 ui_test_utils::RunAllPendingInMessageLoop();
69 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 70 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
71 EXPECT_FALSE(protector_service_->GetLastChange());
70 } 72 }
71 73
72 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) { 74 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndDismiss) {
73 // Show the change and immediately dismiss it. 75 // Show the change and immediately dismiss it.
74 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 76 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
75 WillOnce(Return(true)); 77 WillOnce(Return(true));
76 protector_service_->ShowChange(mock_change_); 78 protector_service_->ShowChange(mock_change_);
77 ui_test_utils::RunAllPendingInMessageLoop(); 79 ui_test_utils::RunAllPendingInMessageLoop();
78 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 80 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
81 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
79 protector_service_->DismissChange(mock_change_); 82 protector_service_->DismissChange(mock_change_);
80 ui_test_utils::RunAllPendingInMessageLoop(); 83 ui_test_utils::RunAllPendingInMessageLoop();
81 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 84 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
85 EXPECT_FALSE(protector_service_->GetLastChange());
82 } 86 }
83 87
84 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) { 88 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowAndApply) {
85 // Show the change and apply it. 89 // Show the change and apply it.
86 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 90 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
87 WillOnce(Return(true)); 91 WillOnce(Return(true));
88 protector_service_->ShowChange(mock_change_); 92 protector_service_->ShowChange(mock_change_);
89 ui_test_utils::RunAllPendingInMessageLoop(); 93 ui_test_utils::RunAllPendingInMessageLoop();
90 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 94 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
91 EXPECT_CALL(*mock_change_, Apply(browser())); 95 EXPECT_CALL(*mock_change_, Apply(browser()));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 164 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
161 } 165 }
162 166
163 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) { 167 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleChangesAndApply) {
164 // Show the first change. 168 // Show the first change.
165 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 169 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
166 WillOnce(Return(true)); 170 WillOnce(Return(true));
167 protector_service_->ShowChange(mock_change_); 171 protector_service_->ShowChange(mock_change_);
168 ui_test_utils::RunAllPendingInMessageLoop(); 172 ui_test_utils::RunAllPendingInMessageLoop();
169 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 173 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
174 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
170 175
171 // ProtectService will own this change instance as well. 176 // ProtectService will own this change instance as well.
172 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 177 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
173 // Show the second change. 178 // Show the second change.
174 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 179 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
175 WillOnce(Return(true)); 180 WillOnce(Return(true));
181 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
176 protector_service_->ShowChange(mock_change2); 182 protector_service_->ShowChange(mock_change2);
177 ui_test_utils::RunAllPendingInMessageLoop(); 183 ui_test_utils::RunAllPendingInMessageLoop();
178 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 184 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
179 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 185 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
186 EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
180 187
181 // Apply the first change, the second should still be active. 188 // Apply the first change, the second should still be active.
182 EXPECT_CALL(*mock_change_, Apply(browser())); 189 EXPECT_CALL(*mock_change_, Apply(browser()));
183 protector_service_->ApplyChange(mock_change_, browser()); 190 protector_service_->ApplyChange(mock_change_, browser());
184 ui_test_utils::RunAllPendingInMessageLoop(); 191 ui_test_utils::RunAllPendingInMessageLoop();
185 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 192 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
186 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 193 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
194 EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
187 195
188 // Finally apply the second change. 196 // Finally apply the second change.
189 EXPECT_CALL(*mock_change2, Apply(browser())); 197 EXPECT_CALL(*mock_change2, Apply(browser()));
190 protector_service_->ApplyChange(mock_change2, browser()); 198 protector_service_->ApplyChange(mock_change2, browser());
191 ui_test_utils::RunAllPendingInMessageLoop(); 199 ui_test_utils::RunAllPendingInMessageLoop();
192 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 200 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
193 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 201 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
202 EXPECT_FALSE(protector_service_->GetLastChange());
194 } 203 }
195 204
196 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, 205 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest,
197 ShowMultipleChangesDismissAndApply) { 206 ShowMultipleChangesDismissAndApply) {
198 // Show the first change. 207 // Show the first change.
199 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). 208 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
200 WillOnce(Return(true)); 209 WillOnce(Return(true));
201 protector_service_->ShowChange(mock_change_); 210 protector_service_->ShowChange(mock_change_);
202 ui_test_utils::RunAllPendingInMessageLoop(); 211 ui_test_utils::RunAllPendingInMessageLoop();
203 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 212 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
204 213
205 // ProtectService will own this change instance as well. 214 // ProtectService will own this change instance as well.
206 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 215 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
207 // Show the second change. 216 // Show the second change.
208 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 217 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
209 WillOnce(Return(true)); 218 WillOnce(Return(true));
219 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
210 protector_service_->ShowChange(mock_change2); 220 protector_service_->ShowChange(mock_change2);
211 ui_test_utils::RunAllPendingInMessageLoop(); 221 ui_test_utils::RunAllPendingInMessageLoop();
212 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 222 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
213 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 223 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
214 224
215 // Dismiss the first change, the second should still be active. 225 // Dismiss the first change, the second should still be active.
216 protector_service_->DismissChange(mock_change_); 226 protector_service_->DismissChange(mock_change_);
217 ui_test_utils::RunAllPendingInMessageLoop(); 227 ui_test_utils::RunAllPendingInMessageLoop();
218 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 228 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
219 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 229 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
(...skipping 18 matching lines...) Expand all
238 // The first bubble view has been displayed. 248 // The first bubble view has been displayed.
239 GlobalError* error = GetGlobalError(mock_change_); 249 GlobalError* error = GetGlobalError(mock_change_);
240 ASSERT_TRUE(error); 250 ASSERT_TRUE(error);
241 ASSERT_TRUE(error->HasShownBubbleView()); 251 ASSERT_TRUE(error->HasShownBubbleView());
242 252
243 // ProtectService will own this change instance as well. 253 // ProtectService will own this change instance as well.
244 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 254 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
245 // Show the second change. 255 // Show the second change.
246 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 256 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
247 WillOnce(Return(true)); 257 WillOnce(Return(true));
258 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
248 protector_service_->ShowChange(mock_change2); 259 protector_service_->ShowChange(mock_change2);
249 ui_test_utils::RunAllPendingInMessageLoop(); 260 ui_test_utils::RunAllPendingInMessageLoop();
250 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); 261 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
251 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 262 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
252 263
253 // The second bubble view hasn't been displayed because the first is still 264 // The second bubble view hasn't been displayed because the first is still
254 // shown. 265 // shown.
255 GlobalError* error2 = GetGlobalError(mock_change2); 266 GlobalError* error2 = GetGlobalError(mock_change2);
256 ASSERT_TRUE(error2); 267 ASSERT_TRUE(error2);
257 EXPECT_FALSE(error2->HasShownBubbleView()); 268 EXPECT_FALSE(error2->HasShownBubbleView());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 error->BubbleViewCancelButtonPressed(browser()); 307 error->BubbleViewCancelButtonPressed(browser());
297 error->GetBubbleView()->CloseBubbleView(); 308 error->GetBubbleView()->CloseBubbleView();
298 ui_test_utils::RunAllPendingInMessageLoop(); 309 ui_test_utils::RunAllPendingInMessageLoop();
299 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); 310 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
300 311
301 // ProtectService will own this change instance as well. 312 // ProtectService will own this change instance as well.
302 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); 313 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
303 // Show the second change. 314 // Show the second change.
304 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). 315 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
305 WillOnce(Return(true)); 316 WillOnce(Return(true));
317 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(false));
306 protector_service_->ShowChange(mock_change2); 318 protector_service_->ShowChange(mock_change2);
307 ui_test_utils::RunAllPendingInMessageLoop(); 319 ui_test_utils::RunAllPendingInMessageLoop();
308 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); 320 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
309 321
310 // The second bubble view has been displayed. 322 // The second bubble view has been displayed.
311 GlobalError* error2 = GetGlobalError(mock_change2); 323 GlobalError* error2 = GetGlobalError(mock_change2);
312 ASSERT_TRUE(error2); 324 ASSERT_TRUE(error2);
313 ASSERT_TRUE(error2->HasShownBubbleView()); 325 ASSERT_TRUE(error2->HasShownBubbleView());
314 326
315 // Finally apply the second change. 327 // Finally apply the second change.
316 EXPECT_CALL(*mock_change2, Apply(browser())); 328 EXPECT_CALL(*mock_change2, Apply(browser()));
317 error2->BubbleViewCancelButtonPressed(browser()); 329 error2->BubbleViewCancelButtonPressed(browser());
318 error2->GetBubbleView()->CloseBubbleView(); 330 error2->GetBubbleView()->CloseBubbleView();
319 ui_test_utils::RunAllPendingInMessageLoop(); 331 ui_test_utils::RunAllPendingInMessageLoop();
320 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); 332 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
321 } 333 }
322 334
335 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleDifferentURLs) {
336 GURL url1("http://example.com/");
337 GURL url2("http://example.net/");
338
339 // Show the first change with some non-empty URL.
340 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
341 WillOnce(Return(true));
342 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
343 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
344 protector_service_->ShowChange(mock_change_);
345 ui_test_utils::RunAllPendingInMessageLoop();
346 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
347 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
348
349 // ProtectService will own this change instance as well.
350 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
351 // Show the second change with another non-empty URL.
352 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
353 WillOnce(Return(true));
354 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
355 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
356 protector_service_->ShowChange(mock_change2);
357 ui_test_utils::RunAllPendingInMessageLoop();
358
359 // Both changes are shown separately, not composited.
360 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
361 EXPECT_TRUE(IsGlobalErrorActive(mock_change2));
362 EXPECT_EQ(mock_change2, protector_service_->GetLastChange());
363
364 protector_service_->DismissChange(mock_change_);
365 protector_service_->DismissChange(mock_change2);
366 ui_test_utils::RunAllPendingInMessageLoop();
367 EXPECT_FALSE(protector_service_->GetLastChange());
368 }
369
370 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismiss) {
371 GURL url1("http://example.com/");
372
373 // Show the first change.
374 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
375 WillOnce(Return(true));
376 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
377 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
378 protector_service_->ShowChange(mock_change_);
379 ui_test_utils::RunAllPendingInMessageLoop();
380 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
381 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
382
383 // The first bubble view has been displayed.
384 GlobalError* error = GetGlobalError(mock_change_);
385 ASSERT_TRUE(error);
386 EXPECT_TRUE(error->HasShownBubbleView());
387
388 // ProtectService will own this change instance as well.
389 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
390 // Show the second change.
391 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
392 WillOnce(Return(true));
393 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
394 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
395 protector_service_->ShowChange(mock_change2);
396 ui_test_utils::RunAllPendingInMessageLoop();
397
398 // Now ProtectorService should be showing a single composite change.
399 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
400 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
401
402 BaseSettingChange* composite_change = protector_service_->GetLastChange();
403 ASSERT_TRUE(composite_change);
404 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
405
406 // The second (composite) bubble view has been displayed.
407 GlobalError* error2 = GetGlobalError(composite_change);
408 ASSERT_TRUE(error2);
409 EXPECT_TRUE(error2->HasShownBubbleView());
410
411 protector_service_->DismissChange(composite_change);
412 ui_test_utils::RunAllPendingInMessageLoop();
413 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
414 EXPECT_FALSE(protector_service_->GetLastChange());
415
416 // Show the third change.
417 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
418 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
419 WillOnce(Return(true));
420 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url1));
421 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
422 protector_service_->ShowChange(mock_change3);
423 ui_test_utils::RunAllPendingInMessageLoop();
424
425 // The third change should not be composed with the previous.
426 EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
427 EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
428
429 protector_service_->DismissChange(mock_change3);
430 ui_test_utils::RunAllPendingInMessageLoop();
431 EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
432 EXPECT_FALSE(protector_service_->GetLastChange());
433 }
434
435 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndOther) {
436 GURL url1("http://example.com/");
437 GURL url2("http://example.net/");
438
439 // Show the first change.
440 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
441 WillOnce(Return(true));
442 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
443 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
444 protector_service_->ShowChange(mock_change_);
445 ui_test_utils::RunAllPendingInMessageLoop();
446 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
447 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
448
449 // ProtectService will own this change instance as well.
450 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
451 // Show the second change.
452 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
453 WillOnce(Return(true));
454 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
455 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
456 protector_service_->ShowChange(mock_change2);
457 ui_test_utils::RunAllPendingInMessageLoop();
458
459 // Now ProtectorService should be showing a single composite change.
460 BaseSettingChange* composite_change = protector_service_->GetLastChange();
461 ASSERT_TRUE(composite_change);
462 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
463
464 // Show the third change, with the same URL as 1st and 2nd.
465 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
466 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
467 WillOnce(Return(true));
468 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url1));
469 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
470 protector_service_->ShowChange(mock_change3);
471 ui_test_utils::RunAllPendingInMessageLoop();
472
473 // The third change should be composed with the previous.
474 EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
475 EXPECT_EQ(composite_change, protector_service_->GetLastChange());
476 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
477
478 // Show the 4th change, now with a different URL.
479 MockSettingChange* mock_change4 = new NiceMock<MockSettingChange>();
480 EXPECT_CALL(*mock_change4, MockInit(browser()->profile())).
481 WillOnce(Return(true));
482 EXPECT_CALL(*mock_change4, GetNewSettingURL()).WillRepeatedly(Return(url2));
483 EXPECT_CALL(*mock_change4, CanBeMerged()).WillRepeatedly(Return(true));
484 protector_service_->ShowChange(mock_change4);
485 ui_test_utils::RunAllPendingInMessageLoop();
486
487 // The 4th change is shown independently.
488 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
489 EXPECT_TRUE(IsGlobalErrorActive(mock_change4));
490 EXPECT_EQ(mock_change4, protector_service_->GetLastChange());
491
492 protector_service_->DismissChange(composite_change);
493 protector_service_->DismissChange(mock_change4);
494 ui_test_utils::RunAllPendingInMessageLoop();
495 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
496 EXPECT_FALSE(IsGlobalErrorActive(mock_change4));
497 EXPECT_FALSE(protector_service_->GetLastChange());
498 }
499
500 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismissSingle) {
501 GURL url1("http://example.com/");
502 GURL url2("http://example.net/");
503
504 // Show the first change.
505 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
506 WillOnce(Return(true));
507 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
508 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
509 protector_service_->ShowChange(mock_change_);
510 ui_test_utils::RunAllPendingInMessageLoop();
511 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
512 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
513
514 // ProtectService will own this change instance as well.
515 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
516 // Show the second change.
517 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
518 WillOnce(Return(true));
519 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url1));
520 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
521 protector_service_->ShowChange(mock_change2);
522 ui_test_utils::RunAllPendingInMessageLoop();
523
524 // Now ProtectorService should be showing a single composite change.
525 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
526 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
527
528 BaseSettingChange* composite_change = protector_service_->GetLastChange();
529 ASSERT_TRUE(composite_change);
530 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
531
532 // Show the third change with a different URL.
533 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>();
534 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())).
535 WillOnce(Return(true));
536 EXPECT_CALL(*mock_change3, GetNewSettingURL()).WillRepeatedly(Return(url2));
537 EXPECT_CALL(*mock_change3, CanBeMerged()).WillRepeatedly(Return(true));
538 protector_service_->ShowChange(mock_change3);
539 ui_test_utils::RunAllPendingInMessageLoop();
540
541 // The third change should not be composed with the previous.
542 EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
543 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
544 EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
545
546 // Now dismiss the first change.
547 protector_service_->DismissChange(mock_change_);
548 ui_test_utils::RunAllPendingInMessageLoop();
549
550 // This should effectively dismiss the whole composite change.
551 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
552 EXPECT_TRUE(IsGlobalErrorActive(mock_change3));
553 EXPECT_EQ(mock_change3, protector_service_->GetLastChange());
554
555 protector_service_->DismissChange(mock_change3);
556 ui_test_utils::RunAllPendingInMessageLoop();
557 EXPECT_FALSE(IsGlobalErrorActive(mock_change3));
558 EXPECT_FALSE(protector_service_->GetLastChange());
559 }
560
561 // Verifies that changes with different URLs but same domain are merged.
562 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, SameDomainDifferentURLs) {
563 GURL url1("http://www.example.com/abc");
564 GURL url2("http://example.com/def");
565
566 // Show the first change with some non-empty URL.
567 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
568 WillOnce(Return(true));
569 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
570 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
571 protector_service_->ShowChange(mock_change_);
572 ui_test_utils::RunAllPendingInMessageLoop();
573 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
574 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
575
576 // ProtectService will own this change instance as well.
577 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
578 // Show the second change with another non-empty URL having same domain.
579 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
580 WillOnce(Return(true));
581 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
582 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
583 protector_service_->ShowChange(mock_change2);
584 ui_test_utils::RunAllPendingInMessageLoop();
585
586 // Changes should be merged.
587 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
588 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
589
590 BaseSettingChange* composite_change = protector_service_->GetLastChange();
591 ASSERT_TRUE(composite_change);
592 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
593
594 protector_service_->DismissChange(composite_change);
595 ui_test_utils::RunAllPendingInMessageLoop();
596 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
597 EXPECT_FALSE(protector_service_->GetLastChange());
598 }
599
600 // Verifies that changes with different Google URLs are merged.
601 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, DifferentGoogleDomains) {
602 GURL url1("http://www.google.com/search?q=");
603 GURL url2("http://google.ru/search?q=");
604
605 // Show the first change with some non-empty URL.
606 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())).
607 WillOnce(Return(true));
608 EXPECT_CALL(*mock_change_, GetNewSettingURL()).WillRepeatedly(Return(url1));
609 EXPECT_CALL(*mock_change_, CanBeMerged()).WillRepeatedly(Return(true));
610 protector_service_->ShowChange(mock_change_);
611 ui_test_utils::RunAllPendingInMessageLoop();
612 EXPECT_TRUE(IsGlobalErrorActive(mock_change_));
613 EXPECT_EQ(mock_change_, protector_service_->GetLastChange());
614
615 // ProtectService will own this change instance as well.
616 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>();
617 // Show the second change with another non-empty URL having same domain.
618 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())).
619 WillOnce(Return(true));
620 EXPECT_CALL(*mock_change2, GetNewSettingURL()).WillRepeatedly(Return(url2));
621 EXPECT_CALL(*mock_change2, CanBeMerged()).WillRepeatedly(Return(true));
622 protector_service_->ShowChange(mock_change2);
623 ui_test_utils::RunAllPendingInMessageLoop();
624
625 // Changes should be merged.
626 EXPECT_FALSE(IsGlobalErrorActive(mock_change_));
627 EXPECT_FALSE(IsGlobalErrorActive(mock_change2));
628
629 BaseSettingChange* composite_change = protector_service_->GetLastChange();
630 ASSERT_TRUE(composite_change);
631 EXPECT_TRUE(IsGlobalErrorActive(composite_change));
632
633 protector_service_->DismissChange(composite_change);
634 ui_test_utils::RunAllPendingInMessageLoop();
635 EXPECT_FALSE(IsGlobalErrorActive(composite_change));
636 EXPECT_FALSE(protector_service_->GetLastChange());
637 }
638
323 // TODO(ivankr): Timeout test. 639 // TODO(ivankr): Timeout test.
324 640
325 } // namespace protector 641 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/protector_service.cc ('k') | chrome/browser/protector/session_startup_change.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698