blob: 59e74b6ef53a4505f83687fe04620de4cb5d0577 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This just tests the interface. It does not test for specific results, only
// that callbacks are correctly invoked, expected parameters are correct,
// and failures are detected.
var availableTests = [
function changeSavedPassword() {
var numCalls = 0;
var callback = function(savedPasswordsList) {
numCalls++;
if (numCalls == 1) {
chrome.passwordsPrivate.changeSavedPassword(0, 'new_user');
} else if (numCalls == 2) {
chrome.test.assertEq(
'new_user', savedPasswordsList[0].loginPair.username);
chrome.passwordsPrivate.changeSavedPassword(
0, 'another_user', 'new_pass');
} else if (numCalls == 3) {
chrome.test.assertEq(
'another_user', savedPasswordsList[0].loginPair.username);
chrome.test.assertEq(
'new_pass'.length, savedPasswordsList[0].numCharactersInPassword);
chrome.test.succeed();
} else {
chrome.test.fail();
}
};
chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(callback);
chrome.passwordsPrivate.getSavedPasswordList(callback);
},
function removeAndUndoRemoveSavedPassword() {
var numCalls = 0;
var numSavedPasswords;
var callback = function(savedPasswordsList) {
numCalls++;
if (numCalls == 1) {
numSavedPasswords = savedPasswordsList.length;
chrome.passwordsPrivate.removeSavedPassword(savedPasswordsList[0].id);
} else if (numCalls == 2) {
chrome.test.assertEq(
savedPasswordsList.length, numSavedPasswords - 1);
chrome.passwordsPrivate.undoRemoveSavedPasswordOrException();
} else if (numCalls == 3) {
chrome.test.assertEq(savedPasswordsList.length, numSavedPasswords);
chrome.test.succeed();
} else {
chrome.test.fail();
}
};
chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(callback);
chrome.passwordsPrivate.getSavedPasswordList(callback);
},
function removeAndUndoRemovePasswordException() {
var numCalls = 0;
var numPasswordExceptions;
var callback = function(passwordExceptionsList) {
numCalls++;
if (numCalls == 1) {
numPasswordExceptions = passwordExceptionsList.length;
chrome.passwordsPrivate.removePasswordException(
passwordExceptionsList[0].id);
} else if (numCalls == 2) {
chrome.test.assertEq(
passwordExceptionsList.length, numPasswordExceptions - 1);
chrome.passwordsPrivate.undoRemoveSavedPasswordOrException();
} else if (numCalls == 3) {
chrome.test.assertEq(
passwordExceptionsList.length, numPasswordExceptions);
chrome.test.succeed();
} else {
chrome.test.fail();
}
};
chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener(
callback);
chrome.passwordsPrivate.getPasswordExceptionList(callback);
},
function requestPlaintextPassword() {
chrome.passwordsPrivate.requestPlaintextPassword(0, password => {
// Ensure that the callback is invoked.
chrome.test.succeed();
});
},
function getSavedPasswordList() {
var callback = function(list) {
chrome.test.assertTrue(!!list);
chrome.test.assertTrue(list.length > 0);
var idSet = new Set();
for (var i = 0; i < list.length; ++i) {
var entry = list[i];
chrome.test.assertTrue(!!entry.loginPair);
chrome.test.assertTrue(!!entry.loginPair.urls.origin);
chrome.test.assertTrue(!!entry.loginPair.urls.shown);
chrome.test.assertTrue(!!entry.loginPair.urls.link);
idSet.add(entry.id);
}
// Ensure that all entry ids are unique.
chrome.test.assertEq(list.length, idSet.size);
// Ensure that the callback is invoked.
chrome.test.succeed();
};
chrome.passwordsPrivate.getSavedPasswordList(callback);
},
function getPasswordExceptionList() {
var callback = function(list) {
chrome.test.assertTrue(!!list);
chrome.test.assertTrue(list.length > 0);
var idSet = new Set();
for (var i = 0; i < list.length; ++i) {
var exception = list[i];
chrome.test.assertTrue(!!exception.urls.origin);
chrome.test.assertTrue(!!exception.urls.shown);
chrome.test.assertTrue(!!exception.urls.link);
idSet.add(exception.id);
}
// Ensure that all exception ids are unique.
chrome.test.assertEq(list.length, idSet.size);
// Ensure that the callback is invoked.
chrome.test.succeed();
};
chrome.passwordsPrivate.getPasswordExceptionList(callback);
},
function importPasswords() {
chrome.passwordsPrivate.importPasswords();
chrome.test.succeed();
},
function exportPasswords() {
let callback = function() {
chrome.test.assertNoLastError();
// Ensure that the callback is invoked.
chrome.test.succeed();
};
chrome.passwordsPrivate.exportPasswords(callback);
},
function cancelExportPasswords() {
chrome.passwordsPrivate.cancelExportPasswords();
chrome.test.succeed();
},
function requestExportProgressStatus() {
let callback = function(status) {
chrome.test.assertEq(
chrome.passwordsPrivate.ExportProgressStatus.IN_PROGRESS, status);
// Ensure that the callback is invoked.
chrome.test.succeed();
};
chrome.passwordsPrivate.requestExportProgressStatus(callback);
},
];
var testToRun = window.location.search.substring(1);
chrome.test.runTests(availableTests.filter(function(op) {
return op.name == testToRun;
}));