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

Unified Diff: components/autofill/browser/autofill_xml_parser_unittest.cc

Issue 17392006: In components/autofill, move browser/ to core/browser/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to fix conflicts Created 7 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/autofill/browser/autofill_xml_parser.cc ('k') | components/autofill/browser/contact_info.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/browser/autofill_xml_parser_unittest.cc
diff --git a/components/autofill/browser/autofill_xml_parser_unittest.cc b/components/autofill/browser/autofill_xml_parser_unittest.cc
deleted file mode 100644
index 0679d296ce3508ebf56cd82a1b7c30d3d34c7349..0000000000000000000000000000000000000000
--- a/components/autofill/browser/autofill_xml_parser_unittest.cc
+++ /dev/null
@@ -1,375 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <string>
-#include <vector>
-
-#include "base/memory/scoped_ptr.h"
-#include "base/strings/string_number_conversions.h"
-#include "components/autofill/browser/autofill_xml_parser.h"
-#include "components/autofill/browser/field_types.h"
-#include "components/autofill/content/browser/autocheckout_page_meta_data.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/libjingle/source/talk/xmllite/xmlparser.h"
-
-namespace autofill {
-namespace {
-
-class AutofillQueryXmlParserTest : public testing::Test {
- public:
- AutofillQueryXmlParserTest(): upload_required_(USE_UPLOAD_RATES) {};
- virtual ~AutofillQueryXmlParserTest() {};
-
- protected:
- void ParseQueryXML(const std::string& xml, bool should_succeed) {
- // Create a parser.
- AutofillQueryXmlParser parse_handler(&field_infos_,
- &upload_required_,
- &experiment_id_,
- &page_meta_data_);
- buzz::XmlParser parser(&parse_handler);
- parser.Parse(xml.c_str(), xml.length(), true);
- EXPECT_EQ(should_succeed, parse_handler.succeeded());
- }
-
- std::vector<AutofillServerFieldInfo> field_infos_;
- UploadRequired upload_required_;
- std::string experiment_id_;
- autofill::AutocheckoutPageMetaData page_meta_data_;
-};
-
-class AutofillUploadXmlParserTest : public testing::Test {
- public:
- AutofillUploadXmlParserTest(): positive_(0), negative_(0) {};
- virtual ~AutofillUploadXmlParserTest() {};
-
- protected:
- void ParseUploadXML(const std::string& xml, bool should_succeed) {
- // Create a parser.
- AutofillUploadXmlParser parse_handler(&positive_, &negative_);
- buzz::XmlParser parser(&parse_handler);
- parser.Parse(xml.c_str(), xml.length(), true);
-
- EXPECT_EQ(should_succeed, parse_handler.succeeded());
- }
-
- double positive_;
- double negative_;
-};
-
-TEST_F(AutofillQueryXmlParserTest, BasicQuery) {
- // An XML string representing a basic query response.
- std::string xml = "<autofillqueryresponse>"
- "<field autofilltype=\"0\" />"
- "<field autofilltype=\"1\" />"
- "<field autofilltype=\"3\" />"
- "<field autofilltype=\"2\" />"
- "<field autofilltype=\"61\" defaultvalue=\"default\"/>"
- "</autofillqueryresponse>";
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(USE_UPLOAD_RATES, upload_required_);
- ASSERT_EQ(5U, field_infos_.size());
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_EQ(UNKNOWN_TYPE, field_infos_[1].field_type);
- EXPECT_EQ(NAME_FIRST, field_infos_[2].field_type);
- EXPECT_EQ(EMPTY_TYPE, field_infos_[3].field_type);
- EXPECT_TRUE(field_infos_[3].default_value.empty());
- EXPECT_EQ(FIELD_WITH_DEFAULT_VALUE, field_infos_[4].field_type);
- EXPECT_EQ("default", field_infos_[4].default_value);
- EXPECT_TRUE(experiment_id_.empty());
-}
-
-// Test parsing the upload required attribute.
-TEST_F(AutofillQueryXmlParserTest, TestUploadRequired) {
- std::string xml = "<autofillqueryresponse uploadrequired=\"true\">"
- "<field autofilltype=\"0\" />"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(upload_required_, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_TRUE(experiment_id_.empty());
-
- field_infos_.clear();
- xml = "<autofillqueryresponse uploadrequired=\"false\">"
- "<field autofilltype=\"0\" />"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(UPLOAD_NOT_REQUIRED, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_TRUE(experiment_id_.empty());
-
- field_infos_.clear();
- xml = "<autofillqueryresponse uploadrequired=\"bad_value\">"
- "<field autofilltype=\"0\" />"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(USE_UPLOAD_RATES, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_TRUE(experiment_id_.empty());
-}
-
-// Test parsing the experiment id attribute
-TEST_F(AutofillQueryXmlParserTest, ParseExperimentId) {
- // When the attribute is missing, we should get back the default value -- the
- // empty string.
- std::string xml = "<autofillqueryresponse>"
- "<field autofilltype=\"0\" />"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(USE_UPLOAD_RATES, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_TRUE(experiment_id_.empty());
-
- field_infos_.clear();
-
- // When the attribute is present, make sure we parse it.
- xml = "<autofillqueryresponse experimentid=\"FancyNewAlgorithm\">"
- "<field autofilltype=\"0\" />"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(USE_UPLOAD_RATES, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_EQ(std::string("FancyNewAlgorithm"), experiment_id_);
-
- field_infos_.clear();
-
- // Make sure that we can handle parsing both the upload required and the
- // experiment id attribute together.
- xml = "<autofillqueryresponse uploadrequired=\"false\""
- " experimentid=\"ServerSmartyPants\">"
- "<field autofilltype=\"0\" />"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(UPLOAD_NOT_REQUIRED, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_EQ("ServerSmartyPants", experiment_id_);
-}
-
-// Test XML response with autofill_flow information.
-TEST_F(AutofillQueryXmlParserTest, ParseAutofillFlow) {
- std::string xml = "<autofillqueryresponse>"
- "<field autofilltype=\"55\"/>"
- "<autofill_flow page_no=\"1\" total_pages=\"10\">"
- "<page_advance_button id=\"foo\"/>"
- "</autofill_flow>"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(1U, field_infos_.size());
- EXPECT_EQ(1, page_meta_data_.current_page_number);
- EXPECT_EQ(10, page_meta_data_.total_pages);
- EXPECT_EQ("foo", page_meta_data_.proceed_element_descriptor.descriptor);
- EXPECT_EQ(autofill::WebElementDescriptor::ID,
- page_meta_data_.proceed_element_descriptor.retrieval_method);
-
- // Clear |field_infos_| for the next test;
- field_infos_.clear();
-
- // Test css_selector as page_advance_button.
- xml = "<autofillqueryresponse>"
- "<field autofilltype=\"55\"/>"
- "<autofill_flow page_no=\"1\" total_pages=\"10\">"
- "<page_advance_button css_selector=\"[name=&quot;foo&quot;]\"/>"
- "</autofill_flow>"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(1U, field_infos_.size());
- EXPECT_EQ(1, page_meta_data_.current_page_number);
- EXPECT_EQ(10, page_meta_data_.total_pages);
- EXPECT_EQ("[name=\"foo\"]",
- page_meta_data_.proceed_element_descriptor.descriptor);
- EXPECT_EQ(autofill::WebElementDescriptor::CSS_SELECTOR,
- page_meta_data_.proceed_element_descriptor.retrieval_method);
-
- // Clear |field_infos_| for the next test;
- field_infos_.clear();
-
- // Test first attribute is always the one set.
- xml = "<autofillqueryresponse>"
- "<field autofilltype=\"55\"/>"
- "<autofill_flow page_no=\"1\" total_pages=\"10\">"
- "<page_advance_button css_selector=\"[name=&quot;foo&quot;]\""
- " id=\"foo\"/>"
- "</autofill_flow>"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(1U, field_infos_.size());
- EXPECT_EQ(1, page_meta_data_.current_page_number);
- EXPECT_EQ(10, page_meta_data_.total_pages);
- EXPECT_EQ("[name=\"foo\"]",
- page_meta_data_.proceed_element_descriptor.descriptor);
- EXPECT_EQ(autofill::WebElementDescriptor::CSS_SELECTOR,
- page_meta_data_.proceed_element_descriptor.retrieval_method);
-
- // Clear |field_infos_| for the next test;
- field_infos_.clear();
-
- // Test parsing click_elements_before_formfill correctly.
- xml = "<autofillqueryresponse>"
- "<field autofilltype=\"55\"/>"
- "<autofill_flow page_no=\"1\" total_pages=\"10\">"
- "<click_elements_before_formfill>"
- "<web_element id=\"btn1\" /></click_elements_before_formfill>"
- "<click_elements_before_formfill>"
- "<web_element css_selector=\"[name=&quot;btn2&quot;]\"/>"
- "</click_elements_before_formfill>"
- "</autofill_flow>"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(1U, field_infos_.size());
- EXPECT_EQ(1, page_meta_data_.current_page_number);
- EXPECT_EQ(10, page_meta_data_.total_pages);
- ASSERT_EQ(2U, page_meta_data_.click_elements_before_form_fill.size());
- autofill::WebElementDescriptor& click_elment =
- page_meta_data_.click_elements_before_form_fill[0];
- EXPECT_EQ("btn1", click_elment.descriptor);
- EXPECT_EQ(autofill::WebElementDescriptor::ID, click_elment.retrieval_method);
- click_elment = page_meta_data_.click_elements_before_form_fill[1];
- EXPECT_EQ("[name=\"btn2\"]", click_elment.descriptor);
- EXPECT_EQ(autofill::WebElementDescriptor::CSS_SELECTOR,
- click_elment.retrieval_method);
-
- // Clear |field_infos_| for the next test;
- field_infos_.clear();
-
- // Test parsing click_elements_after_formfill correctly.
- xml = "<autofillqueryresponse>"
- "<field autofilltype=\"55\"/>"
- "<autofill_flow page_no=\"1\" total_pages=\"10\">"
- "<click_elements_after_formfill>"
- "<web_element id=\"btn1\" /></click_elements_after_formfill>"
- "</autofill_flow>"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(1U, field_infos_.size());
- EXPECT_EQ(1, page_meta_data_.current_page_number);
- EXPECT_EQ(10, page_meta_data_.total_pages);
- ASSERT_EQ(1U, page_meta_data_.click_elements_after_form_fill.size());
- click_elment = page_meta_data_.click_elements_after_form_fill[0];
- EXPECT_EQ("btn1", click_elment.descriptor);
- EXPECT_EQ(autofill::WebElementDescriptor::ID, click_elment.retrieval_method);
-}
-
-// Test badly formed XML queries.
-TEST_F(AutofillQueryXmlParserTest, ParseErrors) {
- // Test no Autofill type.
- std::string xml = "<autofillqueryresponse>"
- "<field/>"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, false);
-
- EXPECT_EQ(USE_UPLOAD_RATES, upload_required_);
- EXPECT_EQ(0U, field_infos_.size());
- EXPECT_TRUE(experiment_id_.empty());
-
- // Test an incorrect Autofill type.
- xml = "<autofillqueryresponse>"
- "<field autofilltype=\"-1\"/>"
- "</autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(USE_UPLOAD_RATES, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- // AutofillType was out of range and should be set to NO_SERVER_DATA.
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_TRUE(experiment_id_.empty());
-
- // Test upper bound for the field type, MAX_VALID_FIELD_TYPE.
- field_infos_.clear();
- xml = "<autofillqueryresponse><field autofilltype=\"" +
- base::IntToString(MAX_VALID_FIELD_TYPE) + "\"/></autofillqueryresponse>";
-
- ParseQueryXML(xml, true);
-
- EXPECT_EQ(USE_UPLOAD_RATES, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- // AutofillType was out of range and should be set to NO_SERVER_DATA.
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_TRUE(experiment_id_.empty());
-
- // Test an incorrect Autofill type.
- field_infos_.clear();
- xml = "<autofillqueryresponse>"
- "<field autofilltype=\"No Type\"/>"
- "</autofillqueryresponse>";
-
- // Parse fails but an entry is still added to field_infos_.
- ParseQueryXML(xml, false);
-
- EXPECT_EQ(USE_UPLOAD_RATES, upload_required_);
- ASSERT_EQ(1U, field_infos_.size());
- EXPECT_EQ(NO_SERVER_DATA, field_infos_[0].field_type);
- EXPECT_TRUE(experiment_id_.empty());
-}
-
-// Test successfull upload response.
-TEST_F(AutofillUploadXmlParserTest, TestSuccessfulResponse) {
- ParseUploadXML("<autofilluploadresponse positiveuploadrate=\"0.5\" "
- "negativeuploadrate=\"0.3\"/>",
- true);
-
- EXPECT_DOUBLE_EQ(0.5, positive_);
- EXPECT_DOUBLE_EQ(0.3, negative_);
-}
-
-// Test failed upload response.
-TEST_F(AutofillUploadXmlParserTest, TestFailedResponse) {
- ParseUploadXML("<autofilluploadresponse positiveuploadrate=\"\" "
- "negativeuploadrate=\"0.3\"/>",
- false);
-
- EXPECT_DOUBLE_EQ(0, positive_);
- EXPECT_DOUBLE_EQ(0.3, negative_); // Partially parsed.
- negative_ = 0;
-
- ParseUploadXML("<autofilluploadresponse positiveuploadrate=\"0.5\" "
- "negativeuploadrate=\"0.3\"",
- false);
-
- EXPECT_DOUBLE_EQ(0, positive_);
- EXPECT_DOUBLE_EQ(0, negative_);
-
- ParseUploadXML("bad data", false);
-
- EXPECT_DOUBLE_EQ(0, positive_);
- EXPECT_DOUBLE_EQ(0, negative_);
-
- ParseUploadXML(std::string(), false);
-
- EXPECT_DOUBLE_EQ(0, positive_);
- EXPECT_DOUBLE_EQ(0, negative_);
-}
-
-} // namespace
-} // namespace autofill
« no previous file with comments | « components/autofill/browser/autofill_xml_parser.cc ('k') | components/autofill/browser/contact_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698