| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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)); |
| 176 protector_service_->ShowChange(mock_change2); | 181 protector_service_->ShowChange(mock_change2); |
| 177 ui_test_utils::RunAllPendingInMessageLoop(); | 182 ui_test_utils::RunAllPendingInMessageLoop(); |
| 178 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); | 183 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); |
| 179 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); | 184 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); |
| 185 EXPECT_EQ(mock_change2, protector_service_->GetLastChange()); |
| 180 | 186 |
| 181 // Apply the first change, the second should still be active. | 187 // Apply the first change, the second should still be active. |
| 182 EXPECT_CALL(*mock_change_, Apply(browser())); | 188 EXPECT_CALL(*mock_change_, Apply(browser())); |
| 183 protector_service_->ApplyChange(mock_change_, browser()); | 189 protector_service_->ApplyChange(mock_change_, browser()); |
| 184 ui_test_utils::RunAllPendingInMessageLoop(); | 190 ui_test_utils::RunAllPendingInMessageLoop(); |
| 185 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); | 191 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); |
| 186 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); | 192 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); |
| 193 EXPECT_EQ(mock_change2, protector_service_->GetLastChange()); |
| 187 | 194 |
| 188 // Finally apply the second change. | 195 // Finally apply the second change. |
| 189 EXPECT_CALL(*mock_change2, Apply(browser())); | 196 EXPECT_CALL(*mock_change2, Apply(browser())); |
| 190 protector_service_->ApplyChange(mock_change2, browser()); | 197 protector_service_->ApplyChange(mock_change2, browser()); |
| 191 ui_test_utils::RunAllPendingInMessageLoop(); | 198 ui_test_utils::RunAllPendingInMessageLoop(); |
| 192 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); | 199 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); |
| 193 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); | 200 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); |
| 201 EXPECT_FALSE(protector_service_->GetLastChange()); |
| 194 } | 202 } |
| 195 | 203 |
| 196 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, | 204 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, |
| 197 ShowMultipleChangesDismissAndApply) { | 205 ShowMultipleChangesDismissAndApply) { |
| 198 // Show the first change. | 206 // Show the first change. |
| 199 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). | 207 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). |
| 200 WillOnce(Return(true)); | 208 WillOnce(Return(true)); |
| 201 protector_service_->ShowChange(mock_change_); | 209 protector_service_->ShowChange(mock_change_); |
| 202 ui_test_utils::RunAllPendingInMessageLoop(); | 210 ui_test_utils::RunAllPendingInMessageLoop(); |
| 203 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); | 211 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 ASSERT_TRUE(error2->HasShownBubbleView()); | 321 ASSERT_TRUE(error2->HasShownBubbleView()); |
| 314 | 322 |
| 315 // Finally apply the second change. | 323 // Finally apply the second change. |
| 316 EXPECT_CALL(*mock_change2, Apply(browser())); | 324 EXPECT_CALL(*mock_change2, Apply(browser())); |
| 317 error2->BubbleViewCancelButtonPressed(browser()); | 325 error2->BubbleViewCancelButtonPressed(browser()); |
| 318 error2->GetBubbleView()->CloseBubbleView(); | 326 error2->GetBubbleView()->CloseBubbleView(); |
| 319 ui_test_utils::RunAllPendingInMessageLoop(); | 327 ui_test_utils::RunAllPendingInMessageLoop(); |
| 320 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); | 328 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); |
| 321 } | 329 } |
| 322 | 330 |
| 331 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowMultipleDifferentKeys) { |
| 332 // Show the first change with some non-empty key. |
| 333 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). |
| 334 WillOnce(Return(true)); |
| 335 EXPECT_CALL(*mock_change_, GetApplyKeyword()).WillRepeatedly(Return("K1")); |
| 336 protector_service_->ShowChange(mock_change_); |
| 337 ui_test_utils::RunAllPendingInMessageLoop(); |
| 338 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); |
| 339 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); |
| 340 |
| 341 // ProtectService will own this change instance as well. |
| 342 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); |
| 343 // Show the second change with another non-empty key. |
| 344 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). |
| 345 WillOnce(Return(true)); |
| 346 EXPECT_CALL(*mock_change2, GetApplyKeyword()).WillRepeatedly(Return("K2")); |
| 347 protector_service_->ShowChange(mock_change2); |
| 348 ui_test_utils::RunAllPendingInMessageLoop(); |
| 349 |
| 350 // Both changes are shown separately, not composited. |
| 351 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); |
| 352 EXPECT_TRUE(IsGlobalErrorActive(mock_change2)); |
| 353 EXPECT_EQ(mock_change2, protector_service_->GetLastChange()); |
| 354 |
| 355 protector_service_->DismissChange(mock_change_); |
| 356 protector_service_->DismissChange(mock_change2); |
| 357 ui_test_utils::RunAllPendingInMessageLoop(); |
| 358 EXPECT_FALSE(protector_service_->GetLastChange()); |
| 359 } |
| 360 |
| 361 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismiss) { |
| 362 const std::string key1 = "K1"; |
| 363 |
| 364 // Show the first change. |
| 365 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). |
| 366 WillOnce(Return(true)); |
| 367 EXPECT_CALL(*mock_change_, GetApplyKeyword()).WillRepeatedly(Return(key1)); |
| 368 protector_service_->ShowChange(mock_change_); |
| 369 ui_test_utils::RunAllPendingInMessageLoop(); |
| 370 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); |
| 371 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); |
| 372 |
| 373 // The first bubble view has been displayed. |
| 374 GlobalError* error = GetGlobalError(mock_change_); |
| 375 ASSERT_TRUE(error); |
| 376 EXPECT_TRUE(error->HasShownBubbleView()); |
| 377 |
| 378 // ProtectService will own this change instance as well. |
| 379 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); |
| 380 // Show the second change. |
| 381 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). |
| 382 WillOnce(Return(true)); |
| 383 EXPECT_CALL(*mock_change2, GetApplyKeyword()).WillRepeatedly(Return(key1)); |
| 384 protector_service_->ShowChange(mock_change2); |
| 385 ui_test_utils::RunAllPendingInMessageLoop(); |
| 386 |
| 387 // Now ProtectorService should be showing a single composite change. |
| 388 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); |
| 389 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); |
| 390 |
| 391 BaseSettingChange* composite_change = protector_service_->GetLastChange(); |
| 392 ASSERT_TRUE(composite_change); |
| 393 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); |
| 394 |
| 395 // The second (composite) bubble view has been displayed. |
| 396 GlobalError* error2 = GetGlobalError(composite_change); |
| 397 ASSERT_TRUE(error2); |
| 398 EXPECT_TRUE(error2->HasShownBubbleView()); |
| 399 |
| 400 protector_service_->DismissChange(composite_change); |
| 401 ui_test_utils::RunAllPendingInMessageLoop(); |
| 402 EXPECT_FALSE(IsGlobalErrorActive(composite_change)); |
| 403 EXPECT_FALSE(protector_service_->GetLastChange()); |
| 404 |
| 405 // Show the third change. |
| 406 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>(); |
| 407 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())). |
| 408 WillOnce(Return(true)); |
| 409 EXPECT_CALL(*mock_change3, GetApplyKeyword()).WillRepeatedly(Return(key1)); |
| 410 protector_service_->ShowChange(mock_change3); |
| 411 ui_test_utils::RunAllPendingInMessageLoop(); |
| 412 |
| 413 // The third change should not be composed with the previous. |
| 414 EXPECT_TRUE(IsGlobalErrorActive(mock_change3)); |
| 415 EXPECT_EQ(mock_change3, protector_service_->GetLastChange()); |
| 416 |
| 417 protector_service_->DismissChange(mock_change3); |
| 418 ui_test_utils::RunAllPendingInMessageLoop(); |
| 419 EXPECT_FALSE(IsGlobalErrorActive(mock_change3)); |
| 420 EXPECT_FALSE(protector_service_->GetLastChange()); |
| 421 } |
| 422 |
| 423 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndOther) { |
| 424 const std::string key1 = "K1"; |
| 425 const std::string key2 = "K2"; |
| 426 |
| 427 // Show the first change. |
| 428 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). |
| 429 WillOnce(Return(true)); |
| 430 EXPECT_CALL(*mock_change_, GetApplyKeyword()).WillRepeatedly(Return(key1)); |
| 431 protector_service_->ShowChange(mock_change_); |
| 432 ui_test_utils::RunAllPendingInMessageLoop(); |
| 433 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); |
| 434 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); |
| 435 |
| 436 // ProtectService will own this change instance as well. |
| 437 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); |
| 438 // Show the second change. |
| 439 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). |
| 440 WillOnce(Return(true)); |
| 441 EXPECT_CALL(*mock_change2, GetApplyKeyword()).WillRepeatedly(Return(key1)); |
| 442 protector_service_->ShowChange(mock_change2); |
| 443 ui_test_utils::RunAllPendingInMessageLoop(); |
| 444 |
| 445 // Now ProtectorService should be showing a single composite change. |
| 446 BaseSettingChange* composite_change = protector_service_->GetLastChange(); |
| 447 ASSERT_TRUE(composite_change); |
| 448 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); |
| 449 |
| 450 // Show the third change, with the same key as 1st and 2nd. |
| 451 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>(); |
| 452 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())). |
| 453 WillOnce(Return(true)); |
| 454 EXPECT_CALL(*mock_change3, GetApplyKeyword()).WillRepeatedly(Return(key1)); |
| 455 protector_service_->ShowChange(mock_change3); |
| 456 ui_test_utils::RunAllPendingInMessageLoop(); |
| 457 |
| 458 // The third change should be composed with the previous. |
| 459 EXPECT_FALSE(IsGlobalErrorActive(mock_change3)); |
| 460 EXPECT_EQ(composite_change, protector_service_->GetLastChange()); |
| 461 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); |
| 462 |
| 463 // Show the 4th change, now with a different key. |
| 464 MockSettingChange* mock_change4 = new NiceMock<MockSettingChange>(); |
| 465 EXPECT_CALL(*mock_change4, MockInit(browser()->profile())). |
| 466 WillOnce(Return(true)); |
| 467 EXPECT_CALL(*mock_change4, GetApplyKeyword()).WillRepeatedly(Return(key2)); |
| 468 protector_service_->ShowChange(mock_change4); |
| 469 ui_test_utils::RunAllPendingInMessageLoop(); |
| 470 |
| 471 // The 4th change is shown independently. |
| 472 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); |
| 473 EXPECT_TRUE(IsGlobalErrorActive(mock_change4)); |
| 474 EXPECT_EQ(mock_change4, protector_service_->GetLastChange()); |
| 475 |
| 476 protector_service_->DismissChange(composite_change); |
| 477 protector_service_->DismissChange(mock_change4); |
| 478 ui_test_utils::RunAllPendingInMessageLoop(); |
| 479 EXPECT_FALSE(IsGlobalErrorActive(composite_change)); |
| 480 EXPECT_FALSE(IsGlobalErrorActive(mock_change4)); |
| 481 EXPECT_FALSE(protector_service_->GetLastChange()); |
| 482 } |
| 483 |
| 484 IN_PROC_BROWSER_TEST_F(ProtectorServiceTest, ShowCompositeAndDismissSingle) { |
| 485 const std::string key1 = "K1"; |
| 486 const std::string key2 = "K2"; |
| 487 |
| 488 // Show the first change. |
| 489 EXPECT_CALL(*mock_change_, MockInit(browser()->profile())). |
| 490 WillOnce(Return(true)); |
| 491 EXPECT_CALL(*mock_change_, GetApplyKeyword()).WillRepeatedly(Return(key1)); |
| 492 protector_service_->ShowChange(mock_change_); |
| 493 ui_test_utils::RunAllPendingInMessageLoop(); |
| 494 EXPECT_TRUE(IsGlobalErrorActive(mock_change_)); |
| 495 EXPECT_EQ(mock_change_, protector_service_->GetLastChange()); |
| 496 |
| 497 // ProtectService will own this change instance as well. |
| 498 MockSettingChange* mock_change2 = new NiceMock<MockSettingChange>(); |
| 499 // Show the second change. |
| 500 EXPECT_CALL(*mock_change2, MockInit(browser()->profile())). |
| 501 WillOnce(Return(true)); |
| 502 EXPECT_CALL(*mock_change2, GetApplyKeyword()).WillRepeatedly(Return(key1)); |
| 503 protector_service_->ShowChange(mock_change2); |
| 504 ui_test_utils::RunAllPendingInMessageLoop(); |
| 505 |
| 506 // Now ProtectorService should be showing a single composite change. |
| 507 EXPECT_FALSE(IsGlobalErrorActive(mock_change_)); |
| 508 EXPECT_FALSE(IsGlobalErrorActive(mock_change2)); |
| 509 |
| 510 BaseSettingChange* composite_change = protector_service_->GetLastChange(); |
| 511 ASSERT_TRUE(composite_change); |
| 512 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); |
| 513 |
| 514 // Show the third change with a different key. |
| 515 MockSettingChange* mock_change3 = new NiceMock<MockSettingChange>(); |
| 516 EXPECT_CALL(*mock_change3, MockInit(browser()->profile())). |
| 517 WillOnce(Return(true)); |
| 518 EXPECT_CALL(*mock_change3, GetApplyKeyword()).WillRepeatedly(Return(key2)); |
| 519 protector_service_->ShowChange(mock_change3); |
| 520 ui_test_utils::RunAllPendingInMessageLoop(); |
| 521 |
| 522 // The third change should not be composed with the previous. |
| 523 EXPECT_TRUE(IsGlobalErrorActive(mock_change3)); |
| 524 EXPECT_TRUE(IsGlobalErrorActive(composite_change)); |
| 525 EXPECT_EQ(mock_change3, protector_service_->GetLastChange()); |
| 526 |
| 527 // Now dismiss the first change. |
| 528 protector_service_->DismissChange(mock_change_); |
| 529 ui_test_utils::RunAllPendingInMessageLoop(); |
| 530 |
| 531 // This should effectively dismiss the whole composite change. |
| 532 EXPECT_FALSE(IsGlobalErrorActive(composite_change)); |
| 533 EXPECT_TRUE(IsGlobalErrorActive(mock_change3)); |
| 534 EXPECT_EQ(mock_change3, protector_service_->GetLastChange()); |
| 535 |
| 536 protector_service_->DismissChange(mock_change3); |
| 537 ui_test_utils::RunAllPendingInMessageLoop(); |
| 538 EXPECT_FALSE(IsGlobalErrorActive(mock_change3)); |
| 539 EXPECT_FALSE(protector_service_->GetLastChange()); |
| 540 } |
| 541 |
| 323 // TODO(ivankr): Timeout test. | 542 // TODO(ivankr): Timeout test. |
| 324 | 543 |
| 325 } // namespace protector | 544 } // namespace protector |
| OLD | NEW |