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

Side by Side Diff: chrome/test/data/webui/settings/import_data_dialog_test.js

Issue 2717013002: MD Settings: Stop using prefs to populate import data dialog. (Closed)
Patch Set: Nits. Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/settings/people_page/import_data_dialog.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @implements {settings.ImportDataBrowserProxy} 7 * @implements {settings.ImportDataBrowserProxy}
8 * @extends {settings.TestBrowserProxy} 8 * @extends {settings.TestBrowserProxy}
9 */ 9 */
10 var TestImportDataBrowserProxy = function() { 10 var TestImportDataBrowserProxy = function() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ]; 67 ];
68 68
69 function createBooleanPref(name) { 69 function createBooleanPref(name) {
70 return { 70 return {
71 key: name, 71 key: name,
72 type: chrome.settingsPrivate.PrefType.BOOLEAN, 72 type: chrome.settingsPrivate.PrefType.BOOLEAN,
73 value: true, 73 value: true,
74 }; 74 };
75 } 75 }
76 76
77 var prefs = {};
78 [
79 'import_history',
80 'import_bookmarks',
81 'import_saved_passwords',
82 'import_search_engine',
83 'import_autofill_form_data',
84 ].forEach(function(name) {
85 prefs[name] = createBooleanPref(name);
86 });
87
88 var dialog = null; 77 var dialog = null;
89 78
90 setup(function() { 79 setup(function() {
91 browserProxy = new TestImportDataBrowserProxy(); 80 browserProxy = new TestImportDataBrowserProxy();
92 browserProxy.setBrowserProfiles(browserProfiles); 81 browserProxy.setBrowserProfiles(browserProfiles);
93 settings.ImportDataBrowserProxyImpl.instance_ = browserProxy; 82 settings.ImportDataBrowserProxyImpl.instance_ = browserProxy;
94 PolymerTest.clearBody(); 83 PolymerTest.clearBody();
95 dialog = document.createElement('settings-import-data-dialog'); 84 dialog = document.createElement('settings-import-data-dialog');
96 dialog.set('prefs', prefs);
97 document.body.appendChild(dialog); 85 document.body.appendChild(dialog);
98 return browserProxy.whenCalled('initializeImportDialog').then(function() { 86 return browserProxy.whenCalled('initializeImportDialog').then(function() {
99 assertTrue(dialog.$.dialog.open); 87 assertTrue(dialog.$.dialog.open);
100 Polymer.dom.flush(); 88 Polymer.dom.flush();
101 }); 89 });
102 }); 90 });
103 91
104 function simulateBrowserProfileChange(index) { 92 function simulateBrowserProfileChange(index) {
105 dialog.$.browserSelect.selectedIndex = index; 93 dialog.$.browserSelect.selectedIndex = index;
106 dialog.$.browserSelect.dispatchEvent(new CustomEvent('change')); 94 dialog.$.browserSelect.dispatchEvent(new CustomEvent('change'));
107 } 95 }
108 96
109 test('Initialization', function() { 97 test('Initialization', function() {
110 assertFalse(dialog.$.import.hidden); 98 assertFalse(dialog.$.import.hidden);
111 assertFalse(dialog.$.import.disabled); 99 assertFalse(dialog.$.import.disabled);
112 assertFalse(dialog.$.cancel.hidden); 100 assertFalse(dialog.$.cancel.hidden);
113 assertFalse(dialog.$.cancel.disabled); 101 assertFalse(dialog.$.cancel.disabled);
114 assertTrue(dialog.$.done.hidden); 102 assertTrue(dialog.$.done.hidden);
115 assertTrue(dialog.$.successIcon.parentElement.hidden); 103 assertTrue(dialog.$.successIcon.parentElement.hidden);
116 }); 104 });
117 105
118 test('ImportButton', function() { 106 test('ImportButton', function() {
119 assertFalse(dialog.$.import.disabled); 107 assertFalse(dialog.$.import.disabled);
120 108
121 // Flip all prefs to false. 109 var checkboxes = dialog.shadowRoot.querySelectorAll('paper-checkbox');
122 Object.keys(prefs).forEach(function(prefName) { 110 assertEquals(5, checkboxes.length);
123 dialog.set('prefs.' + prefName + '.value', false); 111
112 checkboxes.forEach(function(checkbox) {
113 checkbox.checked = false;
124 }); 114 });
115 checkboxes[0].fire('change');
125 assertTrue(dialog.$.import.disabled); 116 assertTrue(dialog.$.import.disabled);
126 117
127 // Change browser selection to "Import from Bookmarks HTML file". 118 // Change browser selection to "Import from Bookmarks HTML file".
128 simulateBrowserProfileChange(1); 119 simulateBrowserProfileChange(1);
129 assertTrue(dialog.$.import.disabled); 120 assertTrue(dialog.$.import.disabled);
130 121
131 // Ensure everything except |import_bookmarks| is ignored. 122 // Ensure everything except |favorites| is ignored.
132 dialog.set('prefs.import_history.value', true); 123 var history = dialog.$$('#history');
124 history.checked = true;
125 history.fire('change');
133 assertTrue(dialog.$.import.disabled); 126 assertTrue(dialog.$.import.disabled);
134 127
135 dialog.set('prefs.import_bookmarks.value', true); 128 var favorites = dialog.$$('#favorites');
129 favorites.checked = true;
130 favorites.fire('change');
136 assertFalse(dialog.$.import.disabled); 131 assertFalse(dialog.$.import.disabled);
137 }); 132 });
138 133
139 function assertInProgressButtons() { 134 function assertInProgressButtons() {
140 assertFalse(dialog.$.import.hidden); 135 assertFalse(dialog.$.import.hidden);
141 assertTrue(dialog.$.import.disabled); 136 assertTrue(dialog.$.import.disabled);
142 assertFalse(dialog.$.cancel.hidden); 137 assertFalse(dialog.$.cancel.hidden);
143 assertTrue(dialog.$.cancel.disabled); 138 assertTrue(dialog.$.cancel.disabled);
144 assertTrue(dialog.$.done.hidden); 139 assertTrue(dialog.$.done.hidden);
145 assertTrue(dialog.$$('paper-spinner').active); 140 assertTrue(dialog.$$('paper-spinner').active);
(...skipping 22 matching lines...) Expand all
168 163
169 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED); 164 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED);
170 assertSucceededButtons(); 165 assertSucceededButtons();
171 166
172 assertFalse(dialog.$.successIcon.parentElement.hidden); 167 assertFalse(dialog.$.successIcon.parentElement.hidden);
173 assertFalse(dialog.$$('settings-toggle-button').parentElement.hidden); 168 assertFalse(dialog.$$('settings-toggle-button').parentElement.hidden);
174 }); 169 });
175 }); 170 });
176 171
177 test('ImportFromBrowserProfile', function() { 172 test('ImportFromBrowserProfile', function() {
178 dialog.set('prefs.import_bookmarks.value', false); 173 dialog.$.favorites.checked = false;
179 174
180 var expectedIndex = 0; 175 var expectedIndex = 0;
181 simulateBrowserProfileChange(expectedIndex); 176 simulateBrowserProfileChange(expectedIndex);
182 MockInteractions.tap(dialog.$.import); 177 MockInteractions.tap(dialog.$.import);
183 return browserProxy.whenCalled('importData').then(function(actualIndex) { 178 return browserProxy.whenCalled('importData').then(function(actualIndex) {
184 assertEquals(expectedIndex, actualIndex); 179 assertEquals(expectedIndex, actualIndex);
185 180
186 simulateImportStatusChange(settings.ImportDataStatus.IN_PROGRESS); 181 simulateImportStatusChange(settings.ImportDataStatus.IN_PROGRESS);
187 assertInProgressButtons(); 182 assertInProgressButtons();
188 183
189 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED); 184 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED);
190 assertSucceededButtons(); 185 assertSucceededButtons();
191 186
192 assertFalse(dialog.$.successIcon.parentElement.hidden); 187 assertFalse(dialog.$.successIcon.parentElement.hidden);
193 assertTrue(dialog.$$('settings-toggle-button').parentElement.hidden); 188 assertTrue(dialog.$$('settings-toggle-button').parentElement.hidden);
194 }); 189 });
195 }); 190 });
196 191
197 test('ImportError', function() { 192 test('ImportError', function() {
198 simulateImportStatusChange(settings.ImportDataStatus.FAILED); 193 simulateImportStatusChange(settings.ImportDataStatus.FAILED);
199 assertFalse(dialog.$.dialog.open); 194 assertFalse(dialog.$.dialog.open);
200 }); 195 });
201 }); 196 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/people_page/import_data_dialog.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698