Index: chrome/test/data/extensions/api_test/quick_unlock_private/apiTests/background.js |
diff --git a/chrome/test/data/extensions/api_test/quick_unlock_private/apiTests/background.js b/chrome/test/data/extensions/api_test/quick_unlock_private/apiTests/background.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..22508756a3787574a7dcc009fbfc64ca8e37ed87 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/quick_unlock_private/apiTests/background.js |
@@ -0,0 +1,118 @@ |
+// Copyright (c) 2016 The Chromium Authors. All rights reserved. |
Devlin
2016/05/31 22:58:39
no (c)
jdufault
2016/06/01 00:07:36
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+var QuickUnlockMode = chrome.quickUnlockPrivate.QuickUnlockMode; |
+ |
+function checkPassword(password, callback) { |
+ chrome.quickUnlockPrivate.getActiveModes(onGetActiveModes); |
+ |
+ function onGetActiveModes(modes) { |
+ var passwords = Array(modes.length).fill(''); |
+ chrome.quickUnlockPrivate.setModes(password, modes, passwords, callback); |
+ } |
+} |
+ |
+// Verifies that the valid password is accepted. This uses a fake authentication |
+// backend. |
+function checkValidPasswordTest() { |
+ checkPassword('valid', onCheckPassword); |
+ |
+ function onCheckPassword(result) { |
+ chrome.test.assertTrue(result); |
+ chrome.test.succeed(); |
+ }; |
+} |
+ |
+// Verifies that the invalid password is rejected. This uses a fake |
+// authentication backend. |
+function checkInvalidPasswordTest() { |
+ checkPassword('invalid', onCheckPassword); |
+ |
+ function onCheckPassword(result) { |
+ chrome.test.assertFalse(result); |
+ chrome.test.succeed(); |
+ }; |
+} |
+ |
+// Verifies that chrome.quickUnlockPrivate.getAvailableModes returns only PIN. |
+function checkAvailableModes() { |
+ chrome.quickUnlockPrivate.getAvailableModes(onGetAvailableModes); |
+ |
+ function onGetAvailableModes(modes) { |
+ chrome.test.checkDeepEq(modes, [QuickUnlockMode.PIN]); |
+ chrome.test.succeed(); |
+ } |
+} |
+ |
+// Verifies that we cannot change modes with an invalid password. |
+function checkSetModesFailsWithInvalidPassword() { |
+ function onActiveModesChanged(newModes) { |
+ chrome.test.fail('Mode change callback should not be called'); |
+ } |
+ |
+ chrome.quickUnlockPrivate.onActiveModesChanged.addListener( |
+ onActiveModesChanged); |
+ |
+ chrome.quickUnlockPrivate.setModes( |
+ 'invalid', [QuickUnlockMode.PIN], ['111'], onModeSet); |
+ |
+ function onModeSet(success) { |
+ chrome.quickUnlockPrivate.onActiveModesChanged.removeListener( |
+ onActiveModesChanged); |
+ |
+ chrome.test.assertFalse(success); |
+ chrome.test.succeed(); |
+ } |
+} |
+ |
+// Verifies that we can set the quick unlock mode to PIN, we can fetch that mode |
+// using getActiveModes, and that we can clear the pin with setModes. |
+function checkSetAndGetModes() { |
+ chrome.quickUnlockPrivate.setModes( |
+ 'valid', [QuickUnlockMode.PIN], ['111'], onModeSet); |
+ |
+ function onModeSet(result) { |
+ chrome.test.assertTrue(result); |
+ chrome.quickUnlockPrivate.getActiveModes(onGetActiveModesExpectPin); |
+ } |
+ |
+ function onGetActiveModesExpectPin(modes) { |
+ chrome.test.checkDeepEq(modes, [QuickUnlockMode.PIN]); |
+ chrome.quickUnlockPrivate.setModes('valid', [], [], onModeClear); |
+ } |
+ |
+ function onModeClear(result) { |
+ chrome.test.assertTrue(result); |
+ chrome.quickUnlockPrivate.getActiveModes(onGetActiveModesExpectNone); |
+ } |
+ |
+ function onGetActiveModesExpectNone(modes) { |
+ chrome.test.checkDeepEq(modes, []); |
+ chrome.test.succeed(); |
+ } |
+} |
+ |
+// Verifies that the onActiveModesChange event gets called. |
+function checkActiveModesChangedEvent() { |
+ chrome.quickUnlockPrivate.setModes('valid', [], [], chrome.test.assertTrue); |
+ |
+ chrome.quickUnlockPrivate.onActiveModesChanged.addListener( |
+ onActiveModesChanged); |
+ function onActiveModesChanged(newModes) { |
+ chrome.quickUnlockPrivate.onActiveModesChanged.removeListener( |
+ onActiveModesChanged); |
+ |
+ chrome.test.checkDeepEq(newModes, [QuickUnlockMode.PIN]); |
+ chrome.test.succeed(); |
+ } |
+ |
+ chrome.quickUnlockPrivate.setModes( |
+ 'valid', [QuickUnlockMode.PIN], ['111'], chrome.test.assertTrue); |
+} |
+ |
+chrome.test.sendMessage('ready'); |
+chrome.test.runTests( |
+ [checkValidPasswordTest, checkInvalidPasswordTest, checkAvailableModes, |
+ checkSetModesFailsWithInvalidPassword, checkSetAndGetModes, |
+ checkActiveModesChangedEvent]); |