OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/autofill/autofill_xml_parser.h" | 9 #include "chrome/browser/autofill/autofill_xml_parser.h" |
10 #include "chrome/browser/autofill/field_types.h" | 10 #include "chrome/browser/autofill/field_types.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 &experiment_id)); | 147 &experiment_id)); |
148 parser.reset(new buzz::XmlParser(parse_handler.get())); | 148 parser.reset(new buzz::XmlParser(parse_handler.get())); |
149 parser->Parse(xml.c_str(), xml.length(), true); | 149 parser->Parse(xml.c_str(), xml.length(), true); |
150 EXPECT_TRUE(parse_handler->succeeded()); | 150 EXPECT_TRUE(parse_handler->succeeded()); |
151 EXPECT_EQ(UPLOAD_NOT_REQUIRED, upload_required); | 151 EXPECT_EQ(UPLOAD_NOT_REQUIRED, upload_required); |
152 ASSERT_EQ(1U, field_types.size()); | 152 ASSERT_EQ(1U, field_types.size()); |
153 EXPECT_EQ(NO_SERVER_DATA, field_types[0]); | 153 EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
154 EXPECT_EQ(std::string("ServerSmartyPants"), experiment_id); | 154 EXPECT_EQ(std::string("ServerSmartyPants"), experiment_id); |
155 } | 155 } |
156 | 156 |
| 157 // Test XML response with autofill_flow information. |
| 158 TEST(AutofillQueryXmlParserTest, ParseAutofillFlow) { |
| 159 std::vector<AutofillFieldType> field_types; |
| 160 UploadRequired upload_required = USE_UPLOAD_RATES; |
| 161 std::string experiment_id; |
| 162 |
| 163 std::string xml = "<autofillqueryresponse>" |
| 164 "<field autofilltype=\"55\"/>" |
| 165 "<autofill_flow page_no=\"1\" total_pages=\"10\"/>" |
| 166 "</autofillqueryresponse>"; |
| 167 |
| 168 scoped_ptr<AutofillQueryXmlParser> parse_handler( |
| 169 new AutofillQueryXmlParser(&field_types, &upload_required, |
| 170 &experiment_id)); |
| 171 scoped_ptr<buzz::XmlParser> parser(new buzz::XmlParser(parse_handler.get())); |
| 172 parser->Parse(xml.c_str(), xml.length(), true); |
| 173 EXPECT_TRUE(parse_handler->succeeded()); |
| 174 EXPECT_EQ(1U, field_types.size()); |
| 175 EXPECT_EQ(1, parse_handler->current_page_number()); |
| 176 EXPECT_EQ(10, parse_handler->total_pages()); |
| 177 } |
| 178 |
157 // Test badly formed XML queries. | 179 // Test badly formed XML queries. |
158 TEST(AutofillQueryXmlParserTest, ParseErrors) { | 180 TEST(AutofillQueryXmlParserTest, ParseErrors) { |
159 std::vector<AutofillFieldType> field_types; | 181 std::vector<AutofillFieldType> field_types; |
160 UploadRequired upload_required = USE_UPLOAD_RATES; | 182 UploadRequired upload_required = USE_UPLOAD_RATES; |
161 std::string experiment_id; | 183 std::string experiment_id; |
162 | 184 |
163 // Test no Autofill type. | 185 // Test no Autofill type. |
164 std::string xml = "<autofillqueryresponse>" | 186 std::string xml = "<autofillqueryresponse>" |
165 "<field/>" | 187 "<field/>" |
166 "</autofillqueryresponse>"; | 188 "</autofillqueryresponse>"; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 xml = ""; | 280 xml = ""; |
259 parse_handler.reset(new AutofillUploadXmlParser(&positive, &negative)); | 281 parse_handler.reset(new AutofillUploadXmlParser(&positive, &negative)); |
260 parser.reset(new buzz::XmlParser(parse_handler.get())); | 282 parser.reset(new buzz::XmlParser(parse_handler.get())); |
261 parser->Parse(xml.c_str(), xml.length(), true); | 283 parser->Parse(xml.c_str(), xml.length(), true); |
262 EXPECT_TRUE(!parse_handler->succeeded()); | 284 EXPECT_TRUE(!parse_handler->succeeded()); |
263 EXPECT_DOUBLE_EQ(0, positive); | 285 EXPECT_DOUBLE_EQ(0, positive); |
264 EXPECT_DOUBLE_EQ(0, negative); | 286 EXPECT_DOUBLE_EQ(0, negative); |
265 } | 287 } |
266 | 288 |
267 } // namespace | 289 } // namespace |
OLD | NEW |