Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: chrome/browser/ui/cocoa/autofill/save_card_bubble_view_unittest.mm

Issue 1757103002: Add explanation text and legal message footer to upload bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/json/json_reader.h"
5 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/values.h"
6 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" 8 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h"
7 #import "chrome/browser/ui/cocoa/autofill/save_card_bubble_view_bridge.h" 9 #import "chrome/browser/ui/cocoa/autofill/save_card_bubble_view_bridge.h"
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
9 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
10 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 #import "ui/events/test/cocoa_test_event_utils.h" 14 #import "ui/events/test/cocoa_test_event_utils.h"
13 15
14 #include <Carbon/Carbon.h> // For the kVK_* constants. 16 #include <Carbon/Carbon.h> // For the kVK_* constants.
15 17
16 namespace autofill { 18 namespace autofill {
17 19
18 namespace { 20 namespace {
19 21
20 class TestSaveCardBubbleController : public SaveCardBubbleController { 22 class TestSaveCardBubbleController : public SaveCardBubbleController {
21 public: 23 public:
22 TestSaveCardBubbleController() { 24 TestSaveCardBubbleController() {
23 lines_.reset(new LegalMessageLines()); 25 std::string message_json =
26 "{"
27 " \"line\" : ["
28 " {"
29 " \"template\": \"Please check out our {0}.\","
30 " \"template_parameter\": ["
31 " {"
32 " \"display_text\": \"terms of service\","
33 " \"url\": \"http://help.example.com/legal_message\""
34 " }"
35 " ]"
36 " },"
37 " {"
38 " \"template\": \"We also have a {0} and {1}.\","
39 " \"template_parameter\": ["
40 " {"
41 " \"display_text\": \"mission statement\","
42 " \"url\": \"http://www.example.com/our_mission\""
43 " },"
44 " {"
45 " \"display_text\": \"privacy policy\","
46 " \"url\": \"http://help.example.com/privacy_policy\""
47 " }"
48 " ]"
49 " }"
50 " ]"
51 "}";
52 scoped_ptr<base::Value> value(base::JSONReader::Read(message_json));
53 base::DictionaryValue* legal_message;
54 value->GetAsDictionary(&legal_message);
groby-ooo-7-16 2016/03/03 00:40:23 ASSERT_TRUE?
Justin Donnelly 2016/03/03 18:45:10 Done. (Required moving this code to a void functio
55 LegalMessageLine::Parse(*legal_message, &lines_);
24 56
25 on_save_button_was_called_ = false; 57 on_save_button_was_called_ = false;
26 on_cancel_button_was_called_ = false; 58 on_cancel_button_was_called_ = false;
27 on_learn_more_was_called_ = false; 59 on_learn_more_was_called_ = false;
60 on_legal_message_was_called_ = false;
28 on_bubble_closed_was_called_ = false; 61 on_bubble_closed_was_called_ = false;
29 } 62 }
30 63
31 // SaveCardBubbleController: 64 // SaveCardBubbleController:
32 base::string16 GetWindowTitle() const override { return base::string16(); } 65 base::string16 GetWindowTitle() const override { return base::string16(); }
33 66
34 base::string16 GetExplanatoryMessage() const override { 67 base::string16 GetExplanatoryMessage() const override {
35 return base::string16(); 68 return base::string16();
36 } 69 }
37 70
38 const CreditCard GetCard() const override { 71 const CreditCard GetCard() const override {
39 return CreditCard(); 72 return CreditCard();
40 } 73 }
41 74
42 void OnSaveButton() override { on_save_button_was_called_ = true; } 75 void OnSaveButton() override { on_save_button_was_called_ = true; }
43 void OnCancelButton() override { on_cancel_button_was_called_ = true; } 76 void OnCancelButton() override { on_cancel_button_was_called_ = true; }
groby-ooo-7-16 2016/03/03 00:40:23 It's not the CL to change this, but this looks lik
Justin Donnelly 2016/03/03 18:45:10 I don't disagree, but some reviewers are enthusias
groby-ooo-7-16 2016/03/07 19:54:58 Argl. If it's more complicated, the likelihood it
Justin Donnelly 2016/03/07 21:21:02 I'm not sure there's anything in all of software e
44 void OnLearnMoreClicked() override { on_learn_more_was_called_ = true; } 77 void OnLearnMoreClicked() override { on_learn_more_was_called_ = true; }
45 void OnLegalMessageLinkClicked(const GURL& url) override {} 78 void OnLegalMessageLinkClicked(const GURL& url) override {
79 on_legal_message_was_called_ = true;
80 legal_message_url_ = url.spec();
81 }
46 void OnBubbleClosed() override { on_bubble_closed_was_called_ = true; } 82 void OnBubbleClosed() override { on_bubble_closed_was_called_ = true; }
47 83
48 const LegalMessageLines& GetLegalMessageLines() const override { 84 const LegalMessageLines& GetLegalMessageLines() const override {
49 return *lines_; 85 return lines_;
50 } 86 }
51 87
52 // Testing state. 88 // Testing state.
53 bool on_save_button_was_called() { return on_save_button_was_called_; } 89 bool on_save_button_was_called() { return on_save_button_was_called_; }
54 bool on_cancel_button_was_called() { return on_cancel_button_was_called_; } 90 bool on_cancel_button_was_called() { return on_cancel_button_was_called_; }
55 bool on_learn_more_was_called() { return on_learn_more_was_called_; } 91 bool on_learn_more_was_called() { return on_learn_more_was_called_; }
92 bool on_legal_message_was_called() { return on_legal_message_was_called_; }
93 std::string legal_message_url() { return legal_message_url_; }
56 bool on_bubble_closed_was_called() { return on_bubble_closed_was_called_; } 94 bool on_bubble_closed_was_called() { return on_bubble_closed_was_called_; }
57 95
58 private: 96 private:
59 scoped_ptr<LegalMessageLines> lines_; 97 LegalMessageLines lines_;
60 98
61 bool on_save_button_was_called_; 99 bool on_save_button_was_called_;
62 bool on_cancel_button_was_called_; 100 bool on_cancel_button_was_called_;
63 bool on_learn_more_was_called_; 101 bool on_learn_more_was_called_;
102 bool on_legal_message_was_called_;
103 std::string legal_message_url_;
64 bool on_bubble_closed_was_called_; 104 bool on_bubble_closed_was_called_;
65 }; 105 };
66 106
67 class SaveCardBubbleViewTest : public CocoaProfileTest { 107 class SaveCardBubbleViewTest : public CocoaProfileTest {
68 public: 108 public:
69 void SetUp() override { 109 void SetUp() override {
70 CocoaProfileTest::SetUp(); 110 CocoaProfileTest::SetUp();
71 ASSERT_TRUE(browser()); 111 ASSERT_TRUE(browser());
72 112
73 browser_window_controller_ = 113 browser_window_controller_ =
(...skipping 19 matching lines...) Expand all
93 }; 133 };
94 134
95 } // namespace 135 } // namespace
96 136
97 TEST_F(SaveCardBubbleViewTest, SaveShouldClose) { 137 TEST_F(SaveCardBubbleViewTest, SaveShouldClose) {
98 [bridge_->view_controller_ onSaveButton:nil]; 138 [bridge_->view_controller_ onSaveButton:nil];
99 139
100 EXPECT_TRUE(bubble_controller_->on_save_button_was_called()); 140 EXPECT_TRUE(bubble_controller_->on_save_button_was_called());
101 EXPECT_FALSE(bubble_controller_->on_cancel_button_was_called()); 141 EXPECT_FALSE(bubble_controller_->on_cancel_button_was_called());
102 EXPECT_FALSE(bubble_controller_->on_learn_more_was_called()); 142 EXPECT_FALSE(bubble_controller_->on_learn_more_was_called());
143 EXPECT_FALSE(bubble_controller_->on_legal_message_was_called());
103 144
104 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called()); 145 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called());
105 } 146 }
106 147
107 TEST_F(SaveCardBubbleViewTest, CancelShouldClose) { 148 TEST_F(SaveCardBubbleViewTest, CancelShouldClose) {
108 [bridge_->view_controller_ onCancelButton:nil]; 149 [bridge_->view_controller_ onCancelButton:nil];
109 150
110 EXPECT_FALSE(bubble_controller_->on_save_button_was_called()); 151 EXPECT_FALSE(bubble_controller_->on_save_button_was_called());
111 EXPECT_TRUE(bubble_controller_->on_cancel_button_was_called()); 152 EXPECT_TRUE(bubble_controller_->on_cancel_button_was_called());
112 EXPECT_FALSE(bubble_controller_->on_learn_more_was_called()); 153 EXPECT_FALSE(bubble_controller_->on_learn_more_was_called());
154 EXPECT_FALSE(bubble_controller_->on_legal_message_was_called());
113 155
114 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called()); 156 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called());
115 } 157 }
116 158
117 TEST_F(SaveCardBubbleViewTest, LearnMoreShouldNotClose) { 159 TEST_F(SaveCardBubbleViewTest, LearnMoreShouldNotClose) {
118 NSTextView* textView = nil; 160 NSTextView* textView = nil;
119 NSObject* link = nil; 161 NSObject* link = nil;
120 [bridge_->view_controller_ textView:textView clickedOnLink:link atIndex:0]; 162 [bridge_->view_controller_ textView:textView clickedOnLink:link atIndex:0];
121 163
122 EXPECT_FALSE(bubble_controller_->on_save_button_was_called()); 164 EXPECT_FALSE(bubble_controller_->on_save_button_was_called());
123 EXPECT_FALSE(bubble_controller_->on_cancel_button_was_called()); 165 EXPECT_FALSE(bubble_controller_->on_cancel_button_was_called());
124 EXPECT_TRUE(bubble_controller_->on_learn_more_was_called()); 166 EXPECT_TRUE(bubble_controller_->on_learn_more_was_called());
167 EXPECT_FALSE(bubble_controller_->on_legal_message_was_called());
125 168
126 EXPECT_FALSE(bubble_controller_->on_bubble_closed_was_called()); 169 EXPECT_FALSE(bubble_controller_->on_bubble_closed_was_called());
127 } 170 }
171
172 TEST_F(SaveCardBubbleViewTest, LegalMessageShouldNotClose) {
173 NSString* legalText = @"We also have a mission statement and privacy policy.";
174 base::scoped_nsobject<NSTextView> textView(
175 [[NSTextView alloc] initWithFrame:NSZeroRect]);
176 base::scoped_nsobject<NSAttributedString> attributedMessage(
177 [[NSAttributedString alloc] initWithString:legalText attributes:@{}]);
178 [[textView textStorage] setAttributedString:attributedMessage];
179
180 NSObject* link = nil;
181 [bridge_->view_controller_ textView:textView clickedOnLink:link atIndex:40];
182
183 EXPECT_FALSE(bubble_controller_->on_save_button_was_called());
184 EXPECT_FALSE(bubble_controller_->on_cancel_button_was_called());
185 EXPECT_FALSE(bubble_controller_->on_learn_more_was_called());
groby-ooo-7-16 2016/03/03 00:40:23 Do these EXPECT_FALSE statements matter?
Justin Donnelly 2016/03/03 18:45:10 I think so. Effective unit tests IMO check both th
groby-ooo-7-16 2016/03/07 19:54:58 Meh... There's an infinite number of unexpected co
Justin Donnelly 2016/03/07 21:21:02 Granted, you can't check them all. But I don't thi
186 EXPECT_TRUE(bubble_controller_->on_legal_message_was_called());
187
188 std::string url("http://help.example.com/privacy_policy");
189 EXPECT_EQ(url, bubble_controller_->legal_message_url());
190
191 EXPECT_FALSE(bubble_controller_->on_bubble_closed_was_called());
192 }
128 193
129 TEST_F(SaveCardBubbleViewTest, ReturnInvokesDefaultAction) { 194 TEST_F(SaveCardBubbleViewTest, ReturnInvokesDefaultAction) {
130 [[bridge_->view_controller_ window] 195 [[bridge_->view_controller_ window]
131 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode( 196 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode(
132 kVK_Return, '\r', NSKeyDown, 0)]; 197 kVK_Return, '\r', NSKeyDown, 0)];
133 198
134 EXPECT_TRUE(bubble_controller_->on_save_button_was_called()); 199 EXPECT_TRUE(bubble_controller_->on_save_button_was_called());
135 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called()); 200 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called());
136 } 201 }
137 202
138 TEST_F(SaveCardBubbleViewTest, EscapeCloses) { 203 TEST_F(SaveCardBubbleViewTest, EscapeCloses) {
139 [[bridge_->view_controller_ window] 204 [[bridge_->view_controller_ window]
140 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode( 205 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode(
141 kVK_Escape, '\e', NSKeyDown, 0)]; 206 kVK_Escape, '\e', NSKeyDown, 0)];
142 207
143 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called()); 208 EXPECT_TRUE(bubble_controller_->on_bubble_closed_was_called());
144 } 209 }
145 210
146 } // namespace autofill 211 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698