OLD | NEW |
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 | 76 |
77 virtual void TearDown() OVERRIDE { | 77 virtual void TearDown() OVERRIDE { |
78 // Reset the driver now to cause all pref observers to be removed and avoid | 78 // Reset the driver now to cause all pref observers to be removed and avoid |
79 // crashes that otherwise occur in the destructor. | 79 // crashes that otherwise occur in the destructor. |
80 driver_.reset(); | 80 driver_.reset(); |
81 ChromeRenderViewHostTestHarness::TearDown(); | 81 ChromeRenderViewHostTestHarness::TearDown(); |
82 } | 82 } |
83 | 83 |
84 protected: | 84 protected: |
85 // Searches for an |AutofillMsg_AcceptDataListSuggestion| message in the queue | |
86 // of sent IPC messages. If none is present, returns false. Otherwise, | |
87 // extracts the first |AutofillMsg_AcceptDataListSuggestion| message, fills | |
88 // the output parameter with the value of the message's parameter, and clears | |
89 // the queue of sent messages. | |
90 bool GetAcceptDataListSuggestion( | |
91 base::string16* value) { | |
92 const uint32 kMsgID = AutofillMsg_AcceptDataListSuggestion::ID; | |
93 const IPC::Message* message = | |
94 process()->sink().GetFirstMessageMatching(kMsgID); | |
95 if (!message) | |
96 return false; | |
97 Tuple1<base::string16> autofill_param; | |
98 AutofillMsg_AcceptDataListSuggestion::Read(message, &autofill_param); | |
99 if (value) | |
100 *value = autofill_param.a; | |
101 process()->sink().ClearMessages(); | |
102 return true; | |
103 } | |
104 | |
105 // Searches for an |AutofillMsg_FormDataFilled| message in the queue of sent | 85 // Searches for an |AutofillMsg_FormDataFilled| message in the queue of sent |
106 // IPC messages. If none is present, returns false. Otherwise, extracts the | 86 // IPC messages. If none is present, returns false. Otherwise, extracts the |
107 // first |AutofillMsg_FormDataFilled| message, fills the output parameters | 87 // first |AutofillMsg_FormDataFilled| message, fills the output parameters |
108 // with the values of the message's parameters, and clears the queue of sent | 88 // with the values of the message's parameters, and clears the queue of sent |
109 // messages. | 89 // messages. |
110 bool GetAutofillFormDataFilledMessage(int* page_id, FormData* results) { | 90 bool GetAutofillFormDataFilledMessage(int* page_id, FormData* results) { |
111 const uint32 kMsgID = AutofillMsg_FormDataFilled::ID; | 91 const uint32 kMsgID = AutofillMsg_FormDataFilled::ID; |
112 const IPC::Message* message = | 92 const IPC::Message* message = |
113 process()->sink().GetFirstMessageMatching(kMsgID); | 93 process()->sink().GetFirstMessageMatching(kMsgID); |
114 if (!message) | 94 if (!message) |
(...skipping 23 matching lines...) Expand all Loading... |
138 Tuple1<std::vector<FormDataPredictions> > autofill_param; | 118 Tuple1<std::vector<FormDataPredictions> > autofill_param; |
139 AutofillMsg_FieldTypePredictionsAvailable::Read(message, &autofill_param); | 119 AutofillMsg_FieldTypePredictionsAvailable::Read(message, &autofill_param); |
140 if (predictions) | 120 if (predictions) |
141 *predictions = autofill_param.a; | 121 *predictions = autofill_param.a; |
142 | 122 |
143 process()->sink().ClearMessages(); | 123 process()->sink().ClearMessages(); |
144 return true; | 124 return true; |
145 } | 125 } |
146 | 126 |
147 // Searches for a message matching |messageID| in the queue of sent IPC | 127 // Searches for a message matching |messageID| in the queue of sent IPC |
| 128 // messages. If none is present, returns false. Otherwise, extracts the first |
| 129 // matching message, fills the output parameter with the string16 from the |
| 130 // message's parameter, and clears the queue of sent messages. |
| 131 bool GetString16FromMessageWithID(uint32 messageID, base::string16* value) { |
| 132 const IPC::Message* message = |
| 133 process()->sink().GetFirstMessageMatching(messageID); |
| 134 if (!message) |
| 135 return false; |
| 136 Tuple1<base::string16> autofill_param; |
| 137 switch (messageID) { |
| 138 case AutofillMsg_SetNodeText::ID: |
| 139 AutofillMsg_SetNodeText::Read(message, &autofill_param); |
| 140 break; |
| 141 case AutofillMsg_AcceptDataListSuggestion::ID: |
| 142 AutofillMsg_AcceptDataListSuggestion::Read(message, &autofill_param); |
| 143 break; |
| 144 default: |
| 145 NOTREACHED(); |
| 146 } |
| 147 if (value) |
| 148 *value = autofill_param.a; |
| 149 process()->sink().ClearMessages(); |
| 150 return true; |
| 151 } |
| 152 |
| 153 // Searches for a message matching |messageID| in the queue of sent IPC |
148 // messages. If none is present, returns false. Otherwise, clears the queue | 154 // messages. If none is present, returns false. Otherwise, clears the queue |
149 // of sent messages and returns true. | 155 // of sent messages and returns true. |
150 bool HasMessageMatchingID(uint32 messageID) { | 156 bool HasMessageMatchingID(uint32 messageID) { |
151 const IPC::Message* message = | 157 const IPC::Message* message = |
152 process()->sink().GetFirstMessageMatching(messageID); | 158 process()->sink().GetFirstMessageMatching(messageID); |
153 if (!message) | 159 if (!message) |
154 return false; | 160 return false; |
155 process()->sink().ClearMessages(); | 161 process()->sink().ClearMessages(); |
156 return true; | 162 return true; |
157 } | 163 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_SetAutofillActionPreview::ID)); | 231 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_SetAutofillActionPreview::ID)); |
226 } | 232 } |
227 | 233 |
228 TEST_F(AutofillDriverImplTest, FillActionSentToRenderer) { | 234 TEST_F(AutofillDriverImplTest, FillActionSentToRenderer) { |
229 driver_->SetRendererActionOnFormDataReception( | 235 driver_->SetRendererActionOnFormDataReception( |
230 AutofillDriver::FORM_DATA_ACTION_FILL); | 236 AutofillDriver::FORM_DATA_ACTION_FILL); |
231 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_SetAutofillActionFill::ID)); | 237 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_SetAutofillActionFill::ID)); |
232 } | 238 } |
233 | 239 |
234 TEST_F(AutofillDriverImplTest, AcceptDataListSuggestion) { | 240 TEST_F(AutofillDriverImplTest, AcceptDataListSuggestion) { |
235 base::string16 inputValue(UTF8ToUTF16("barfoo")); | 241 base::string16 input_value(ASCIIToUTF16("barfoo")); |
236 base::string16 outputValue; | 242 base::string16 output_value; |
237 driver_->RendererShouldAcceptDataListSuggestion(inputValue); | 243 driver_->RendererShouldAcceptDataListSuggestion(input_value); |
238 EXPECT_TRUE(GetAcceptDataListSuggestion(&outputValue)); | 244 EXPECT_TRUE(GetString16FromMessageWithID( |
239 EXPECT_EQ(inputValue, outputValue); | 245 AutofillMsg_AcceptDataListSuggestion::ID, |
| 246 &output_value)); |
| 247 EXPECT_EQ(input_value, output_value); |
240 } | 248 } |
241 | 249 |
242 TEST_F(AutofillDriverImplTest, ClearFilledFormSentToRenderer) { | 250 TEST_F(AutofillDriverImplTest, ClearFilledFormSentToRenderer) { |
243 driver_->RendererShouldClearFilledForm(); | 251 driver_->RendererShouldClearFilledForm(); |
244 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearForm::ID)); | 252 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearForm::ID)); |
245 } | 253 } |
246 | 254 |
247 TEST_F(AutofillDriverImplTest, ClearPreviewedFormSentToRenderer) { | 255 TEST_F(AutofillDriverImplTest, ClearPreviewedFormSentToRenderer) { |
248 driver_->RendererShouldClearPreviewedForm(); | 256 driver_->RendererShouldClearPreviewedForm(); |
249 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearPreviewedForm::ID)); | 257 EXPECT_TRUE(HasMessageMatchingID(AutofillMsg_ClearPreviewedForm::ID)); |
250 } | 258 } |
251 | 259 |
| 260 TEST_F(AutofillDriverImplTest, SetNodeText) { |
| 261 base::string16 input_value(ASCIIToUTF16("barqux")); |
| 262 base::string16 output_value; |
| 263 driver_->RendererShouldSetNodeText(input_value); |
| 264 EXPECT_TRUE(GetString16FromMessageWithID(AutofillMsg_SetNodeText::ID, |
| 265 &output_value)); |
| 266 EXPECT_EQ(input_value, output_value); |
| 267 } |
| 268 |
252 } // namespace autofill | 269 } // namespace autofill |
OLD | NEW |