Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package

name_field_unittest.cc

// Copyright (c) 2010 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 "base/scoped_ptr.h"
#include "base/scoped_vector.h"
#include "chrome/browser/autofill/autofill_field.h"
#include "chrome/browser/autofill/name_field.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/form_field.h"

namespace {

class NameFieldTest : public testing::Test {
 public:
  NameFieldTest() {}

 protected:
  ScopedVector<AutoFillField> list_;
  scoped_ptr<NameField> field_;
  FieldTypeMap field_type_map_;
  std::vector<AutoFillField*>::const_iterator iter_;

 private:
  DISALLOW_COPY_AND_ASSIGN(NameFieldTest);
};

TEST_F(NameFieldTest, FirstMiddleLast) {
  list_.push_back(
      new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("First Name"),
                                               ASCIIToUTF16("First"),
                                               string16(),
                                               ASCIIToUTF16("text")),
                        ASCIIToUTF16("name1")));
  list_.push_back(
      new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Middle Name"),
                                               ASCIIToUTF16("Middle"),
                                               string16(),
                                               ASCIIToUTF16("text")),
                        ASCIIToUTF16("name2")));
  list_.push_back(
      new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
                                               ASCIIToUTF16("Last"),
                                               string16(),
                                               ASCIIToUTF16("text")),
                        ASCIIToUTF16("name3")));
  list_.push_back(NULL);
  iter_ = list_.begin();
  field_.reset(NameField::Parse(&iter_, false));
  ASSERT_NE(static_cast<NameField*>(NULL), field_.get());
  ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
  ASSERT_TRUE(
      field_type_map_.find(ASCIIToUTF16("name1")) != field_type_map_.end());
  EXPECT_EQ(NAME_FIRST, field_type_map_[ASCIIToUTF16("name1")]);
  ASSERT_TRUE(
      field_type_map_.find(ASCIIToUTF16("name2")) != field_type_map_.end());
  EXPECT_EQ(NAME_MIDDLE, field_type_map_[ASCIIToUTF16("name2")]);
  ASSERT_TRUE(
      field_type_map_.find(ASCIIToUTF16("name3")) != field_type_map_.end());
  EXPECT_EQ(NAME_LAST, field_type_map_[ASCIIToUTF16("name3")]);
}

}  // namespace

Generated by  Doxygen 1.6.0   Back to index