summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/fax_field_unittest.cc
blob: 0ba21c0b7f159978eeb0308c13341ec13c3f2411 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 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 "base/utf_string_conversions.h"
#include "chrome/browser/autofill/fax_field.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/glue/form_field.h"

namespace {

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

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

 private:
  DISALLOW_COPY_AND_ASSIGN(FaxFieldTest);
};

TEST_F(FaxFieldTest, Empty) {
  list_.push_back(NULL);
  iter_ = list_.begin();
  field_.reset(FaxField::Parse(&iter_));
  ASSERT_EQ(static_cast<FaxField*>(NULL), field_.get());
}

TEST_F(FaxFieldTest, NonParse) {
  list_.push_back(new AutoFillField);
  list_.push_back(NULL);
  iter_ = list_.begin();
  field_.reset(FaxField::Parse(&iter_));
  ASSERT_EQ(static_cast<FaxField*>(NULL), field_.get());
}

TEST_F(FaxFieldTest, ParseOneLineFax) {
  list_.push_back(
      new AutoFillField(webkit_glue::FormField(ASCIIToUTF16("Fax"),
                                               ASCIIToUTF16("faxnumber"),
                                               string16(),
                                               ASCIIToUTF16("text"),
                                               0),
                        ASCIIToUTF16("fax1")));
  list_.push_back(NULL);
  iter_ = list_.begin();
  field_.reset(FaxField::Parse(&iter_));
  ASSERT_NE(static_cast<FaxField*>(NULL), field_.get());
  ASSERT_TRUE(field_->GetFieldInfo(&field_type_map_));
  ASSERT_TRUE(
      field_type_map_.find(ASCIIToUTF16("fax1")) != field_type_map_.end());
  EXPECT_EQ(PHONE_FAX_WHOLE_NUMBER, field_type_map_[ASCIIToUTF16("fax1")]);
}

}  // namespace