OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <Carbon/Carbon.h> // For the kVK_* constants. | 5 #include <Carbon/Carbon.h> // For the kVK_* constants. |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" | |
12 #import "chrome/browser/ui/cocoa/autofill/save_card_bubble_view_bridge.h" | 11 #import "chrome/browser/ui/cocoa/autofill/save_card_bubble_view_bridge.h" |
13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
14 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" | 13 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" |
15 #include "components/autofill/core/browser/credit_card.h" | 14 #include "components/autofill/core/browser/credit_card.h" |
| 15 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #import "ui/events/test/cocoa_test_event_utils.h" | 18 #import "ui/events/test/cocoa_test_event_utils.h" |
18 | 19 |
19 namespace autofill { | 20 namespace autofill { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 class TestSaveCardBubbleController : public SaveCardBubbleController { | 24 class TestSaveCardBubbleController : public SaveCardBubbleController { |
24 public: | 25 public: |
25 TestSaveCardBubbleController() { | 26 TestSaveCardBubbleController() { |
26 ParseLegalMessageJson(); | 27 ParseLegalMessageJson(); |
27 | 28 |
28 on_save_button_was_called_ = false; | 29 on_save_button_was_called_ = false; |
29 on_cancel_button_was_called_ = false; | 30 on_cancel_button_was_called_ = false; |
30 on_learn_more_was_called_ = false; | 31 on_learn_more_was_called_ = false; |
31 on_legal_message_was_called_ = false; | 32 on_legal_message_was_called_ = false; |
32 on_bubble_closed_was_called_ = false; | 33 on_bubble_closed_was_called_ = false; |
33 } | 34 } |
34 | 35 |
35 // SaveCardBubbleController: | 36 // SaveCardBubbleController: |
36 base::string16 GetWindowTitle() const override { return base::string16(); } | 37 MOCK_CONST_METHOD0(GetWindowTitle, base::string16()); |
| 38 MOCK_CONST_METHOD0(GetExplanatoryMessage, base::string16()); |
| 39 MOCK_CONST_METHOD0(GetCard, const CreditCard()); |
| 40 MOCK_CONST_METHOD0(GetCvcImageResourceId, int()); |
| 41 MOCK_CONST_METHOD0(ShouldRequestCvcFromUser, bool()); |
| 42 MOCK_CONST_METHOD0(GetCvcEnteredByUser, base::string16()); |
37 | 43 |
38 base::string16 GetExplanatoryMessage() const override { | 44 void OnSaveButton(const base::string16& cvc) override { |
39 return base::string16(); | 45 on_save_button_was_called_ = true; |
40 } | 46 } |
41 | |
42 const CreditCard GetCard() const override { | |
43 return CreditCard(); | |
44 } | |
45 | |
46 void OnSaveButton() override { on_save_button_was_called_ = true; } | |
47 void OnCancelButton() override { on_cancel_button_was_called_ = true; } | 47 void OnCancelButton() override { on_cancel_button_was_called_ = true; } |
48 void OnLearnMoreClicked() override { on_learn_more_was_called_ = true; } | 48 void OnLearnMoreClicked() override { on_learn_more_was_called_ = true; } |
49 void OnLegalMessageLinkClicked(const GURL& url) override { | 49 void OnLegalMessageLinkClicked(const GURL& url) override { |
50 on_legal_message_was_called_ = true; | 50 on_legal_message_was_called_ = true; |
51 legal_message_url_ = url.spec(); | 51 legal_message_url_ = url.spec(); |
52 } | 52 } |
53 void OnBubbleClosed() override { on_bubble_closed_was_called_ = true; } | 53 void OnBubbleClosed() override { on_bubble_closed_was_called_ = true; } |
54 | 54 |
55 const LegalMessageLines& GetLegalMessageLines() const override { | 55 const LegalMessageLines& GetLegalMessageLines() const override { |
56 return lines_; | 56 return lines_; |
57 } | 57 } |
58 | 58 |
| 59 MOCK_CONST_METHOD1(InputCvcIsValid, bool(const base::string16& input_text)); |
| 60 |
59 // Testing state. | 61 // Testing state. |
60 bool on_save_button_was_called() { return on_save_button_was_called_; } | 62 bool on_save_button_was_called() { return on_save_button_was_called_; } |
61 bool on_cancel_button_was_called() { return on_cancel_button_was_called_; } | 63 bool on_cancel_button_was_called() { return on_cancel_button_was_called_; } |
62 bool on_learn_more_was_called() { return on_learn_more_was_called_; } | 64 bool on_learn_more_was_called() { return on_learn_more_was_called_; } |
63 bool on_legal_message_was_called() { return on_legal_message_was_called_; } | 65 bool on_legal_message_was_called() { return on_legal_message_was_called_; } |
64 std::string legal_message_url() { return legal_message_url_; } | 66 std::string legal_message_url() { return legal_message_url_; } |
65 bool on_bubble_closed_was_called() { return on_bubble_closed_was_called_; } | 67 bool on_bubble_closed_was_called() { return on_bubble_closed_was_called_; } |
66 | 68 |
67 private: | 69 private: |
68 void ParseLegalMessageJson() { | 70 void ParseLegalMessageJson() { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 210 |
209 TEST_F(SaveCardBubbleViewTest, EscapeCloses) { | 211 TEST_F(SaveCardBubbleViewTest, EscapeCloses) { |
210 [[bridge_->view_controller_ window] | 212 [[bridge_->view_controller_ window] |
211 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode( | 213 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode( |
212 kVK_Escape, '\e', NSKeyDown, 0)]; | 214 kVK_Escape, '\e', NSKeyDown, 0)]; |
213 | 215 |
214 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called()); | 216 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called()); |
215 } | 217 } |
216 | 218 |
217 } // namespace autofill | 219 } // namespace autofill |
OLD | NEW |