summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/options/autofill_options_browsertest.js
blob: 29a778f00023ad500a962b4740221cbf4470641f (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) 2012 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.

GEN_INCLUDE(['options_browsertest_base.js']);

/**
 * Returns the HTML element for the |field|.
 * @param {string} field The field name for the element.
 * @return {HTMLElement} The HTML element.
 */
function getField(field) {
  return document.querySelector(
      '#autofill-edit-address-overlay [field=' + field + ']');
}

/**
 * Returns the size of the |list|.
 * @param {HTMLElement} list The list to check.
 * @return {number} The size of the list.
 */
function getListSize(list) {
  // Remove 1 for placeholder input field.
  return list.items.length - 1;
}

/**
 * TestFixture for autofill options WebUI testing.
 * @extends {testing.Test}
 * @constructor
 */
function AutofillOptionsWebUITest() {}

AutofillOptionsWebUITest.prototype = {
  __proto__: OptionsBrowsertestBase.prototype,

  /**
   * Browse to autofill options.
   * @override
   */
  browsePreload: 'chrome://settings-frame/autofill',
};

// Test opening the autofill options has correct location.
TEST_F('AutofillOptionsWebUITest', 'testOpenAutofillOptions', function() {
  assertEquals(this.browsePreload, document.location.href);
});

/**
 * TestFixture for autofill edit address overlay WebUI testing.
 * @extends {testing.Test}
 * @constructor
 */
function AutofillEditAddressWebUITest() {}

AutofillEditAddressWebUITest.prototype = {
  __proto__: OptionsBrowsertestBase.prototype,

  /** @override  */
  browsePreload: 'chrome://settings-frame/autofillEditAddress',
};

TEST_F('AutofillEditAddressWebUITest', 'testInitialFormLayout', function() {
  assertEquals(this.browsePreload, document.location.href);

  var fields = ['country', 'phone', 'email', 'fullName', 'city'];
  for (field in fields) {
    assertEquals('', getField(fields[field]).value, 'Field: ' + fields[field]);
  }

  testDone();
});

TEST_F('AutofillEditAddressWebUITest', 'testLoadAddress', function() {
  // http://crbug.com/434502
  // Accessibility failure was originally (and consistently) seen on Mac OS and
  // Chromium OS. Disabling for all OSs because of a flake in Windows. There is
  // a possibility for flake in linux too.
  this.disableAccessibilityChecks();

  assertEquals(this.browsePreload, document.location.href);

  var testAddress = {
    guid: 'GUID Value',
    fullName: 'Full Name 1',
    companyName: 'Company Name Value',
    addrLines: 'First Line Value\nSecond Line Value',
    dependentLocality: 'Dependent Locality Value',
    city: 'City Value',
    state: 'State Value',
    postalCode: 'Postal Code Value',
    sortingCode: 'Sorting Code Value',
    country: 'CH',
    phone: '123',
    email: 'a@b.c',
    languageCode: 'de',
    components: [[
       {field: 'postalCode', length: 'short'},
       {field: 'sortingCode', length: 'short'},
       {field: 'dependentLocality', length: 'short'},
       {field: 'city', length: 'short'},
       {field: 'state', length: 'short'},
       {field: 'addrLines', length: 'long'},
       {field: 'companyName', length: 'long'},
       {field: 'country', length: 'long'},
       {field: 'fullName', length: 'long', placeholder: 'Add name'}
    ]]
  };
  AutofillEditAddressOverlay.loadAddress(testAddress);

  var overlay = AutofillEditAddressOverlay.getInstance();
  assertEquals(testAddress.guid, overlay.guid_);
  assertEquals(testAddress.languageCode, overlay.languageCode_);

  var inputs = ['companyName', 'dependentLocality', 'city', 'state',
                'postalCode', 'sortingCode', 'fullName', 'email', 'phone'];
  for (var i in inputs) {
    var field = getField(inputs[i]);
    assertEquals(testAddress[inputs[i]], field.value);
    assertTrue(field instanceof HTMLInputElement);
  }

  var addrLines = getField('addrLines');
  assertEquals(testAddress.addrLines, addrLines.value);
  assertTrue(addrLines instanceof HTMLTextAreaElement);

  var country = getField('country');
  assertEquals(testAddress.country, country.value);
  assertTrue(country instanceof HTMLSelectElement);
});

TEST_F('AutofillEditAddressWebUITest', 'testLoadAddressComponents', function() {
  assertEquals(this.browsePreload, document.location.href);

  var testInput = {
    languageCode: 'fr',
    components: [[{field: 'city'}],
                 [{field: 'state'}]]
  };
  AutofillEditAddressOverlay.loadAddressComponents(testInput);

  assertEquals('fr', AutofillEditAddressOverlay.getInstance().languageCode_);
  expectEquals(2, $('autofill-edit-address-fields').children.length);
});

TEST_F('AutofillEditAddressWebUITest', 'testFieldValuesSaved', function() {
  assertEquals(this.browsePreload, document.location.href);

  AutofillEditAddressOverlay.loadAddressComponents({
    languageCode: 'en',
    components: [[{field: 'city'}]]
  });
  getField('city').value = 'New York';

  AutofillEditAddressOverlay.loadAddressComponents({
    languageCode: 'en',
    components: [[{field: 'state'}]]
  });
  assertEquals(null, getField('city'));

  AutofillEditAddressOverlay.loadAddressComponents({
    languageCode: 'en',
    components: [[{field: 'city'}]]
  });
  assertEquals('New York', getField('city').value);
});