OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 #include <string> |
| 5 |
| 6 #include "base/basictypes.h" |
| 7 #include "base/bind.h" |
| 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 10 #include "chrome/browser/ui/views/crypto_module_password_dialog_view.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/views/controls/textfield/textfield.h" |
| 13 |
| 14 std::string kSlotName = "slot"; |
| 15 std::string kServer = "server"; |
| 16 |
| 17 namespace browser { |
| 18 CryptoModulePasswordReason kReason = kCryptoModulePasswordKeygen; |
| 19 |
| 20 class CryptoModulePasswordDialogViewTest : public testing::Test { |
| 21 public: |
| 22 CryptoModulePasswordDialogViewTest() {} |
| 23 ~CryptoModulePasswordDialogViewTest() {} |
| 24 void Capture(const char* text) { |
| 25 text_ = text; |
| 26 } |
| 27 void CreateDialogCrypto(const CryptoModulePasswordCallback& callback) { |
| 28 dialog_.reset(new CryptoModulePasswordDialogView( |
| 29 kSlotName, kReason, kServer, callback)); |
| 30 } |
| 31 browser::CryptoModulePasswordCallback* callback_; |
| 32 std::string text_; |
| 33 scoped_ptr<CryptoModulePasswordDialogView> dialog_; |
| 34 }; |
| 35 |
| 36 TEST_F(CryptoModulePasswordDialogViewTest, TestAccept) { |
| 37 browser::CryptoModulePasswordCallback cb( |
| 38 base::Bind(&browser::CryptoModulePasswordDialogViewTest::Capture, |
| 39 base::Unretained(this))); |
| 40 CreateDialogCrypto(cb); |
| 41 EXPECT_EQ(dialog_->password_entry_, dialog_->GetInitiallyFocusedView()); |
| 42 EXPECT_TRUE(dialog_->IsModal()); |
| 43 const std::string kPassword = "diAl0g"; |
| 44 dialog_->password_entry_->SetText(UTF8ToUTF16(kPassword)); |
| 45 EXPECT_TRUE(dialog_->Accept()); |
| 46 EXPECT_EQ(kPassword, text_); |
| 47 const string16 empty; |
| 48 EXPECT_EQ(empty, dialog_->password_entry_->text()); |
| 49 } |
| 50 } // namespace browser |
OLD | NEW |