Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: chrome/browser/resources/settings/people_page/quick_unlock_choose_method.js

Issue 2157673002: Browser tests for the quick_unlock settings pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pin-unlock-quick-unlock-interface
Patch Set: Address comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 /**
6 * @fileoverview
7 * 'settings-quick-unlock-choose-method' allows the user to change how they
8 * unlock their device. Note that setting up the unlock method is delegated
9 * to other elements.
10 *
11 * Example:
12 *
13 * <settings-quick-unlock-choose-method
14 * set-modes="[[quickUnlockSetModes]]"
15 * prefs="{{prefs}}">
16 * </settings-quick-unlock-choose-method>
17 */
18
19 (function() {
20 'use strict';
21
22 /** @const */ var ENABLE_LOCK_SCREEN_PREF = 'settings.enable_screen_lock';
23
24 /** @enum {string} */
25 var QuickUnlockUnlockType = {
26 VALUE_PENDING: 'value_pending',
27 NONE: 'none',
28 PASSWORD: 'password',
29 PIN_PASSWORD: 'pin+password'
30 };
31
32 Polymer({
33 is: 'settings-quick-unlock-choose-method',
34
35 behaviors: [PrefsBehavior, QuickUnlockPasswordDetectBehavior],
36
37 properties: {
38 /** Preferences state. */
39 prefs: {
40 type: Object,
41 notify: true,
42 },
43
44 /**
45 * The currently selected unlock type.
46 * @type {!QuickUnlockUnlockType}
47 * @private
48 */
49 selectedUnlockType_: {
50 type: String,
51 notify: true,
52 value: QuickUnlockUnlockType.VALUE_PENDING,
53 observer: 'selectedUnlockTypeChanged_'
54 }
55 },
56
57 observers: ['onSetModesChanged_(setModes)'],
58
59 /** @override */
60 attached: function() {
61 CrSettingsPrefs.initialized.then(this.updateUnlockType_.bind(this));
62
63 this.boundOnPrefsChanged_ = function(prefs) {
64 for (var i = 0; i < prefs.length; ++i) {
65 if (prefs[i].key == ENABLE_LOCK_SCREEN_PREF)
66 this.updateUnlockType_();
67 }
68 }.bind(this);
69 this.boundOnActiveModesChanged_ = this.updateUnlockType_.bind(this);
70
71 chrome.settingsPrivate.onPrefsChanged.addListener(
72 this.boundOnPrefsChanged_);
73 chrome.quickUnlockPrivate.onActiveModesChanged.addListener(
74 this.boundOnActiveModesChanged_);
75
76 if (settings.getCurrentRoute() == settings.Route.QUICK_UNLOCK_CHOOSE_METHOD)
77 this.askForPasswordIfUnset();
78 },
79
80 /** @override */
81 detached: function() {
82 chrome.settingsPrivate.onPrefsChanged.removeListener(
83 this.boundOnPrefsChanged_);
84 chrome.quickUnlockPrivate.onActiveModesChanged.removeListener(
85 this.boundOnActiveModesChanged_);
86 },
87
88 /** @protected */
89 currentRouteChanged: function() {
90 if (settings.getCurrentRoute() == settings.Route.QUICK_UNLOCK_CHOOSE_METHOD)
91 this.askForPasswordIfUnset();
92 },
93
94 /** @private */
95 onSetModesChanged_: function() {
96 if (settings.getCurrentRoute() == settings.Route.QUICK_UNLOCK_CHOOSE_METHOD)
97 this.askForPasswordIfUnset();
98 },
99
100 /**
101 * Updates the selected unlock type radio group. This function will get called
102 * after preferences are initialized, after the quick unlock mode has been
103 * changed, and after the lockscreen preference has changed.
104 *
105 * @private
106 */
107 updateUnlockType_: function() {
108 // The quickUnlockPrivate.onActiveModesChanged event could trigger this
109 // function before CrSettingsPrefs is initialized if another settings page
110 // changes the quick unlock state.
111 if (!CrSettingsPrefs.isInitialized)
112 return;
113
114 if (!this.getPref(ENABLE_LOCK_SCREEN_PREF).value) {
115 this.selectedUnlockType_ = QuickUnlockUnlockType.NONE;
116 return;
117 }
118
119 chrome.quickUnlockPrivate.getActiveModes(function(modes) {
120 if (modes.includes(chrome.quickUnlockPrivate.QuickUnlockMode.PIN)) {
121 this.selectedUnlockType_ = QuickUnlockUnlockType.PIN_PASSWORD;
122 } else if (this.selectedUnlockType_ !=
123 QuickUnlockUnlockType.PIN_PASSWORD) {
124 // We don't want to clobber an existing PIN+PASSWORD state because the
125 // user needs to configure that option before actually using it.
126 //
127 // Specifically, this check is needed because this function gets called
128 // by the pref system after changing the unlock type from NONE to
129 // PIN+PASSWORD. Without the conditional assignment, this function would
130 // change the PIN+PASSWORD lock type to PASSWORD because the PIN hasn't
131 // been configured yet.
132 this.selectedUnlockType_ = QuickUnlockUnlockType.PASSWORD;
133 }
134 }.bind(this));
135 },
136
137 /**
138 * Called when the unlock type has changed.
139 * @param {!string} selected The current unlock type.
140 * @param {?string} previous The old unlock type. undefined if not present.
141 * @private
142 */
143 selectedUnlockTypeChanged_: function(selected, previous) {
144 // This method gets invoked when setting the initial value from the existing
145 // state. In that case, we don't need to bother updating the prefs.
146 if (!previous)
147 return;
148
149 this.setPrefValue(ENABLE_LOCK_SCREEN_PREF,
150 selected != QuickUnlockUnlockType.NONE);
151 if (selected != QuickUnlockUnlockType.PIN_PASSWORD && this.setModes) {
152 this.setModes.call(null, [], [], function(didSet) {
153 assert(didSet, 'Failed to clear quick unlock modes');
154 });
155 }
156 },
157
158 /**
159 * Retruns true if the setup pin section should be shown.
160 * @param {!string} selectedUnlockType The current unlock type. Used to let
161 * polymer know about the dependency.
162 * @private
163 */
164 showSetupPin_: function(selectedUnlockType) {
165 return selectedUnlockType === QuickUnlockUnlockType.PIN_PASSWORD;
166 },
167
168 /** @private */
169 onConfigurePin_: function() {
170 settings.navigateTo(settings.Route.QUICK_UNLOCK_SETUP_PIN);
171 },
172 });
173
174 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698