Chromium Code Reviews| 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 }, { | |
|
tommycli
2016/11/17 17:04:28
nit... isn't normally the second { on the next lin
dpapad
2016/11/17 18:29:09
Done.
| |
| 58 autofillFormData: false, | |
| 59 favorites: true, | |
| 60 history: false, | |
| 61 index: 1, | |
| 62 name: "Bookmarks HTML File", | |
| 63 passwords: false, | |
| 64 search: false | |
| 65 }, | |
| 66 ]; | |
| 67 | |
| 68 function createBooleanPref(name) { | |
| 69 return { | |
| 70 key: name, | |
| 71 type: chrome.settingsPrivate.PrefType.BOOLEAN, | |
| 72 value: true, | |
| 73 }; | |
| 74 } | |
| 75 | |
| 76 var prefs = {}; | |
| 77 [ | |
| 78 'import_history', | |
| 79 'import_bookmarks', | |
| 80 'import_saved_passwords', | |
| 81 'import_search_engine', | |
| 82 'import_autofill_form_data', | |
| 83 ].forEach(function(name) { | |
| 84 prefs[name] = createBooleanPref(name); | |
| 85 }); | |
| 86 | |
| 87 var dialog = null; | |
| 88 | |
| 89 setup(function() { | |
| 90 browserProxy = new TestImportDataBrowserProxy(); | |
| 91 browserProxy.setBrowserProfiles(browserProfiles); | |
| 92 settings.ImportDataBrowserProxyImpl.instance_ = browserProxy; | |
| 93 PolymerTest.clearBody(); | |
| 94 dialog = document.createElement('settings-import-data-dialog'); | |
| 95 dialog.set('prefs', prefs); | |
| 96 document.body.appendChild(dialog); | |
| 97 assertTrue(dialog.$.dialog.open); | |
| 98 return browserProxy.whenCalled('initializeImportDialog').then(function() { | |
| 99 Polymer.dom.flush(); | |
| 100 }); | |
| 101 }); | |
| 102 | |
| 103 function simulateBrowserProfileChange(index) { | |
| 104 dialog.$.browserSelect.selectedIndex = index; | |
| 105 dialog.$.browserSelect.dispatchEvent(new CustomEvent('change')); | |
| 106 } | |
| 107 | |
| 108 test('Initialization', function() { | |
| 109 assertFalse(dialog.$.import.hidden); | |
| 110 assertFalse(dialog.$.import.disabled); | |
| 111 assertFalse(dialog.$.cancel.hidden); | |
| 112 assertFalse(dialog.$.cancel.disabled); | |
| 113 assertTrue(dialog.$.done.hidden); | |
| 114 assertTrue(dialog.$.successIcon.parentElement.hidden); | |
| 115 }); | |
| 116 | |
| 117 test('ImportButton', function() { | |
| 118 assertFalse(dialog.$.import.disabled); | |
| 119 | |
| 120 // Flip all prefs to false. | |
| 121 Object.keys(prefs).forEach(function(prefName) { | |
| 122 dialog.set('prefs.' + prefName + '.value', false); | |
| 123 }); | |
| 124 assertTrue(dialog.$.import.disabled); | |
| 125 | |
| 126 // Change browser selection to "Import from Bookmarks HTML file". | |
| 127 simulateBrowserProfileChange(1); | |
| 128 assertTrue(dialog.$.import.disabled); | |
| 129 | |
| 130 // Ensure everything except |import_bookmarks| is ignored. | |
| 131 dialog.set('prefs.import_history.value', true); | |
| 132 assertTrue(dialog.$.import.disabled); | |
| 133 | |
| 134 dialog.set('prefs.import_bookmarks.value', true); | |
| 135 assertFalse(dialog.$.import.disabled); | |
| 136 }); | |
| 137 | |
| 138 function assertInProgressButtons() { | |
| 139 assertFalse(dialog.$.import.hidden); | |
| 140 assertTrue(dialog.$.import.disabled); | |
| 141 assertFalse(dialog.$.cancel.hidden); | |
| 142 assertTrue(dialog.$.cancel.disabled); | |
| 143 assertTrue(dialog.$.done.hidden); | |
| 144 assertTrue(dialog.$$('paper-spinner').active); | |
| 145 assertFalse(dialog.$$('paper-spinner').hidden); | |
| 146 } | |
| 147 | |
| 148 function assertSucceededButtons() { | |
| 149 assertTrue(dialog.$.import.hidden); | |
| 150 assertTrue(dialog.$.cancel.hidden); | |
| 151 assertFalse(dialog.$.done.hidden); | |
| 152 assertFalse(dialog.$$('paper-spinner').active); | |
| 153 assertTrue(dialog.$$('paper-spinner').hidden); | |
| 154 } | |
| 155 | |
| 156 /** @param {!settings.ImportDataStatus} status */ | |
| 157 function simulateImportStatusChange(status) { | |
| 158 cr.webUIListenerCallback('import-data-status-changed', status); | |
| 159 } | |
| 160 | |
| 161 test('ImportFromBookmarksFile', function() { | |
| 162 simulateBrowserProfileChange(1); | |
| 163 MockInteractions.tap(dialog.$.import); | |
| 164 return browserProxy.whenCalled('importFromBookmarksFile').then(function() { | |
| 165 simulateImportStatusChange(settings.ImportDataStatus.IN_PROGRESS); | |
| 166 assertInProgressButtons(); | |
| 167 | |
| 168 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED); | |
| 169 assertSucceededButtons(); | |
| 170 | |
| 171 assertFalse(dialog.$.successIcon.parentElement.hidden); | |
| 172 assertFalse(dialog.$$('settings-toggle-button').parentElement.hidden); | |
| 173 }); | |
| 174 }); | |
| 175 | |
| 176 test('ImportFromBrowserProfile', function() { | |
| 177 dialog.set('prefs.import_bookmarks.value', false); | |
| 178 | |
| 179 var expectedIndex = 0; | |
| 180 simulateBrowserProfileChange(expectedIndex); | |
| 181 MockInteractions.tap(dialog.$.import); | |
| 182 return browserProxy.whenCalled('importData').then(function(actualIndex) { | |
| 183 assertEquals(expectedIndex, actualIndex); | |
| 184 | |
| 185 simulateImportStatusChange(settings.ImportDataStatus.IN_PROGRESS); | |
| 186 assertInProgressButtons(); | |
| 187 | |
| 188 simulateImportStatusChange(settings.ImportDataStatus.SUCCEEDED); | |
| 189 assertSucceededButtons(); | |
| 190 | |
| 191 assertFalse(dialog.$.successIcon.parentElement.hidden); | |
| 192 assertTrue(dialog.$$('settings-toggle-button').parentElement.hidden); | |
| 193 }); | |
| 194 }); | |
| 195 | |
| 196 test('ImportError', function() { | |
| 197 simulateImportStatusChange(settings.ImportDataStatus.FAILED); | |
| 198 assertFalse(dialog.$.dialog.open); | |
| 199 }); | |
| 200 }); | |
| OLD | NEW |