Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / users_private / test.js
blob62832e472c52fe8abfc537dff84d64a412191749
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
3 // found in the LICENSE file.
5 // This just tests the interface. It does not test for specific results, only
6 // that callbacks are correctly invoked, expected parameters are correct,
7 // and failures are detected.
9 function callbackResult(result) {
10   if (chrome.runtime.lastError)
11     chrome.test.fail(chrome.runtime.lastError.message);
12   else if (result == false)
13     chrome.test.fail('Failed: ' + result);
16 var kEmail1 = 'asdf@gmail.com';
17 var kEmail2 = 'asdf2@gmail.com';
19 var availableTests = [
20   function addUser() {
21     chrome.usersPrivate.addWhitelistedUser(
22         kEmail1,
23         function(result) {
24           callbackResult(result);
26           chrome.usersPrivate.getWhitelistedUsers(function(users) {
27             var foundUser = false;
28             users.forEach(function(user) {
29               if (user.email == kEmail1) {
30                 foundUser = true;
31               }
32             });
33             chrome.test.assertTrue(foundUser);
34             chrome.test.succeed();
35           });
36         });
37   },
39   function addAndRemoveUsers() {
40     chrome.usersPrivate.addWhitelistedUser(
41         kEmail1,
42         function(result1) {
43           callbackResult(result1);
45           chrome.usersPrivate.addWhitelistedUser(
46               kEmail2,
47               function(result2) {
48                 callbackResult(result2);
50                   chrome.usersPrivate.removeWhitelistedUser(
51                       kEmail1,
52                       function(result3) {
54                         chrome.usersPrivate.getWhitelistedUsers(
55                             function(users) {
56                               chrome.test.assertTrue(users.length == 1);
57                               chrome.test.assertEq(
58                                   kEmail2, users[0].email);
59                               chrome.test.succeed();
60                             });
62                       });
63               });
64         });
66   },
68   function isOwner() {
69     chrome.usersPrivate.isCurrentUserOwner(function(isOwner) {
70       // Since we are testing with --stub-cros-settings this should be true.
71       chrome.test.assertTrue(isOwner);
72       chrome.test.succeed();
73     });
74   },
77 var testToRun = window.location.search.substring(1);
78 chrome.test.runTests(availableTests.filter(function(op) {
79   return op.name == testToRun;
80 }));