diff --git a/apps/settings/js/modules/wifi_utils.js b/apps/settings/js/modules/wifi_utils.js index 5d7dcb24477b..7c323723f0eb 100644 --- a/apps/settings/js/modules/wifi_utils.js +++ b/apps/settings/js/modules/wifi_utils.js @@ -222,7 +222,8 @@ define(function(require) { var certificateList = certList.ServerCert; // reset the option to be only - for (i = 0; i < select.options.length - 1; i++) { + var originLengthOfOptions = select.options.length; + for (i = 0; i < originLengthOfOptions - 1; i++) { select.remove(1); } diff --git a/apps/settings/test/unit/modules/wifi_utils_test.js b/apps/settings/test/unit/modules/wifi_utils_test.js index 6730ddcbf0a8..92437440168b 100644 --- a/apps/settings/test/unit/modules/wifi_utils_test.js +++ b/apps/settings/test/unit/modules/wifi_utils_test.js @@ -231,20 +231,27 @@ suite('WifiUtils', function() { var selectDOM = document.createElement('select'); selectDOM.appendChild(createOption('--')); selectDOM.appendChild(createOption('1')); + selectDOM.appendChild(createOption('2')); MockNavigatorMozWifiManager._certificateList = [ 'cert1', 'cert2', 'cert3' ]; + // the total options would be one default item and certificates + var expectedLengthOfOptions = + 1 + MockNavigatorMozWifiManager._certificateList.length; + this.sinon.spy(selectDOM, 'remove'); this.sinon.spy(selectDOM, 'add'); wifiUtils.loadImportedCertificateOptions(selectDOM); - // we have two options, but we would keep the first one - assert.isTrue(selectDOM.remove.calledOnce); + // we have three options, but we would keep the first one + assert.isTrue(selectDOM.remove.calledTwice); // and we would add three options back based on the number of our fake // certificates assert.isTrue(selectDOM.add.calledThrice); + // and the total options should be one default item and certificates + assert.equal(selectDOM.options.length, expectedLengthOfOptions); }); suite('newListItem', function() {