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 "chrome/browser/extensions/api/idle/idle_api.h" | 5 #include "chrome/browser/extensions/api/idle/idle_api.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 { | 515 { |
516 ScopedListen listen(idle_manager_, extension_->id()); | 516 ScopedListen listen(idle_manager_, extension_->id()); |
517 idle_provider_->set_idle_time(16); | 517 idle_provider_->set_idle_time(16); |
518 EXPECT_CALL(*event_delegate_, | 518 EXPECT_CALL(*event_delegate_, |
519 OnStateChanged(extension_->id(), IDLE_STATE_IDLE)); | 519 OnStateChanged(extension_->id(), IDLE_STATE_IDLE)); |
520 idle_manager_->UpdateIdleState(); | 520 idle_manager_->UpdateIdleState(); |
521 testing::Mock::VerifyAndClearExpectations(event_delegate_); | 521 testing::Mock::VerifyAndClearExpectations(event_delegate_); |
522 } | 522 } |
523 | 523 |
524 // Threshold will reset after unload (and listen count == 0) | 524 // Threshold will reset after unload (and listen count == 0) |
525 UnloadedExtensionInfo details(extension_, | 525 UnloadedExtensionInfo details(extension_.get(), |
526 extension_misc::UNLOAD_REASON_UNINSTALL); | 526 extension_misc::UNLOAD_REASON_UNINSTALL); |
527 idle_manager_->Observe( | 527 idle_manager_->Observe( |
528 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 528 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
529 content::Source<Profile>(browser()->profile()), | 529 content::Source<Profile>(browser()->profile()), |
530 content::Details<UnloadedExtensionInfo>(&details)); | 530 content::Details<UnloadedExtensionInfo>(&details)); |
531 | 531 |
532 { | 532 { |
533 ScopedListen listen(idle_manager_, extension_->id()); | 533 ScopedListen listen(idle_manager_, extension_->id()); |
534 idle_manager_->UpdateIdleState(); | 534 idle_manager_->UpdateIdleState(); |
535 testing::Mock::VerifyAndClearExpectations(event_delegate_); | 535 testing::Mock::VerifyAndClearExpectations(event_delegate_); |
536 | 536 |
537 idle_provider_->set_idle_time(61); | 537 idle_provider_->set_idle_time(61); |
538 EXPECT_CALL(*event_delegate_, | 538 EXPECT_CALL(*event_delegate_, |
539 OnStateChanged(extension_->id(), IDLE_STATE_IDLE)); | 539 OnStateChanged(extension_->id(), IDLE_STATE_IDLE)); |
540 idle_manager_->UpdateIdleState(); | 540 idle_manager_->UpdateIdleState(); |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 // Verifies that unloading an extension with no listeners or threshold works. | 544 // Verifies that unloading an extension with no listeners or threshold works. |
545 TEST_F(IdleTest, UnloadOnly) { | 545 TEST_F(IdleTest, UnloadOnly) { |
546 UnloadedExtensionInfo details(extension_, | 546 UnloadedExtensionInfo details(extension_.get(), |
547 extension_misc::UNLOAD_REASON_UNINSTALL); | 547 extension_misc::UNLOAD_REASON_UNINSTALL); |
548 idle_manager_->Observe( | 548 idle_manager_->Observe( |
549 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 549 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
550 content::Source<Profile>(browser()->profile()), | 550 content::Source<Profile>(browser()->profile()), |
551 content::Details<UnloadedExtensionInfo>(&details)); | 551 content::Details<UnloadedExtensionInfo>(&details)); |
552 } | 552 } |
553 | 553 |
554 // Verifies that its ok for the unload notification to happen before all the | 554 // Verifies that its ok for the unload notification to happen before all the |
555 // listener removals. | 555 // listener removals. |
556 TEST_F(IdleTest, UnloadWhileListening) { | 556 TEST_F(IdleTest, UnloadWhileListening) { |
557 ScopedListen listen(idle_manager_, extension_->id()); | 557 ScopedListen listen(idle_manager_, extension_->id()); |
558 UnloadedExtensionInfo details(extension_, | 558 UnloadedExtensionInfo details(extension_.get(), |
559 extension_misc::UNLOAD_REASON_UNINSTALL); | 559 extension_misc::UNLOAD_REASON_UNINSTALL); |
560 idle_manager_->Observe( | 560 idle_manager_->Observe( |
561 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 561 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
562 content::Source<Profile>(browser()->profile()), | 562 content::Source<Profile>(browser()->profile()), |
563 content::Details<UnloadedExtensionInfo>(&details)); | 563 content::Details<UnloadedExtensionInfo>(&details)); |
564 } | 564 } |
565 | 565 |
566 } // namespace extensions | 566 } // namespace extensions |
OLD | NEW |