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..ba5e8b68e26930edbbc253f68fa8533d4118b12f |
--- /dev/null |
+++ b/chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller_unittest.cc |
@@ -0,0 +1,109 @@ |
+// 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 "base/metrics/histogram_samples.h" |
+#include "base/prefs/pref_service.h" |
+#include "base/test/statistics_delta_reader.h" |
+#include "chrome/browser/ui/passwords/manage_passwords_bubble.h" |
+#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
+#include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller_mock.h" |
+#include "chrome/browser/ui/passwords/manage_passwords_icon.h" |
+#include "chrome/browser/ui/passwords/manage_passwords_icon_mock.h" |
+#include "chrome/test/base/testing_profile.h" |
+#include "components/autofill/core/common/password_form.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+#include "content/public/test/web_contents_tester.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+class ManagePasswordsBubbleUIControllerTest : public testing::Test { |
+ public: |
+ ManagePasswordsBubbleUIControllerTest() |
+ : test_web_contents_( |
+ content::WebContentsTester::CreateTestWebContents(&profile_, |
+ NULL)) {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ // Create the test UIController here so that it's bound to |
+ // |test_web_contents_|, and will be retrieved correctly via |
+ // ManagePasswordsBubbleUIController::FromWebContents in |controller()|. |
+ new ManagePasswordsBubbleUIControllerMock(test_web_contents_.get()); |
+ } |
+ |
+ ManagePasswordsBubbleUIControllerMock* controller() { |
+ return reinterpret_cast<ManagePasswordsBubbleUIControllerMock*>( |
+ ManagePasswordsBubbleUIController::FromWebContents( |
+ test_web_contents_.get())); |
+ } |
+ |
+ private: |
+ content::TestBrowserThreadBundle thread_bundle_; |
+ TestingProfile profile_; |
+ scoped_ptr<content::WebContents> test_web_contents_; |
+}; |
+ |
+TEST_F(ManagePasswordsBubbleUIControllerTest, DefaultState) { |
+ EXPECT_FALSE(controller()->autofill_blocked()); |
+ EXPECT_FALSE(controller()->manage_passwords_bubble_needs_showing()); |
+ EXPECT_FALSE(controller()->manage_passwords_icon_to_be_shown()); |
+ EXPECT_FALSE(controller()->never_saved_password()); |
+ EXPECT_FALSE(controller()->password_to_be_saved()); |
+ EXPECT_FALSE(controller()->saved_password()); |
+ |
+ ManagePasswordsIconMock mock; |
+ controller()->UpdateIconAndBubbleState(&mock); |
+ EXPECT_EQ(ManagePasswordsIcon::INACTIVE_STATE, mock.state()); |
+ EXPECT_EQ(0, mock.bubble_shown_count()); |
+} |
+ |
+TEST_F(ManagePasswordsBubbleUIControllerTest, PasswordAutofilled) { |
+ autofill::PasswordFormMap map; |
+ controller()->OnPasswordAutofilled(map); |
+ |
+ EXPECT_TRUE(controller()->manage_passwords_icon_to_be_shown()); |
+ |
+ EXPECT_FALSE(controller()->autofill_blocked()); |
+ EXPECT_FALSE(controller()->manage_passwords_bubble_needs_showing()); |
+ EXPECT_FALSE(controller()->never_saved_password()); |
+ EXPECT_FALSE(controller()->password_to_be_saved()); |
+ EXPECT_FALSE(controller()->saved_password()); |
+ |
+ ManagePasswordsIconMock mock; |
+ controller()->UpdateIconAndBubbleState(&mock); |
+ EXPECT_EQ(ManagePasswordsIcon::MANAGE_STATE, mock.state()); |
+ EXPECT_EQ(0, mock.bubble_shown_count()); |
+} |
+ |
+TEST_F(ManagePasswordsBubbleUIControllerTest, PasswordSubmitted) { |
+ controller()->OnPasswordSubmitted(NULL); |
+ |
+ EXPECT_TRUE(controller()->manage_passwords_bubble_needs_showing()); |
+ EXPECT_TRUE(controller()->manage_passwords_icon_to_be_shown()); |
+ EXPECT_TRUE(controller()->password_to_be_saved()); |
+ |
+ EXPECT_FALSE(controller()->autofill_blocked()); |
+ EXPECT_FALSE(controller()->never_saved_password()); |
+ EXPECT_FALSE(controller()->saved_password()); |
+ |
+ ManagePasswordsIconMock mock; |
+ controller()->UpdateIconAndBubbleState(&mock); |
+ EXPECT_EQ(ManagePasswordsIcon::PENDING_STATE, mock.state()); |
+ EXPECT_EQ(1, mock.bubble_shown_count()); |
+} |
+ |
+TEST_F(ManagePasswordsBubbleUIControllerTest, BlacklistBlockedAutofill) { |
+ controller()->OnBlacklistBlockedAutofill(); |
+ |
+ EXPECT_TRUE(controller()->autofill_blocked()); |
+ EXPECT_TRUE(controller()->manage_passwords_icon_to_be_shown()); |
+ |
+ EXPECT_FALSE(controller()->manage_passwords_bubble_needs_showing()); |
+ EXPECT_FALSE(controller()->never_saved_password()); |
+ EXPECT_FALSE(controller()->password_to_be_saved()); |
+ EXPECT_FALSE(controller()->saved_password()); |
+ |
+ ManagePasswordsIconMock mock; |
+ controller()->UpdateIconAndBubbleState(&mock); |
+ EXPECT_EQ(ManagePasswordsIcon::BLACKLISTED_STATE, mock.state()); |
+ EXPECT_EQ(0, mock.bubble_shown_count()); |
+} |