| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @constructor |
| 7 * @implements {settings.ImportDataBrowserProxy} |
| 8 * @extends {settings.TestBrowserProxy} |
| 9 */ |
| 10 var TestImportDataBrowserProxy = function() { |
| 11 settings.TestBrowserProxy.call(this, [ |
| 12 'initializeImportDialog', |
| 13 'importFromBookmarksFile', |
| 14 'importData', |
| 15 ]); |
| 16 |
| 17 /** @private {!Array<!settings.BrowserProfile} */ |
| 18 this.browserProfiles_ = []; |
| 19 }; |
| 20 |
| 21 TestImportDataBrowserProxy.prototype = { |
| 22 __proto__: settings.TestBrowserProxy.prototype, |
| 23 |
| 24 /** @param {!Array<!settings.BrowserProfile} browserProfiles */ |
| 25 setBrowserProfiles: function(browserProfiles) { |
| 26 this.browserProfiles_ = browserProfiles; |
| 27 }, |
| 28 |
| 29 /** @override */ |
| 30 initializeImportDialog: function() { |
| 31 this.methodCalled('initializeImportDialog'); |
| 32 return Promise.resolve(this.browserProfiles_.slice()); |
| 33 }, |
| 34 |
| 35 /** @override */ |
| 36 importFromBookmarksFile: function() { |
| 37 this.methodCalled('importFromBookmarksFile'); |
| 38 }, |
| 39 |
| 40 /** @override */ |
| 41 importData: function(browserProfileIndex) { |
| 42 this.methodCalled('importData', browserProfileIndex); |
| 43 }, |
| 44 }; |
| 45 |
| 46 suite('ImportDataDialog', function() { |
| 47 /** @type {!Array<!settings.BrowserProfile} */ |
| 48 var browserProfiles = [ |
| 49 { |
| 50 autofillFormData: true, |
| 51 favorites: true, |
| 52 history: true, |
| 53 index: 0, |
| 54 name: "Mozilla Firefox", |
| 55 passwords: true, |
| 56 search: true |
| 57 }, |
| 58 { |
| 59 autofillFormData: false, |
| 60 favorites: true, |
| 61 history: false, |
| 62 index: 1, |
| 63 name: "Bookmarks HTML File", |
| 64 passwords: false, |
| 65 search: false |
| 66 }, |
| 67 ]; |
| 68 |
| 69 function createBooleanPref(name) { |
| 70 return { |
| 71 key: name, |
| 72 type: chrome.settingsPrivate.PrefType.BOOLEAN, |
| 73 value: true, |
| 74 }; |
| 75 } |
| 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; |
| 89 |
| 90 setup(function() { |
| 91 browserProxy = new TestImportDataBrowserProxy(); |
| 92 browserProxy.setBrowserProfiles(browserProfiles); |
| 93 settings.ImportDataBrowserProxyImpl.instance_ = browserProxy; |
| 94 PolymerTest.clearBody(); |
| 95 dialog = document.createElement('settings-import-data-dialog'); |
| 96 dialog.set('prefs', prefs); |
| 97 document.body.appendChild(dialog); |
| 98 assertTrue(dialog.$.dialog.open); |
| 99 return browserProxy.whenCalled('initializeImportDialog').then(function() { |
| 100 Polymer.dom.flush(); |
| 101 }); |
| 102 }); |
| 103 |
| 104 function simulateBrowserProfileChange(index) { |
| 105 dialog.$.browserSelect.selectedIndex = index; |
| 106 dialog.$.browserSelect.dispatchEvent(new CustomEvent('change')); |
| 107 } |
| 108 |
| 109 test('Initialization', function() { |
| 110 assertFalse(dialog.$.import.hidden); |
| 111 assertFalse(dialog.$.import.disabled); |
| 112 assertFalse(dialog.$.cancel.hidden); |
| 113 assertFalse(dialog.$.cancel.disabled); |
| 114 assertTrue(dialog.$.done.hidden); |
| 115 assertTrue(dialog.$.successIcon.parentElement.hidden); |
| 116 }); |
| 117 |
| 118 test('ImportButton', function() { |
| 119 assertFalse(dialog.$.import.disabled); |
| 120 |
| 121 // Flip all prefs to false. |
| 122 Object.keys(prefs).forEach(function(prefName) { |
| 123 dialog.set('prefs.' + prefName + '.value', false); |
| 124 }); |
| 125 assertTrue(dialog.$.import.disabled); |
| 126 |
| 127 // Change browser selection to "Import from Bookmarks HTML file". |
| 128 simulateBrowserProfileChange(1); |
| 129 assertTrue(dialog.$.import.disabled); |
| 130 |
| 131 // Ensure everything except |import_bookmarks| is ignored. |
| 132 dialog.set('prefs.import_history.value', true); |
| 133 assertTrue(dialog.$.import.disabled); |
| 134 |
| 135 dialog.set('prefs.import_bookmarks.value', true); |
| 136 assertFalse(dialog.$.import.disabled); |
| 137 }); |
| 138 |
| 139 function assertInProgressButtons() { |
| 140 assertFalse(dialog.$.import.hidden); |
| 141 assertTrue(dialog.$.import.disabled); |
| 142 assertFalse(dialog.$.cancel.hidden); |
| 143 assertTrue(dialog.$.cancel.disabled); |
| 144 assertTrue(dialog.$.done.hidden); |
| 145 assertTrue(dialog.$$('paper-spinner').active); |
| 146 assertFalse(dialog.$$('paper-spinner').hidden); |
| 147 } |
| 148 |
| 149 function assertSucceededButtons() { |
| 150 assertTrue(dialog.$.import.hidden); |
| 151 assertTrue(dialog.$.cancel.hidden); |
| 152 assertFalse(dialog.$.done.hidden); |
| 153 assertFalse(dialog.$$('paper-spinner').active); |
| 154 assertTrue(dialog.$$('paper-spinner').hidden); |
| 155 } |
| 156 |
| 157 /** @param {!settings.ImportDataStatus} status */ |
| 158 function simulateImportStatusChange(status) { |
| 159 cr.webUIListenerCallback('import-data-status-changed', status); |
| 160 } |
| 161 |
| 162 test('ImportFromBookmarksFile', function() { |
| 163 simulateBrowserProfileChange(1); |
| 164 MockInteractions.tap(dialog.$.import); |
| 165 return browserProxy.whenCalled('importFromBookmarksFile').then(function() { |
| 166 simulateImportStatusChange(settings.ImportDataStatus.IN_PROGRESS); |
| 167 assertInProgressButtons(); |
| 168 |
| 169 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED); |
| 170 assertSucceededButtons(); |
| 171 |
| 172 assertFalse(dialog.$.successIcon.parentElement.hidden); |
| 173 assertFalse(dialog.$$('settings-toggle-button').parentElement.hidden); |
| 174 }); |
| 175 }); |
| 176 |
| 177 test('ImportFromBrowserProfile', function() { |
| 178 dialog.set('prefs.import_bookmarks.value', false); |
| 179 |
| 180 var expectedIndex = 0; |
| 181 simulateBrowserProfileChange(expectedIndex); |
| 182 MockInteractions.tap(dialog.$.import); |
| 183 return browserProxy.whenCalled('importData').then(function(actualIndex) { |
| 184 assertEquals(expectedIndex, actualIndex); |
| 185 |
| 186 simulateImportStatusChange(settings.ImportDataStatus.IN_PROGRESS); |
| 187 assertInProgressButtons(); |
| 188 |
| 189 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED); |
| 190 assertSucceededButtons(); |
| 191 |
| 192 assertFalse(dialog.$.successIcon.parentElement.hidden); |
| 193 assertTrue(dialog.$$('settings-toggle-button').parentElement.hidden); |
| 194 }); |
| 195 }); |
| 196 |
| 197 test('ImportError', function() { |
| 198 simulateImportStatusChange(settings.ImportDataStatus.FAILED); |
| 199 assertFalse(dialog.$.dialog.open); |
| 200 }); |
| 201 }); |
| OLD | NEW |