| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This just tests the interface. It does not test for specific results, only | 5 // This just tests the interface. It does not test for specific results, only |
| 6 // that callbacks are correctly invoked, expected parameters are correct, | 6 // that callbacks are correctly invoked, expected parameters are correct, |
| 7 // and failures are detected. | 7 // and failures are detected. |
| 8 | 8 |
| 9 var availableTests = [ | 9 var availableTests = [ |
| 10 function removeSavedPassword() { | 10 function removeSavedPassword() { |
| 11 var numCalls = 0; | 11 var numCalls = 0; |
| 12 var numSavedPasswords; | 12 var numSavedPasswords; |
| 13 var callback = function(savedPasswordsList) { | 13 var callback = function(savedPasswordsList) { |
| 14 numCalls++; | 14 numCalls++; |
| 15 | 15 |
| 16 if (numCalls == 1) { | 16 if (numCalls == 1) { |
| 17 numSavedPasswords = savedPasswordsList.length; | 17 numSavedPasswords = savedPasswordsList.length; |
| 18 chrome.passwordsPrivate.removeSavedPassword({ | 18 chrome.passwordsPrivate.removeSavedPassword({ |
| 19 originUrl: savedPasswordsList[0].loginPair.originUrl, | 19 urls: { |
| 20 origin: savedPasswordsList[0].loginPair.urls.origin, |
| 21 shown: savedPasswordsList[0].loginPair.urls.shown, |
| 22 link: savedPasswordsList[0].loginPair.urls.link, |
| 23 }, |
| 20 username: savedPasswordsList[0].loginPair.username | 24 username: savedPasswordsList[0].loginPair.username |
| 21 }); | 25 }); |
| 22 } else if (numCalls == 2) { | 26 } else if (numCalls == 2) { |
| 23 chrome.test.assertEq( | 27 chrome.test.assertEq( |
| 24 savedPasswordsList.length, numSavedPasswords - 1); | 28 savedPasswordsList.length, numSavedPasswords - 1); |
| 25 chrome.test.succeed(); | 29 chrome.test.succeed(); |
| 26 } else { | 30 } else { |
| 27 chrome.test.fail(); | 31 chrome.test.fail(); |
| 28 } | 32 } |
| 29 }; | 33 }; |
| 30 | 34 |
| 31 chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(callback); | 35 chrome.passwordsPrivate.onSavedPasswordsListChanged.addListener(callback); |
| 32 chrome.passwordsPrivate.getSavedPasswordList(callback); | 36 chrome.passwordsPrivate.getSavedPasswordList(callback); |
| 33 }, | 37 }, |
| 34 | 38 |
| 35 function removePasswordException() { | 39 function removePasswordException() { |
| 36 var numCalls = 0; | 40 var numCalls = 0; |
| 37 var numPasswordExceptions; | 41 var numPasswordExceptions; |
| 38 var callback = function(passwordExceptionsList) { | 42 var callback = function(passwordExceptionsList) { |
| 39 numCalls++; | 43 numCalls++; |
| 40 | 44 |
| 41 if (numCalls == 1) { | 45 if (numCalls == 1) { |
| 42 numPasswordExceptions = passwordExceptionsList.length; | 46 numPasswordExceptions = passwordExceptionsList.length; |
| 43 chrome.passwordsPrivate.removePasswordException( | 47 chrome.passwordsPrivate.removePasswordException( |
| 44 passwordExceptionsList[0].exceptionUrl); | 48 passwordExceptionsList[0].urls.origin); |
| 45 } else if (numCalls == 2) { | 49 } else if (numCalls == 2) { |
| 46 chrome.test.assertEq( | 50 chrome.test.assertEq( |
| 47 passwordExceptionsList.length, numPasswordExceptions - 1); | 51 passwordExceptionsList.length, numPasswordExceptions - 1); |
| 48 chrome.test.succeed(); | 52 chrome.test.succeed(); |
| 49 } else { | 53 } else { |
| 50 chrome.test.fail(); | 54 chrome.test.fail(); |
| 51 } | 55 } |
| 52 }; | 56 }; |
| 53 | 57 |
| 54 chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener( | 58 chrome.passwordsPrivate.onPasswordExceptionsListChanged.addListener( |
| 55 callback); | 59 callback); |
| 56 chrome.passwordsPrivate.getPasswordExceptionList(callback); | 60 chrome.passwordsPrivate.getPasswordExceptionList(callback); |
| 57 }, | 61 }, |
| 58 | 62 |
| 59 function requestPlaintextPassword() { | 63 function requestPlaintextPassword() { |
| 60 var callback = function() { | 64 var callback = function() { |
| 61 // Ensure that the callback is invoked. | 65 // Ensure that the callback is invoked. |
| 62 chrome.test.succeed(); | 66 chrome.test.succeed(); |
| 63 }; | 67 }; |
| 64 | 68 |
| 65 chrome.passwordsPrivate.onPlaintextPasswordRetrieved.addListener(callback); | 69 chrome.passwordsPrivate.onPlaintextPasswordRetrieved.addListener(callback); |
| 66 chrome.passwordsPrivate.requestPlaintextPassword( | 70 chrome.passwordsPrivate.requestPlaintextPassword({ |
| 67 {originUrl: 'http://www.test.com', username: 'test@test.com'}); | 71 urls: { |
| 72 origin: 'http://www.test.com', |
| 73 shown: 'www.test.com', |
| 74 link: 'http://www.test.com', |
| 75 }, |
| 76 username: 'test@test.com' |
| 77 }); |
| 68 }, | 78 }, |
| 69 | 79 |
| 70 function getSavedPasswordList() { | 80 function getSavedPasswordList() { |
| 71 var callback = function(list) { | 81 var callback = function(list) { |
| 72 chrome.test.assertTrue(!!list); | 82 chrome.test.assertTrue(!!list); |
| 73 chrome.test.assertTrue(list.length > 0); | 83 chrome.test.assertTrue(list.length > 0); |
| 74 | 84 |
| 75 for (var i = 0; i < list.length; ++i) { | 85 for (var i = 0; i < list.length; ++i) { |
| 76 var entry = list[i]; | 86 var entry = list[i]; |
| 77 chrome.test.assertTrue(!!entry.loginPair); | 87 chrome.test.assertTrue(!!entry.loginPair); |
| 78 chrome.test.assertTrue(!!entry.loginPair.originUrl); | 88 chrome.test.assertTrue(!!entry.loginPair.urls.origin); |
| 79 chrome.test.assertTrue(!!entry.linkUrl); | 89 chrome.test.assertTrue(!!entry.loginPair.urls.shown); |
| 90 chrome.test.assertTrue(!!entry.loginPair.urls.link); |
| 80 } | 91 } |
| 81 | 92 |
| 82 // Ensure that the callback is invoked. | 93 // Ensure that the callback is invoked. |
| 83 chrome.test.succeed(); | 94 chrome.test.succeed(); |
| 84 }; | 95 }; |
| 85 | 96 |
| 86 chrome.passwordsPrivate.getSavedPasswordList(callback); | 97 chrome.passwordsPrivate.getSavedPasswordList(callback); |
| 87 }, | 98 }, |
| 88 | 99 |
| 89 function getPasswordExceptionList() { | 100 function getPasswordExceptionList() { |
| 90 var callback = function(list) { | 101 var callback = function(list) { |
| 91 chrome.test.assertTrue(!!list); | 102 chrome.test.assertTrue(!!list); |
| 92 chrome.test.assertTrue(list.length > 0); | 103 chrome.test.assertTrue(list.length > 0); |
| 93 | 104 |
| 94 for (var i = 0; i < list.length; ++i) { | 105 for (var i = 0; i < list.length; ++i) { |
| 95 var exception = list[i]; | 106 var exception = list[i]; |
| 96 chrome.test.assertTrue(!!exception.exceptionUrl); | 107 chrome.test.assertTrue(!!exception.urls.origin); |
| 97 chrome.test.assertTrue(!!exception.linkUrl); | 108 chrome.test.assertTrue(!!exception.urls.shown); |
| 109 chrome.test.assertTrue(!!exception.urls.link); |
| 98 } | 110 } |
| 99 | 111 |
| 100 // Ensure that the callback is invoked. | 112 // Ensure that the callback is invoked. |
| 101 chrome.test.succeed(); | 113 chrome.test.succeed(); |
| 102 }; | 114 }; |
| 103 | 115 |
| 104 chrome.passwordsPrivate.getPasswordExceptionList(callback); | 116 chrome.passwordsPrivate.getPasswordExceptionList(callback); |
| 105 }, | 117 }, |
| 106 ]; | 118 ]; |
| 107 | 119 |
| 108 var testToRun = window.location.search.substring(1); | 120 var testToRun = window.location.search.substring(1); |
| 109 chrome.test.runTests(availableTests.filter(function(op) { | 121 chrome.test.runTests(availableTests.filter(function(op) { |
| 110 return op.name == testToRun; | 122 return op.name == testToRun; |
| 111 })); | 123 })); |
| OLD | NEW |