OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 file tests the chromeos.quickUnlockPrivate extension API. | 5 // This file tests the chromeos.quickUnlockPrivate extension API. |
6 | 6 |
7 #include "chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_p
rivate_api.h" | 7 #include "chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_p
rivate_api.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Run the function. | 107 // Run the function. |
108 std::unique_ptr<base::Value> result = | 108 std::unique_ptr<base::Value> result = |
109 RunFunction(new QuickUnlockPrivateGetAvailableModesFunction(), | 109 RunFunction(new QuickUnlockPrivateGetAvailableModesFunction(), |
110 base::MakeUnique<base::ListValue>()); | 110 base::MakeUnique<base::ListValue>()); |
111 | 111 |
112 // Extract the results. | 112 // Extract the results. |
113 QuickUnlockModeList modes; | 113 QuickUnlockModeList modes; |
114 | 114 |
115 base::ListValue* list = nullptr; | 115 base::ListValue* list = nullptr; |
116 EXPECT_TRUE(result->GetAsList(&list)); | 116 EXPECT_TRUE(result->GetAsList(&list)); |
117 for (const base::Value& value : *list) { | 117 // Consume the unique_ptr by reference so we don't take ownership. |
| 118 for (const std::unique_ptr<base::Value>& value : (*list)) { |
118 std::string mode; | 119 std::string mode; |
119 EXPECT_TRUE(value.GetAsString(&mode)); | 120 EXPECT_TRUE(value->GetAsString(&mode)); |
120 modes.push_back(quick_unlock_private::ParseQuickUnlockMode(mode)); | 121 modes.push_back(quick_unlock_private::ParseQuickUnlockMode(mode)); |
121 } | 122 } |
122 | 123 |
123 return modes; | 124 return modes; |
124 } | 125 } |
125 | 126 |
126 // Wrapper for chrome.quickUnlockPrivate.getActiveModes. | 127 // Wrapper for chrome.quickUnlockPrivate.getActiveModes. |
127 QuickUnlockModeList GetActiveModes() { | 128 QuickUnlockModeList GetActiveModes() { |
128 std::unique_ptr<base::Value> result = | 129 std::unique_ptr<base::Value> result = |
129 RunFunction(new QuickUnlockPrivateGetActiveModesFunction(), | 130 RunFunction(new QuickUnlockPrivateGetActiveModesFunction(), |
130 base::MakeUnique<base::ListValue>()); | 131 base::MakeUnique<base::ListValue>()); |
131 | 132 |
132 QuickUnlockModeList modes; | 133 QuickUnlockModeList modes; |
133 | 134 |
134 base::ListValue* list = nullptr; | 135 base::ListValue* list = nullptr; |
135 EXPECT_TRUE(result->GetAsList(&list)); | 136 EXPECT_TRUE(result->GetAsList(&list)); |
136 for (const base::Value& value : *list) { | 137 for (const std::unique_ptr<base::Value>& value : *list) { |
137 std::string mode; | 138 std::string mode; |
138 EXPECT_TRUE(value.GetAsString(&mode)); | 139 EXPECT_TRUE(value->GetAsString(&mode)); |
139 modes.push_back(quick_unlock_private::ParseQuickUnlockMode(mode)); | 140 modes.push_back(quick_unlock_private::ParseQuickUnlockMode(mode)); |
140 } | 141 } |
141 | 142 |
142 return modes; | 143 return modes; |
143 } | 144 } |
144 | 145 |
145 // Returns true if |problem| is contained in |problems|. | 146 // Returns true if |problem| is contained in |problems|. |
146 bool HasProblem(CredentialProblem problem, | 147 bool HasProblem(CredentialProblem problem, |
147 const std::vector<CredentialProblem> problems) { | 148 const std::vector<CredentialProblem> problems) { |
148 return std::find(problems.begin(), problems.end(), problem) != | 149 return std::find(problems.begin(), problems.end(), problem) != |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 // length pref. | 485 // length pref. |
485 pref_service->SetInteger(prefs::kPinUnlockMaximumLength, 4); | 486 pref_service->SetInteger(prefs::kPinUnlockMaximumLength, 4); |
486 CheckGetCredentialRequirements(6, 6); | 487 CheckGetCredentialRequirements(6, 6); |
487 | 488 |
488 // Verify that the values received from policy are sanitized. | 489 // Verify that the values received from policy are sanitized. |
489 pref_service->SetInteger(prefs::kPinUnlockMinimumLength, -3); | 490 pref_service->SetInteger(prefs::kPinUnlockMinimumLength, -3); |
490 pref_service->SetInteger(prefs::kPinUnlockMaximumLength, -3); | 491 pref_service->SetInteger(prefs::kPinUnlockMaximumLength, -3); |
491 CheckGetCredentialRequirements(1, 0); | 492 CheckGetCredentialRequirements(1, 0); |
492 } | 493 } |
493 } // namespace chromeos | 494 } // namespace chromeos |
OLD | NEW |