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

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

Issue 2727513002: Revert of MD Settings: Stop using prefs to populate import data dialog. (Closed)
Patch Set: 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
77 var dialog = null; 88 var dialog = null;
78 89
79 setup(function() { 90 setup(function() {
80 browserProxy = new TestImportDataBrowserProxy(); 91 browserProxy = new TestImportDataBrowserProxy();
81 browserProxy.setBrowserProfiles(browserProfiles); 92 browserProxy.setBrowserProfiles(browserProfiles);
82 settings.ImportDataBrowserProxyImpl.instance_ = browserProxy; 93 settings.ImportDataBrowserProxyImpl.instance_ = browserProxy;
83 PolymerTest.clearBody(); 94 PolymerTest.clearBody();
84 dialog = document.createElement('settings-import-data-dialog'); 95 dialog = document.createElement('settings-import-data-dialog');
96 dialog.set('prefs', prefs);
85 document.body.appendChild(dialog); 97 document.body.appendChild(dialog);
86 return browserProxy.whenCalled('initializeImportDialog').then(function() { 98 return browserProxy.whenCalled('initializeImportDialog').then(function() {
87 assertTrue(dialog.$.dialog.open); 99 assertTrue(dialog.$.dialog.open);
88 Polymer.dom.flush(); 100 Polymer.dom.flush();
89 }); 101 });
90 }); 102 });
91 103
92 function simulateBrowserProfileChange(index) { 104 function simulateBrowserProfileChange(index) {
93 dialog.$.browserSelect.selectedIndex = index; 105 dialog.$.browserSelect.selectedIndex = index;
94 dialog.$.browserSelect.dispatchEvent(new CustomEvent('change')); 106 dialog.$.browserSelect.dispatchEvent(new CustomEvent('change'));
95 } 107 }
96 108
97 test('Initialization', function() { 109 test('Initialization', function() {
98 assertFalse(dialog.$.import.hidden); 110 assertFalse(dialog.$.import.hidden);
99 assertFalse(dialog.$.import.disabled); 111 assertFalse(dialog.$.import.disabled);
100 assertFalse(dialog.$.cancel.hidden); 112 assertFalse(dialog.$.cancel.hidden);
101 assertFalse(dialog.$.cancel.disabled); 113 assertFalse(dialog.$.cancel.disabled);
102 assertTrue(dialog.$.done.hidden); 114 assertTrue(dialog.$.done.hidden);
103 assertTrue(dialog.$.successIcon.parentElement.hidden); 115 assertTrue(dialog.$.successIcon.parentElement.hidden);
104 }); 116 });
105 117
106 test('ImportButton', function() { 118 test('ImportButton', function() {
107 assertFalse(dialog.$.import.disabled); 119 assertFalse(dialog.$.import.disabled);
108 120
109 var checkboxes = dialog.shadowRoot.querySelectorAll('paper-checkbox'); 121 // Flip all prefs to false.
110 assertEquals(5, checkboxes.length); 122 Object.keys(prefs).forEach(function(prefName) {
111 123 dialog.set('prefs.' + prefName + '.value', false);
112 checkboxes.forEach(function(checkbox) {
113 checkbox.checked = false;
114 }); 124 });
115 checkboxes[0].fire('change');
116 assertTrue(dialog.$.import.disabled); 125 assertTrue(dialog.$.import.disabled);
117 126
118 // Change browser selection to "Import from Bookmarks HTML file". 127 // Change browser selection to "Import from Bookmarks HTML file".
119 simulateBrowserProfileChange(1); 128 simulateBrowserProfileChange(1);
120 assertTrue(dialog.$.import.disabled); 129 assertTrue(dialog.$.import.disabled);
121 130
122 // Ensure everything except |favorites| is ignored. 131 // Ensure everything except |import_bookmarks| is ignored.
123 var history = dialog.$$('#history'); 132 dialog.set('prefs.import_history.value', true);
124 history.checked = true;
125 history.fire('change');
126 assertTrue(dialog.$.import.disabled); 133 assertTrue(dialog.$.import.disabled);
127 134
128 var favorites = dialog.$$('#favorites'); 135 dialog.set('prefs.import_bookmarks.value', true);
129 favorites.checked = true;
130 favorites.fire('change');
131 assertFalse(dialog.$.import.disabled); 136 assertFalse(dialog.$.import.disabled);
132 }); 137 });
133 138
134 function assertInProgressButtons() { 139 function assertInProgressButtons() {
135 assertFalse(dialog.$.import.hidden); 140 assertFalse(dialog.$.import.hidden);
136 assertTrue(dialog.$.import.disabled); 141 assertTrue(dialog.$.import.disabled);
137 assertFalse(dialog.$.cancel.hidden); 142 assertFalse(dialog.$.cancel.hidden);
138 assertTrue(dialog.$.cancel.disabled); 143 assertTrue(dialog.$.cancel.disabled);
139 assertTrue(dialog.$.done.hidden); 144 assertTrue(dialog.$.done.hidden);
140 assertTrue(dialog.$$('paper-spinner').active); 145 assertTrue(dialog.$$('paper-spinner').active);
(...skipping 22 matching lines...) Expand all
163 168
164 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED); 169 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED);
165 assertSucceededButtons(); 170 assertSucceededButtons();
166 171
167 assertFalse(dialog.$.successIcon.parentElement.hidden); 172 assertFalse(dialog.$.successIcon.parentElement.hidden);
168 assertFalse(dialog.$$('settings-toggle-button').parentElement.hidden); 173 assertFalse(dialog.$$('settings-toggle-button').parentElement.hidden);
169 }); 174 });
170 }); 175 });
171 176
172 test('ImportFromBrowserProfile', function() { 177 test('ImportFromBrowserProfile', function() {
173 dialog.$.favorites.checked = false; 178 dialog.set('prefs.import_bookmarks.value', false);
174 179
175 var expectedIndex = 0; 180 var expectedIndex = 0;
176 simulateBrowserProfileChange(expectedIndex); 181 simulateBrowserProfileChange(expectedIndex);
177 MockInteractions.tap(dialog.$.import); 182 MockInteractions.tap(dialog.$.import);
178 return browserProxy.whenCalled('importData').then(function(actualIndex) { 183 return browserProxy.whenCalled('importData').then(function(actualIndex) {
179 assertEquals(expectedIndex, actualIndex); 184 assertEquals(expectedIndex, actualIndex);
180 185
181 simulateImportStatusChange(settings.ImportDataStatus.IN_PROGRESS); 186 simulateImportStatusChange(settings.ImportDataStatus.IN_PROGRESS);
182 assertInProgressButtons(); 187 assertInProgressButtons();
183 188
184 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED); 189 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED);
185 assertSucceededButtons(); 190 assertSucceededButtons();
186 191
187 assertFalse(dialog.$.successIcon.parentElement.hidden); 192 assertFalse(dialog.$.successIcon.parentElement.hidden);
188 assertTrue(dialog.$$('settings-toggle-button').parentElement.hidden); 193 assertTrue(dialog.$$('settings-toggle-button').parentElement.hidden);
189 }); 194 });
190 }); 195 });
191 196
192 test('ImportError', function() { 197 test('ImportError', function() {
193 simulateImportStatusChange(settings.ImportDataStatus.FAILED); 198 simulateImportStatusChange(settings.ImportDataStatus.FAILED);
194 assertFalse(dialog.$.dialog.open); 199 assertFalse(dialog.$.dialog.open);
195 }); 200 });
196 }); 201 });
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