Test the RemoveCommandObserver() routine that removes an observer from all its registered commands.
Review URL: http://codereview.chromium.org/20180

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9401 0039d316-1c4b-4281-b951-d872f2087c98
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 @@
   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());
+}