diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-20 23:03:14 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-20 23:03:14 +0000 |
commit | 1fc025209fbaeb2eb91cfeac8dbced8bc493f3b2 (patch) | |
tree | 13faf73a68138e0cd30e7b628a677ebb0422aa8c /chrome/browser/command_updater_unittest.cc | |
parent | 91f57782b0dd7a847b8d31020003f00099366545 (diff) | |
download | chromium_src-1fc025209fbaeb2eb91cfeac8dbced8bc493f3b2.zip chromium_src-1fc025209fbaeb2eb91cfeac8dbced8bc493f3b2.tar.gz chromium_src-1fc025209fbaeb2eb91cfeac8dbced8bc493f3b2.tar.bz2 |
Rework the command updater to not be dependent on views::Button (needed for porting).
TEST=make sure back/forward buttons still enable/disable correctly depending on the length of the back/forward navigation list.
Review URL: http://codereview.chromium.org/18343
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8332 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/command_updater_unittest.cc')
-rw-r--r-- | chrome/browser/command_updater_unittest.cc | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/chrome/browser/command_updater_unittest.cc b/chrome/browser/command_updater_unittest.cc new file mode 100644 index 0000000..9100753 --- /dev/null +++ b/chrome/browser/command_updater_unittest.cc @@ -0,0 +1,99 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/logging.h" +#include "chrome/browser/command_updater.h" +#include "testing/gtest/include/gtest/gtest.h" + +class TestingCommandHandlerMock + : public CommandUpdater::CommandUpdaterDelegate { + public: + virtual void ExecuteCommand(int id) { + EXPECT_EQ(1, id); + } +}; + +class CommandUpdaterTest : public testing::Test { +}; + +class TestingCommandObserverMock : public CommandUpdater::CommandObserver { + public: + virtual void EnabledStateChangedForCommand(int id, bool enabled) { + enabled_ = enabled; + } + + bool enabled() const { return enabled_; } + + private: + bool enabled_; +}; + +TEST_F(CommandUpdaterTest, TestBasicAPI) { + TestingCommandHandlerMock handler; + CommandUpdater command_updater(&handler); + + // Unsupported command + EXPECT_FALSE(command_updater.SupportsCommand(0)); + EXPECT_FALSE(command_updater.IsCommandEnabled(0)); + // TestingCommandHandlerMock::ExecuteCommand should not be called, since + // the command is not supported. + command_updater.ExecuteCommand(0); + + // Supported, enabled command + command_updater.UpdateCommandEnabled(1, true); + EXPECT_TRUE(command_updater.SupportsCommand(1)); + EXPECT_TRUE(command_updater.IsCommandEnabled(1)); + command_updater.ExecuteCommand(1); + + // Supported, disabled command + command_updater.UpdateCommandEnabled(2, false); + EXPECT_TRUE(command_updater.SupportsCommand(2)); + EXPECT_FALSE(command_updater.IsCommandEnabled(2)); + // TestingCommandHandlerMock::ExecuteCommmand should not be called, since + // the command_updater is disabled + command_updater.ExecuteCommand(2); +} + +TEST_F(CommandUpdaterTest, TestObservers) { + TestingCommandHandlerMock handler; + CommandUpdater command_updater(&handler); + + // Create an observer for the command 2 and add it to the controller, then + // update the command. + TestingCommandObserverMock observer; + command_updater.AddCommandObserver(2, &observer); + command_updater.UpdateCommandEnabled(2, true); + EXPECT_TRUE(observer.enabled()); + command_updater.UpdateCommandEnabled(2, false); + EXPECT_FALSE(observer.enabled()); + + // Remove the observer and update the command. + command_updater.RemoveCommandObserver(2, &observer); + command_updater.UpdateCommandEnabled(2, true); + EXPECT_FALSE(observer.enabled()); +} + +TEST_F(CommandUpdaterTest, TestRemoveObserverForUnsupportedCommand) { + TestingCommandHandlerMock handler; + CommandUpdater command_updater(&handler); + + // Test removing observers for commands that are unsupported + TestingCommandObserverMock observer; + command_updater.RemoveCommandObserver(3, &observer); +} + +TEST_F(CommandUpdaterTest, TestAddingNullObserver) { + TestingCommandHandlerMock handler; + CommandUpdater command_updater(&handler); + + // Test adding/removing NULL observers + command_updater.AddCommandObserver(4, NULL); +} + +TEST_F(CommandUpdaterTest, TestRemovingNullObserver) { + TestingCommandHandlerMock handler; + CommandUpdater command_updater(&handler); + + command_updater.RemoveCommandObserver(4, NULL); +} |