OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/crypto_module_password_dialog_view.h" | 5 #include "chrome/browser/ui/views/crypto_module_password_dialog_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/ui/crypto_module_password_dialog.h" | 11 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 12 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/views/controls/textfield/textfield.h" | 14 #include "ui/views/controls/textfield/textfield.h" |
14 #include "ui/views/test/views_test_base.h" | 15 #include "ui/views/test/views_test_base.h" |
15 | 16 |
16 namespace chrome { | 17 namespace chrome { |
17 | 18 |
18 class CryptoModulePasswordDialogViewTest : public views::ViewsTestBase { | 19 class CryptoModulePasswordDialogViewTest : public views::ViewsTestBase { |
19 public: | 20 public: |
20 CryptoModulePasswordDialogViewTest() {} | 21 CryptoModulePasswordDialogViewTest() {} |
21 ~CryptoModulePasswordDialogViewTest() override {} | 22 ~CryptoModulePasswordDialogViewTest() override {} |
22 | 23 |
| 24 // Overrides from views::ViewsTestBase: |
| 25 void SetUp() override { |
| 26 ViewsTestBase::SetUp(); |
| 27 // Set the ChromeLayoutProvider as the default layout provider. |
| 28 test_views_delegate()->set_layout_provider( |
| 29 ChromeLayoutProvider::CreateLayoutProvider()); |
| 30 } |
| 31 |
23 void Capture(const std::string& text) { | 32 void Capture(const std::string& text) { |
24 text_ = text; | 33 text_ = text; |
25 } | 34 } |
26 | 35 |
27 void CreateCryptoDialog(const CryptoModulePasswordCallback& callback) { | 36 void CreateCryptoDialog(const CryptoModulePasswordCallback& callback) { |
28 dialog_.reset(new CryptoModulePasswordDialogView("slot", | 37 dialog_.reset(new CryptoModulePasswordDialogView("slot", |
29 kCryptoModulePasswordCertEnrollment, "server", callback)); | 38 kCryptoModulePasswordCertEnrollment, "server", callback)); |
30 } | 39 } |
31 | 40 |
32 std::string text_; | 41 std::string text_; |
33 std::unique_ptr<CryptoModulePasswordDialogView> dialog_; | 42 std::unique_ptr<CryptoModulePasswordDialogView> dialog_; |
34 }; | 43 }; |
35 | 44 |
36 TEST_F(CryptoModulePasswordDialogViewTest, TestAccept) { | 45 TEST_F(CryptoModulePasswordDialogViewTest, TestAccept) { |
37 CryptoModulePasswordCallback cb( | 46 CryptoModulePasswordCallback cb( |
38 base::Bind(&CryptoModulePasswordDialogViewTest::Capture, | 47 base::Bind(&CryptoModulePasswordDialogViewTest::Capture, |
39 base::Unretained(this))); | 48 base::Unretained(this))); |
40 CreateCryptoDialog(cb); | 49 CreateCryptoDialog(cb); |
41 EXPECT_EQ(dialog_->password_entry_, dialog_->GetInitiallyFocusedView()); | 50 EXPECT_EQ(dialog_->password_entry_, dialog_->GetInitiallyFocusedView()); |
42 EXPECT_TRUE(dialog_->GetModalType() != ui::MODAL_TYPE_NONE); | 51 EXPECT_TRUE(dialog_->GetModalType() != ui::MODAL_TYPE_NONE); |
43 const std::string kPassword = "diAl0g"; | 52 const std::string kPassword = "diAl0g"; |
44 dialog_->password_entry_->SetText(base::ASCIIToUTF16(kPassword)); | 53 dialog_->password_entry_->SetText(base::ASCIIToUTF16(kPassword)); |
45 EXPECT_TRUE(dialog_->Accept()); | 54 EXPECT_TRUE(dialog_->Accept()); |
46 EXPECT_EQ(kPassword, text_); | 55 EXPECT_EQ(kPassword, text_); |
47 const base::string16 empty; | 56 const base::string16 empty; |
48 EXPECT_EQ(empty, dialog_->password_entry_->text()); | 57 EXPECT_EQ(empty, dialog_->password_entry_->text()); |
49 } | 58 } |
50 | 59 |
51 } // namespace chrome | 60 } // namespace chrome |
OLD | NEW |