Chromium Code Reviews| 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 function callbackResult(result) { | 9 function callbackResult(result) { |
| 10 if (chrome.runtime.lastError) | 10 if (chrome.runtime.lastError) |
| 11 chrome.test.fail(chrome.runtime.lastError.message); | 11 chrome.test.fail(chrome.runtime.lastError.message); |
| 12 else if (result == false) | 12 else if (result == false) |
| 13 chrome.test.fail('Failed: ' + result); | 13 chrome.test.fail('Failed: ' + result); |
| 14 } | 14 } |
| 15 | 15 |
| 16 var kEmail1 = 'asdf@gmail.com'; | 16 var kEmail1 = 'asdf@gmail.com'; |
| 17 var kEmail2 = 'asdf2@gmail.com'; | 17 var kEmail2 = 'asdf2@gmail.com'; |
| 18 | 18 |
| 19 var availableTests = [ | 19 var availableTests = [ |
| 20 function addUser() { | 20 function addUser() { |
| 21 chrome.usersPrivate.addWhitelistedUser( | 21 chrome.usersPrivate.addWhitelistedUser( |
| 22 kEmail1, | 22 kEmail1, |
| 23 function(result) { | 23 function(result) { |
| 24 callbackResult(result); | 24 callbackResult(result); |
| 25 | 25 |
| 26 chrome.usersPrivate.getWhitelistedUsers(function(users) { | 26 chrome.usersPrivate.getWhitelistedUsers(function(users) { |
| 27 var foundUser = false; | 27 var foundUser = false; |
| 28 users.forEach(function(user) { | 28 users.forEach(function(user) { |
| 29 if (user.email == kEmail1) { | 29 if (user.email == kEmail1 && user.name == kEmail1) { |
|
Oren Blasberg
2016/08/19 18:47:48
I think you're reusing the kEmail1 variable for us
tommycli
2016/08/19 19:15:58
Done.
| |
| 30 foundUser = true; | 30 foundUser = true; |
| 31 } | 31 } |
| 32 }); | 32 }); |
| 33 chrome.test.assertTrue(foundUser); | 33 chrome.test.assertTrue(foundUser); |
| 34 chrome.test.succeed(); | 34 chrome.test.succeed(); |
| 35 }); | 35 }); |
| 36 }); | 36 }); |
| 37 }, | 37 }, |
| 38 | 38 |
| 39 function addAndRemoveUsers() { | 39 function addAndRemoveUsers() { |
| 40 chrome.usersPrivate.addWhitelistedUser( | 40 chrome.usersPrivate.addWhitelistedUser( |
| 41 kEmail1, | 41 kEmail1, |
| 42 function(result1) { | 42 function(result1) { |
| 43 callbackResult(result1); | 43 callbackResult(result1); |
| 44 | 44 |
| 45 chrome.usersPrivate.addWhitelistedUser( | 45 chrome.usersPrivate.addWhitelistedUser( |
| 46 kEmail2, | 46 kEmail2, |
| 47 function(result2) { | 47 function(result2) { |
| 48 callbackResult(result2); | 48 callbackResult(result2); |
| 49 | 49 |
| 50 chrome.usersPrivate.removeWhitelistedUser( | 50 chrome.usersPrivate.removeWhitelistedUser( |
| 51 kEmail1, | 51 kEmail1, |
| 52 function(result3) { | 52 function(result3) { |
| 53 | 53 |
| 54 chrome.usersPrivate.getWhitelistedUsers( | 54 chrome.usersPrivate.getWhitelistedUsers( |
| 55 function(users) { | 55 function(users) { |
| 56 chrome.test.assertTrue(users.length == 1); | 56 chrome.test.assertTrue(users.length == 1); |
| 57 chrome.test.assertEq( | 57 chrome.test.assertEq(kEmail2, users[0].email); |
| 58 kEmail2, users[0].email); | 58 chrome.test.assertEq(kEmail2, users[0].name); |
|
Oren Blasberg
2016/08/19 18:47:48
So this would be kName2
tommycli
2016/08/19 19:15:58
Done.
| |
| 59 chrome.test.succeed(); | 59 chrome.test.succeed(); |
| 60 }); | 60 }); |
| 61 | 61 |
| 62 }); | 62 }); |
| 63 }); | 63 }); |
| 64 }); | 64 }); |
| 65 | 65 |
| 66 }, | 66 }, |
| 67 | 67 |
| 68 function isOwner() { | 68 function isOwner() { |
| 69 chrome.usersPrivate.isCurrentUserOwner(function(isOwner) { | 69 chrome.usersPrivate.isCurrentUserOwner(function(isOwner) { |
| 70 // Since we are testing with --stub-cros-settings this should be true. | 70 // Since we are testing with --stub-cros-settings this should be true. |
| 71 chrome.test.assertTrue(isOwner); | 71 chrome.test.assertTrue(isOwner); |
| 72 chrome.test.succeed(); | 72 chrome.test.succeed(); |
| 73 }); | 73 }); |
| 74 }, | 74 }, |
| 75 ]; | 75 ]; |
| 76 | 76 |
| 77 var testToRun = window.location.search.substring(1); | 77 var testToRun = window.location.search.substring(1); |
| 78 chrome.test.runTests(availableTests.filter(function(op) { | 78 chrome.test.runTests(availableTests.filter(function(op) { |
| 79 return op.name == testToRun; | 79 return op.name == testToRun; |
| 80 })); | 80 })); |
| 81 | |
| OLD | NEW |