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 <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 "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "components/autofill/core/browser/autofill_xml_parser.h" | 10 #include "components/autofill/core/browser/autofill_xml_parser.h" |
11 #include "components/autofill/core/browser/field_types.h" | 11 #include "components/autofill/core/browser/field_types.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/webrtc/libjingle/xmllite/xmlparser.h" | 13 #include "third_party/webrtc/libjingle/xmllite/xmlparser.h" |
14 | 14 |
15 namespace autofill { | 15 namespace autofill { |
16 namespace { | 16 namespace { |
17 | 17 |
18 class AutofillQueryXmlParserTest : public testing::Test { | 18 class AutofillQueryXmlParserTest : public testing::Test { |
19 public: | 19 public: |
20 AutofillQueryXmlParserTest(): upload_required_(USE_UPLOAD_RATES) {}; | 20 AutofillQueryXmlParserTest(): upload_required_(USE_UPLOAD_RATES) {} |
21 ~AutofillQueryXmlParserTest() override{}; | 21 ~AutofillQueryXmlParserTest() override{}; |
22 | 22 |
23 protected: | 23 protected: |
24 void ParseQueryXML(const std::string& xml, bool should_succeed) { | 24 void ParseQueryXML(const std::string& xml, bool should_succeed) { |
25 // Create a parser. | 25 // Create a parser. |
26 AutofillQueryXmlParser parse_handler(&field_infos_, | 26 AutofillQueryXmlParser parse_handler(&field_infos_, |
27 &upload_required_); | 27 &upload_required_); |
28 buzz::XmlParser parser(&parse_handler); | 28 buzz::XmlParser parser(&parse_handler); |
29 parser.Parse(xml.c_str(), xml.length(), true); | 29 parser.Parse(xml.c_str(), xml.length(), true); |
30 EXPECT_EQ(should_succeed, parse_handler.succeeded()); | 30 EXPECT_EQ(should_succeed, parse_handler.succeeded()); |
31 } | 31 } |
32 | 32 |
33 std::vector<AutofillServerFieldInfo> field_infos_; | 33 std::vector<AutofillServerFieldInfo> field_infos_; |
34 UploadRequired upload_required_; | 34 UploadRequired upload_required_; |
35 }; | 35 }; |
36 | 36 |
37 class AutofillUploadXmlParserTest : public testing::Test { | 37 class AutofillUploadXmlParserTest : public testing::Test { |
38 public: | 38 public: |
39 AutofillUploadXmlParserTest(): positive_(0), negative_(0) {}; | 39 AutofillUploadXmlParserTest(): positive_(0), negative_(0) {} |
40 ~AutofillUploadXmlParserTest() override{}; | 40 ~AutofillUploadXmlParserTest() override{}; |
41 | 41 |
42 protected: | 42 protected: |
43 void ParseUploadXML(const std::string& xml, bool should_succeed) { | 43 void ParseUploadXML(const std::string& xml, bool should_succeed) { |
44 // Create a parser. | 44 // Create a parser. |
45 AutofillUploadXmlParser parse_handler(&positive_, &negative_); | 45 AutofillUploadXmlParser parse_handler(&positive_, &negative_); |
46 buzz::XmlParser parser(&parse_handler); | 46 buzz::XmlParser parser(&parse_handler); |
47 parser.Parse(xml.c_str(), xml.length(), true); | 47 parser.Parse(xml.c_str(), xml.length(), true); |
48 | 48 |
49 EXPECT_EQ(should_succeed, parse_handler.succeeded()); | 49 EXPECT_EQ(should_succeed, parse_handler.succeeded()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 "</autofillqueryresponse>"; | 153 "</autofillqueryresponse>"; |
154 | 154 |
155 // Parse fails but an entry is still added to field_infos_. | 155 // Parse fails but an entry is still added to field_infos_. |
156 ParseQueryXML(xml, false); | 156 ParseQueryXML(xml, false); |
157 | 157 |
158 EXPECT_EQ(USE_UPLOAD_RATES, upload_required_); | 158 EXPECT_EQ(USE_UPLOAD_RATES, upload_required_); |
159 ASSERT_EQ(1U, field_infos_.size()); | 159 ASSERT_EQ(1U, field_infos_.size()); |
160 EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type); | 160 EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type); |
161 } | 161 } |
162 | 162 |
163 // Test successfull upload response. | 163 // Test successful upload response. |
164 TEST_F(AutofillUploadXmlParserTest, TestSuccessfulResponse) { | 164 TEST_F(AutofillUploadXmlParserTest, TestSuccessfulResponse) { |
165 ParseUploadXML("<autofilluploadresponse positiveuploadrate=\"0.5\" " | 165 ParseUploadXML("<autofilluploadresponse positiveuploadrate=\"0.5\" " |
166 "negativeuploadrate=\"0.3\"/>", | 166 "negativeuploadrate=\"0.3\"/>", |
167 true); | 167 true); |
168 | 168 |
169 EXPECT_DOUBLE_EQ(0.5, positive_); | 169 EXPECT_DOUBLE_EQ(0.5, positive_); |
170 EXPECT_DOUBLE_EQ(0.3, negative_); | 170 EXPECT_DOUBLE_EQ(0.3, negative_); |
171 } | 171 } |
172 | 172 |
173 // Test failed upload response. | 173 // Test failed upload response. |
(...skipping 19 matching lines...) Expand all Loading... |
193 EXPECT_DOUBLE_EQ(0, negative_); | 193 EXPECT_DOUBLE_EQ(0, negative_); |
194 | 194 |
195 ParseUploadXML(std::string(), false); | 195 ParseUploadXML(std::string(), false); |
196 | 196 |
197 EXPECT_DOUBLE_EQ(0, positive_); | 197 EXPECT_DOUBLE_EQ(0, positive_); |
198 EXPECT_DOUBLE_EQ(0, negative_); | 198 EXPECT_DOUBLE_EQ(0, negative_); |
199 } | 199 } |
200 | 200 |
201 } // namespace | 201 } // namespace |
202 } // namespace autofill | 202 } // namespace autofill |
OLD | NEW |