diff options
Diffstat (limited to 'chrome/browser/command_updater_unittest.cc')
-rw-r--r-- | chrome/browser/command_updater_unittest.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/chrome/browser/command_updater_unittest.cc b/chrome/browser/command_updater_unittest.cc index 0297cbc..d090d3d 100644 --- a/chrome/browser/command_updater_unittest.cc +++ b/chrome/browser/command_updater_unittest.cc @@ -75,3 +75,34 @@ TEST_F(CommandUpdaterTest, TestObservers) { command_updater.UpdateCommandEnabled(2, true); EXPECT_FALSE(observer.enabled()); } + +TEST_F(CommandUpdaterTest, TestObserverRemovingAllCommands) { + TestingCommandHandlerMock handler; + CommandUpdater command_updater(&handler); + + // Create two observers for the commands 1-3 as true, remove one using the + // single remove command, then set the command to false. Ensure that the + // removed observer still thinks all commands are true and the one left + // observing picked up the change. + + TestingCommandObserverMock observer_remove, observer_keep; + command_updater.AddCommandObserver(1, &observer_remove); + command_updater.AddCommandObserver(2, &observer_remove); + command_updater.AddCommandObserver(3, &observer_remove); + command_updater.AddCommandObserver(1, &observer_keep); + command_updater.AddCommandObserver(2, &observer_keep); + command_updater.AddCommandObserver(3, &observer_keep); + command_updater.UpdateCommandEnabled(1, true); + command_updater.UpdateCommandEnabled(2, true); + command_updater.UpdateCommandEnabled(3, true); + EXPECT_TRUE(observer_remove.enabled()); + + // Remove one observer and update the command. Check the states, which + // should be different. + command_updater.RemoveCommandObserver(&observer_remove); + command_updater.UpdateCommandEnabled(1, false); + command_updater.UpdateCommandEnabled(2, false); + command_updater.UpdateCommandEnabled(3, false); + EXPECT_TRUE(observer_remove.enabled()); + EXPECT_FALSE(observer_keep.enabled()); +} |