[email protected] | 7b37fbb | 2011-03-07 16:16:03 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <string> |
| 6 | #include <vector> |
| 7 | |
[email protected] | 8bb74637 | 2012-04-26 04:20:12 | [diff] [blame] | 8 | #include "base/memory/scoped_ptr.h" |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 9 | #include "chrome/browser/autofill/autofill_xml_parser.h" |
| 10 | #include "chrome/browser/autofill/field_types.h" |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 7b7a16b | 2010-06-03 04:08:18 | [diff] [blame] | 12 | #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 13 | |
| 14 | namespace { |
| 15 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 16 | TEST(AutofillQueryXmlParserTest, BasicQuery) { |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 17 | // An XML string representing a basic query response. |
| 18 | std::string xml = "<autofillqueryresponse>" |
| 19 | "<field autofilltype=\"0\" />" |
| 20 | "<field autofilltype=\"1\" />" |
| 21 | "<field autofilltype=\"3\" />" |
| 22 | "<field autofilltype=\"2\" />" |
| 23 | "</autofillqueryresponse>"; |
| 24 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 25 | // Create a vector of AutofillFieldTypes, to assign the parsed field types to. |
| 26 | std::vector<AutofillFieldType> field_types; |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 27 | UploadRequired upload_required = USE_UPLOAD_RATES; |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 28 | std::string experiment_id; |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 29 | |
| 30 | // Create a parser. |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 31 | AutofillQueryXmlParser parse_handler(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 32 | &experiment_id); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 33 | buzz::XmlParser parser(&parse_handler); |
| 34 | parser.Parse(xml.c_str(), xml.length(), true); |
| 35 | EXPECT_TRUE(parse_handler.succeeded()); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 36 | EXPECT_EQ(USE_UPLOAD_RATES, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 37 | ASSERT_EQ(4U, field_types.size()); |
| 38 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
| 39 | EXPECT_EQ(UNKNOWN_TYPE, field_types[1]); |
| 40 | EXPECT_EQ(NAME_FIRST, field_types[2]); |
| 41 | EXPECT_EQ(EMPTY_TYPE, field_types[3]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 42 | EXPECT_EQ(std::string(), experiment_id); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // Test parsing the upload required attribute. |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 46 | TEST(AutofillQueryXmlParserTest, TestUploadRequired) { |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 47 | std::vector<AutofillFieldType> field_types; |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 48 | UploadRequired upload_required = USE_UPLOAD_RATES; |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 49 | std::string experiment_id; |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 50 | |
| 51 | std::string xml = "<autofillqueryresponse uploadrequired=\"true\">" |
| 52 | "<field autofilltype=\"0\" />" |
| 53 | "</autofillqueryresponse>"; |
| 54 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 55 | scoped_ptr<AutofillQueryXmlParser> parse_handler( |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 56 | new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 57 | &experiment_id)); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 58 | scoped_ptr<buzz::XmlParser> parser(new buzz::XmlParser(parse_handler.get())); |
| 59 | parser->Parse(xml.c_str(), xml.length(), true); |
| 60 | EXPECT_TRUE(parse_handler->succeeded()); |
| 61 | EXPECT_EQ(UPLOAD_REQUIRED, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 62 | ASSERT_EQ(1U, field_types.size()); |
| 63 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 64 | EXPECT_EQ(std::string(), experiment_id); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 65 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 66 | field_types.clear(); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 67 | xml = "<autofillqueryresponse uploadrequired=\"false\">" |
| 68 | "<field autofilltype=\"0\" />" |
| 69 | "</autofillqueryresponse>"; |
| 70 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 71 | parse_handler.reset(new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 72 | &experiment_id)); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 73 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 74 | parser->Parse(xml.c_str(), xml.length(), true); |
| 75 | EXPECT_TRUE(parse_handler->succeeded()); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 76 | EXPECT_EQ(UPLOAD_NOT_REQUIRED, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 77 | ASSERT_EQ(1U, field_types.size()); |
| 78 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 79 | EXPECT_EQ(std::string(), experiment_id); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 80 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 81 | field_types.clear(); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 82 | xml = "<autofillqueryresponse uploadrequired=\"bad_value\">" |
| 83 | "<field autofilltype=\"0\" />" |
| 84 | "</autofillqueryresponse>"; |
| 85 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 86 | parse_handler.reset(new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 87 | &experiment_id)); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 88 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 89 | parser->Parse(xml.c_str(), xml.length(), true); |
| 90 | EXPECT_TRUE(parse_handler->succeeded()); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 91 | EXPECT_EQ(USE_UPLOAD_RATES, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 92 | ASSERT_EQ(1U, field_types.size()); |
| 93 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 94 | EXPECT_EQ(std::string(), experiment_id); |
| 95 | } |
| 96 | |
| 97 | // Test parsing the experiment id attribute |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 98 | TEST(AutofillQueryXmlParserTest, ParseExperimentId) { |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 99 | std::vector<AutofillFieldType> field_types; |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 100 | UploadRequired upload_required = USE_UPLOAD_RATES; |
| 101 | std::string experiment_id; |
| 102 | |
| 103 | // When the attribute is missing, we should get back the default value -- the |
| 104 | // empty string. |
| 105 | std::string xml = "<autofillqueryresponse>" |
| 106 | "<field autofilltype=\"0\" />" |
| 107 | "</autofillqueryresponse>"; |
| 108 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 109 | scoped_ptr<AutofillQueryXmlParser> parse_handler( |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 110 | new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 111 | &experiment_id)); |
| 112 | scoped_ptr<buzz::XmlParser> parser(new buzz::XmlParser(parse_handler.get())); |
| 113 | parser->Parse(xml.c_str(), xml.length(), true); |
| 114 | EXPECT_TRUE(parse_handler->succeeded()); |
| 115 | EXPECT_EQ(USE_UPLOAD_RATES, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 116 | ASSERT_EQ(1U, field_types.size()); |
| 117 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 118 | EXPECT_EQ(std::string(), experiment_id); |
| 119 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 120 | field_types.clear(); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 121 | |
| 122 | // When the attribute is present, make sure we parse it. |
| 123 | xml = "<autofillqueryresponse experimentid=\"FancyNewAlgorithm\">" |
| 124 | "<field autofilltype=\"0\" />" |
| 125 | "</autofillqueryresponse>"; |
| 126 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 127 | parse_handler.reset(new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 128 | &experiment_id)); |
| 129 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 130 | parser->Parse(xml.c_str(), xml.length(), true); |
| 131 | EXPECT_TRUE(parse_handler->succeeded()); |
| 132 | EXPECT_EQ(USE_UPLOAD_RATES, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 133 | ASSERT_EQ(1U, field_types.size()); |
| 134 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 135 | EXPECT_EQ(std::string("FancyNewAlgorithm"), experiment_id); |
| 136 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 137 | field_types.clear(); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 138 | |
| 139 | // Make sure that we can handle parsing both the upload required and the |
| 140 | // experiment id attribute together. |
| 141 | xml = "<autofillqueryresponse uploadrequired=\"false\"" |
| 142 | " experimentid=\"ServerSmartyPants\">" |
| 143 | "<field autofilltype=\"0\" />" |
| 144 | "</autofillqueryresponse>"; |
| 145 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 146 | parse_handler.reset(new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 147 | &experiment_id)); |
| 148 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 149 | parser->Parse(xml.c_str(), xml.length(), true); |
| 150 | EXPECT_TRUE(parse_handler->succeeded()); |
| 151 | EXPECT_EQ(UPLOAD_NOT_REQUIRED, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 152 | ASSERT_EQ(1U, field_types.size()); |
| 153 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 154 | EXPECT_EQ(std::string("ServerSmartyPants"), experiment_id); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 155 | } |
| 156 | |
[email protected] | e899b96 | 2013-01-18 20:52:08 | [diff] [blame^] | 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 | |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 179 | // Test badly formed XML queries. |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 180 | TEST(AutofillQueryXmlParserTest, ParseErrors) { |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 181 | std::vector<AutofillFieldType> field_types; |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 182 | UploadRequired upload_required = USE_UPLOAD_RATES; |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 183 | std::string experiment_id; |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 184 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 185 | // Test no Autofill type. |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 186 | std::string xml = "<autofillqueryresponse>" |
| 187 | "<field/>" |
| 188 | "</autofillqueryresponse>"; |
| 189 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 190 | scoped_ptr<AutofillQueryXmlParser> parse_handler( |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 191 | new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 192 | &experiment_id)); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 193 | scoped_ptr<buzz::XmlParser> parser(new buzz::XmlParser(parse_handler.get())); |
| 194 | parser->Parse(xml.c_str(), xml.length(), true); |
| 195 | EXPECT_FALSE(parse_handler->succeeded()); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 196 | EXPECT_EQ(USE_UPLOAD_RATES, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 197 | EXPECT_EQ(0U, field_types.size()); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 198 | EXPECT_EQ(std::string(), experiment_id); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 199 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 200 | // Test an incorrect Autofill type. |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 201 | xml = "<autofillqueryresponse>" |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 202 | "<field autofilltype=\"307\"/>" |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 203 | "</autofillqueryresponse>"; |
| 204 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 205 | parse_handler.reset(new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 206 | &experiment_id)); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 207 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 208 | parser->Parse(xml.c_str(), xml.length(), true); |
| 209 | EXPECT_TRUE(parse_handler->succeeded()); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 210 | EXPECT_EQ(USE_UPLOAD_RATES, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 211 | ASSERT_EQ(1U, field_types.size()); |
[email protected] | 7b37fbb | 2011-03-07 16:16:03 | [diff] [blame] | 212 | // AutofillType was out of range and should be set to NO_SERVER_DATA. |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 213 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 214 | EXPECT_EQ(std::string(), experiment_id); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 215 | |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 216 | // Test an incorrect Autofill type. |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 217 | field_types.clear(); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 218 | xml = "<autofillqueryresponse>" |
| 219 | "<field autofilltype=\"No Type\"/>" |
| 220 | "</autofillqueryresponse>"; |
| 221 | |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 222 | // Parse fails but an entry is still added to field_types. |
| 223 | parse_handler.reset(new AutofillQueryXmlParser(&field_types, &upload_required, |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 224 | &experiment_id)); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 225 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 226 | parser->Parse(xml.c_str(), xml.length(), true); |
| 227 | EXPECT_FALSE(parse_handler->succeeded()); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 228 | EXPECT_EQ(USE_UPLOAD_RATES, upload_required); |
[email protected] | 606d1080 | 2013-01-14 18:14:57 | [diff] [blame] | 229 | ASSERT_EQ(1U, field_types.size()); |
| 230 | EXPECT_EQ(NO_SERVER_DATA, field_types[0]); |
[email protected] | 5f372f8 | 2011-01-31 23:20:50 | [diff] [blame] | 231 | EXPECT_EQ(std::string(), experiment_id); |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 232 | } |
| 233 | |
[email protected] | db16347 | 2010-04-02 22:01:20 | [diff] [blame] | 234 | // Test successfull upload response. |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 235 | TEST(AutofillUploadXmlParser, TestSuccessfulResponse) { |
[email protected] | db16347 | 2010-04-02 22:01:20 | [diff] [blame] | 236 | std::string xml = "<autofilluploadresponse positiveuploadrate=\"0.5\" " |
| 237 | "negativeuploadrate=\"0.3\"/>"; |
| 238 | double positive = 0; |
| 239 | double negative = 0; |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 240 | AutofillUploadXmlParser parse_handler(&positive, &negative); |
[email protected] | db16347 | 2010-04-02 22:01:20 | [diff] [blame] | 241 | buzz::XmlParser parser(&parse_handler); |
| 242 | parser.Parse(xml.c_str(), xml.length(), true); |
| 243 | EXPECT_TRUE(parse_handler.succeeded()); |
| 244 | EXPECT_DOUBLE_EQ(0.5, positive); |
| 245 | EXPECT_DOUBLE_EQ(0.3, negative); |
| 246 | } |
| 247 | |
| 248 | // Test failed upload response. |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 249 | TEST(AutofillUploadXmlParser, TestFailedResponse) { |
[email protected] | db16347 | 2010-04-02 22:01:20 | [diff] [blame] | 250 | std::string xml = "<autofilluploadresponse positiveuploadrate=\"\" " |
| 251 | "negativeuploadrate=\"0.3\"/>"; |
| 252 | double positive = 0; |
| 253 | double negative = 0; |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 254 | scoped_ptr<AutofillUploadXmlParser> parse_handler( |
| 255 | new AutofillUploadXmlParser(&positive, &negative)); |
[email protected] | db16347 | 2010-04-02 22:01:20 | [diff] [blame] | 256 | scoped_ptr<buzz::XmlParser> parser(new buzz::XmlParser(parse_handler.get())); |
| 257 | parser->Parse(xml.c_str(), xml.length(), true); |
| 258 | EXPECT_TRUE(!parse_handler->succeeded()); |
| 259 | EXPECT_DOUBLE_EQ(0, positive); |
| 260 | EXPECT_DOUBLE_EQ(0.3, negative); // Partially parsed. |
| 261 | negative = 0; |
| 262 | |
| 263 | xml = "<autofilluploadresponse positiveuploadrate=\"0.5\" " |
| 264 | "negativeuploadrate=\"0.3\""; |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 265 | parse_handler.reset(new AutofillUploadXmlParser(&positive, &negative)); |
[email protected] | db16347 | 2010-04-02 22:01:20 | [diff] [blame] | 266 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 267 | parser->Parse(xml.c_str(), xml.length(), true); |
| 268 | EXPECT_TRUE(!parse_handler->succeeded()); |
| 269 | EXPECT_DOUBLE_EQ(0, positive); |
| 270 | EXPECT_DOUBLE_EQ(0, negative); |
| 271 | |
| 272 | xml = "bad data"; |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 273 | parse_handler.reset(new AutofillUploadXmlParser(&positive, &negative)); |
[email protected] | db16347 | 2010-04-02 22:01:20 | [diff] [blame] | 274 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 275 | parser->Parse(xml.c_str(), xml.length(), true); |
| 276 | EXPECT_TRUE(!parse_handler->succeeded()); |
| 277 | EXPECT_DOUBLE_EQ(0, positive); |
| 278 | EXPECT_DOUBLE_EQ(0, negative); |
| 279 | |
| 280 | xml = ""; |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 281 | parse_handler.reset(new AutofillUploadXmlParser(&positive, &negative)); |
[email protected] | db16347 | 2010-04-02 22:01:20 | [diff] [blame] | 282 | parser.reset(new buzz::XmlParser(parse_handler.get())); |
| 283 | parser->Parse(xml.c_str(), xml.length(), true); |
| 284 | EXPECT_TRUE(!parse_handler->succeeded()); |
| 285 | EXPECT_DOUBLE_EQ(0, positive); |
| 286 | EXPECT_DOUBLE_EQ(0, negative); |
| 287 | } |
| 288 | |
[email protected] | ec64212b | 2010-03-18 01:02:43 | [diff] [blame] | 289 | } // namespace |