1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/views/crypto_module_password_dialog_view.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/crypto_module_password_dialog.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/views/controls/textfield/textfield.h"
17 class CryptoModulePasswordDialogViewTest
: public testing::Test
{
19 CryptoModulePasswordDialogViewTest() {}
20 virtual ~CryptoModulePasswordDialogViewTest() {}
22 void Capture(const char* text
) {
26 void CreateCryptoDialog(const CryptoModulePasswordCallback
& callback
) {
27 dialog_
.reset(new CryptoModulePasswordDialogView("slot",
28 kCryptoModulePasswordKeygen
, "server", callback
));
31 CryptoModulePasswordCallback
* callback_
;
33 scoped_ptr
<CryptoModulePasswordDialogView
> dialog_
;
36 TEST_F(CryptoModulePasswordDialogViewTest
, TestAccept
) {
37 CryptoModulePasswordCallback
cb(
38 base::Bind(&CryptoModulePasswordDialogViewTest::Capture
,
39 base::Unretained(this)));
40 CreateCryptoDialog(cb
);
41 EXPECT_EQ(dialog_
->password_entry_
, dialog_
->GetInitiallyFocusedView());
42 EXPECT_TRUE(dialog_
->GetModalType() != ui::MODAL_TYPE_NONE
);
43 const std::string kPassword
= "diAl0g";
44 dialog_
->password_entry_
->SetText(ASCIIToUTF16(kPassword
));
45 EXPECT_TRUE(dialog_
->Accept());
46 EXPECT_EQ(kPassword
, text_
);
48 EXPECT_EQ(empty
, dialog_
->password_entry_
->text());