Index: chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller_unittest.mm |
diff --git a/chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller_unittest.mm b/chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller_unittest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cb7136e5c67d9046888b95a6af4fccebdb2c888c |
--- /dev/null |
+++ b/chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller_unittest.mm |
@@ -0,0 +1,89 @@ |
+// 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. |
+ |
+#import "chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller.h" |
+ |
+#include "base/mac/foundation_util.h" |
+#include "base/mac/scoped_nsobject.h" |
+#include "base/strings/string16.h" |
+#include "base/strings/sys_string_conversions.h" |
+#include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
+#include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
+#import "chrome/browser/ui/cocoa/passwords/manage_password_item_view_controller.h" |
+#include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
+#include "chrome/browser/ui/passwords/manage_passwords_ui_controller_mock.h" |
+#include "chrome/test/base/testing_profile.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" |
+#include "testing/gtest_mac.h" |
+ |
+namespace { |
+static const CGFloat kArbitraryWidth = 500; |
+} // namespace |
+ |
+class ManagePasswordItemViewControllerTest : public CocoaTest { |
+ public: |
+ ManagePasswordItemViewControllerTest() |
+ : test_web_contents_( |
+ content::WebContentsTester::CreateTestWebContents(&profile_, |
+ NULL)) {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ CocoaTest::SetUp(); |
+ // Create the test UIController here so that it's bound to |
+ // |test_web_contents_| and therefore accessible to the model. |
+ ui_controller_ = |
+ new ManagePasswordsUIControllerMock(test_web_contents_.get()); |
Scott Hess - ex-Googler
2014/08/06 17:56:38
This is marked weak, so it's owned by test_web_con
dconnelly
2014/08/07 13:10:05
Comment updated.
|
+ } |
+ |
+ protected: |
+ base::scoped_nsobject<ManagePasswordItemViewController> controller_; |
+ scoped_ptr<ManagePasswordsBubbleModel> model_; |
Scott Hess - ex-Googler
2014/08/06 17:56:38
Since they aren't setup by the test class, why are
dconnelly
2014/08/07 13:10:05
Done.
|
+ ManagePasswordsUIControllerMock* ui_controller_; // weak |
+ content::TestBrowserThreadBundle thread_bundle_; |
+ TestingProfile profile_; |
+ scoped_ptr<content::WebContents> test_web_contents_; |
+}; |
+ |
+TEST_F(ManagePasswordItemViewControllerTest, |
+ PendingStateShouldHavePendingView) { |
+ model_.reset(new ManagePasswordsBubbleModel(test_web_contents_.get())); |
+ model_->set_state(password_manager::ui::PENDING_PASSWORD_STATE); |
+ controller_.reset([[ManagePasswordItemViewController alloc] |
+ initWithModel:model_.get() |
+ position:password_manager::ui::FIRST_ITEM |
+ minWidth:kArbitraryWidth]); |
+ EXPECT_EQ(MANAGE_PASSWORD_ITEM_STATE_PENDING, [controller_ state]); |
+ EXPECT_NSEQ([ManagePasswordItemPendingView class], |
+ [[controller_ contentView] class]); |
+} |
+ |
+TEST_F(ManagePasswordItemViewControllerTest, |
+ PendingViewShouldHaveCorrectUsernameAndObscuredPassword) { |
+ // Set the pending credentials. |
+ autofill::PasswordForm form; |
+ NSString* username = @"foo"; |
+ NSString* password = @"bar"; |
Scott Hess - ex-Googler
2014/08/06 17:56:38
NSString* const kUsername, etc.
dconnelly
2014/08/07 13:10:05
For some bizarre reason, SysNSStringToUTF16 doesn'
Scott Hess - ex-Googler
2014/08/07 22:05:33
Are you saying "const NSString* kUsername" (pointe
dconnelly
2014/08/08 08:25:59
I was being dumb. Done.
|
+ form.username_value = base::SysNSStringToUTF16(username); |
+ form.password_value = base::SysNSStringToUTF16(password); |
+ ui_controller_->SetPendingCredentials(form); |
+ ui_controller_->SetState(password_manager::ui::PENDING_PASSWORD_STATE); |
+ |
+ // Model must be created after the credentials are set. |
+ model_.reset(new ManagePasswordsBubbleModel(test_web_contents_.get())); |
+ |
+ controller_.reset([[ManagePasswordItemViewController alloc] |
+ initWithModel:model_.get() |
+ position:password_manager::ui::FIRST_ITEM |
+ minWidth:kArbitraryWidth]); |
+ ManagePasswordItemPendingView* pendingView = |
+ base::mac::ObjCCast<ManagePasswordItemPendingView>( |
+ [controller_ contentView]); |
+ |
+ // Ensure the fields are populated properly and the password is obscured. |
+ EXPECT_NSEQ(username, pendingView.usernameField.stringValue); |
+ EXPECT_NSEQ(password, pendingView.passwordField.stringValue); |
+ EXPECT_TRUE([[pendingView.passwordField cell] echosBullets]); |
+} |