Chromium Code Reviews| Index: chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller_unittest.cc |
| diff --git a/chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller_unittest.cc b/chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dbed2d69cd4853597db891f2cd3b2e1a48938927 |
| --- /dev/null |
| +++ b/chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller_unittest.cc |
| @@ -0,0 +1,78 @@ |
| +// Copyright 2014 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 "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_command_controller.h" |
| +#include "chrome/browser/ui/browser_window.h" |
| +#include "chrome/test/base/browser_with_test_window_test.h" |
| + |
| +namespace { |
| + |
| +class ManagePasswordsBubbleUIControllerTest : public BrowserWithTestWindowTest { |
| + public: |
| + ManagePasswordsBubbleUIControllerTest() {} |
| + |
| + virtual void SetUp() OVERRIDE { |
| + BrowserWithTestWindowTest::SetUp(); |
| + |
| + // Force the command to be enabled, regardless of icon state. |
| + browser()->command_controller()->command_updater()->UpdateCommandEnabled( |
| + IDC_MANAGE_PASSWORDS_FOR_PAGE, true); |
| + |
| + // Open a tab in which we can play; this will be tab 0. We need to ensure |
| + // that a tab has been opened, as commands don't fire in a tabless window. |
| + AddTab(browser(), GURL("http://foo/")); |
| + } |
| + |
| + void ExecuteManagePasswordsCommand() { |
| + CommandUpdater* updater = |
| + browser()->command_controller()->command_updater(); |
| + ASSERT_TRUE(updater->IsCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE)); |
| + ASSERT_TRUE(updater->ExecuteCommand(IDC_MANAGE_PASSWORDS_FOR_PAGE)); |
| + } |
| + |
| + protected: |
| + class Window : public TestBrowserWindow { |
| + public: |
| + Window() : show_bubble_count_(0) {} |
| + |
| + int show_bubble_count() const { return show_bubble_count_; } |
| + |
| + // TestBrowserWindow: |
| + virtual bool IsActive() const OVERRIDE { return true; } |
| + virtual void ShowManagePasswordsBubble( |
| + content::WebContents* contents) OVERRIDE { |
| + show_bubble_count_++; |
|
vabr (Chromium)
2014/04/23 10:22:31
optional nit:
++show_bubble_count_ seems more appr
|
| + } |
| + |
| + private: |
| + int show_bubble_count_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Window); |
| + }; |
| + |
| + virtual BrowserWindow* CreateBrowserWindow() OVERRIDE { |
| + return new ManagePasswordsBubbleUIControllerTest::Window(); |
| + } |
| + |
| + ManagePasswordsBubbleUIControllerTest::Window* test_window() { |
| + return static_cast<ManagePasswordsBubbleUIControllerTest::Window*>( |
| + browser()->window()); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ManagePasswordsBubbleUIControllerTest); |
| +}; |
| + |
| +TEST_F(ManagePasswordsBubbleUIControllerTest, CommandControlsBubble) { |
| + EXPECT_EQ(0, test_window()->show_bubble_count()); |
| + ExecuteManagePasswordsCommand(); |
| + EXPECT_EQ(1, test_window()->show_bubble_count()); |
| +} |
| + |
| +} // namespace |