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

Side by Side Diff: components/autofill/content/browser/autofill_driver_impl_unittest.cc

Issue 69293007: Abstracted AutofillMsg_SetNodeText IPC out of core autofill code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unittest. Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return false; 137 return false;
138 Tuple1<std::vector<FormDataPredictions> > autofill_param; 138 Tuple1<std::vector<FormDataPredictions> > autofill_param;
139 AutofillMsg_FieldTypePredictionsAvailable::Read(message, &autofill_param); 139 AutofillMsg_FieldTypePredictionsAvailable::Read(message, &autofill_param);
140 if (predictions) 140 if (predictions)
141 *predictions = autofill_param.a; 141 *predictions = autofill_param.a;
142 142
143 process()->sink().ClearMessages(); 143 process()->sink().ClearMessages();
144 return true; 144 return true;
145 } 145 }
146 146
147 // Searches for an |AutofillMsg_SetNodeText| message in the queue of sent IPC
148 // messages. If none is present, returns false. Otherwise, extracts the first
149 // |AutofillMsg_SetNodeText| message, fills the output parameter with the
150 // value of the message's parameter, and clears the queue of sent messages.
151 bool GetSetNodeText(base::string16* value) {
jif-google 2013/11/13 08:24:45 GetSetNodeText could be factored with GetAcceptDat
blundell 2013/11/13 11:55:45 I think it would be worth doing a |GetValueFromMes
jif-google 2013/11/13 14:20:25 Done.
152 const uint32 kMsgID = AutofillMsg_SetNodeText::ID;
153 const IPC::Message* message =
154 process()->sink().GetFirstMessageMatching(kMsgID);
155 if (!message)
156 return false;
157 Tuple1<base::string16> autofill_param;
158 AutofillMsg_SetNodeText::Read(message, &autofill_param);
159 if (value)
160 *value = autofill_param.a;
161 process()->sink().ClearMessages();
162 return true;
163 }
164
147 // Searches for a message matching |messageID| in the queue of sent IPC 165 // Searches for a message matching |messageID| in the queue of sent IPC
148 // messages. If none is present, returns false. Otherwise, clears the queue 166 // messages. If none is present, returns false. Otherwise, clears the queue
149 // of sent messages and returns true. 167 // of sent messages and returns true.
150 bool HasMessageMatchingID(uint32 messageID) { 168 bool HasMessageMatchingID(uint32 messageID) {
151 const IPC::Message* message = 169 const IPC::Message* message =
152 process()->sink().GetFirstMessageMatching(messageID); 170 process()->sink().GetFirstMessageMatching(messageID);
153 if (!message) 171 if (!message)
154 return false; 172 return false;
155 process()->sink().ClearMessages(); 173 process()->sink().ClearMessages();
156 return true; 174 return true;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 TEST_F(AutofillDriverImplTest, ClearFilledFormSentToRenderer) { 260 TEST_F(AutofillDriverImplTest, ClearFilledFormSentToRenderer) {
243 driver_->RendererShouldClearFilledForm(); 261 driver_->RendererShouldClearFilledForm();
244 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearForm::ID)); 262 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearForm::ID));
245 } 263 }
246 264
247 TEST_F(AutofillDriverImplTest, ClearPreviewedFormSentToRenderer) { 265 TEST_F(AutofillDriverImplTest, ClearPreviewedFormSentToRenderer) {
248 driver_->RendererShouldClearPreviewedForm(); 266 driver_->RendererShouldClearPreviewedForm();
249 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearPreviewedForm::ID)); 267 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearPreviewedForm::ID));
250 } 268 }
251 269
270 TEST_F(AutofillDriverImplTest, SetNodeText) {
271 base::string16 inputValue(UTF8ToUTF16("barqux"));
272 base::string16 outputValue;
273 driver_->RendererShouldSetNodeText(inputValue);
274 EXPECT_TRUE(GetSetNodeText(&outputValue));
275 EXPECT_EQ(inputValue, outputValue);
276 }
277
252 } // namespace autofill 278 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698