| 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 #include "chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler
.h" | 5 #include "chrome/browser/ui/webui/settings/chromeos/easy_unlock_settings_handler
.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/signin/easy_unlock_service.h" | 10 #include "chrome/browser/signin/easy_unlock_service.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 fake_easy_unlock_service()->set_is_allowed(false); | 189 fake_easy_unlock_service()->set_is_allowed(false); |
| 190 handler.reset(EasyUnlockSettingsHandler::Create(data_source, profile())); | 190 handler.reset(EasyUnlockSettingsHandler::Create(data_source, profile())); |
| 191 EXPECT_FALSE(handler.get()); | 191 EXPECT_FALSE(handler.get()); |
| 192 } | 192 } |
| 193 | 193 |
| 194 TEST_F(EasyUnlockSettingsHandlerTest, EnabledStatus) { | 194 TEST_F(EasyUnlockSettingsHandlerTest, EnabledStatus) { |
| 195 std::unique_ptr<EasyUnlockSettingsHandler> handler; | 195 std::unique_ptr<EasyUnlockSettingsHandler> handler; |
| 196 handler.reset(new TestEasyUnlockSettingsHandler(profile())); | 196 handler.reset(new TestEasyUnlockSettingsHandler(profile())); |
| 197 handler->set_web_ui(web_ui()); | 197 handler->set_web_ui(web_ui()); |
| 198 | 198 |
| 199 // Test the C++ -> JS push path. | |
| 200 handler->SendEnabledStatus(); | |
| 201 VerifyEnabledStatusCallback(1U, false); | |
| 202 | |
| 203 fake_easy_unlock_service()->set_is_enabled(true); | |
| 204 handler->SendEnabledStatus(); | |
| 205 VerifyEnabledStatusCallback(2U, true); | |
| 206 | |
| 207 // Test the JS -> C++ -> JS callback path. | 199 // Test the JS -> C++ -> JS callback path. |
| 208 base::ListValue list_args; | 200 base::ListValue list_args; |
| 209 list_args.Append(new base::StringValue("test-callback-id")); | 201 list_args.Append(new base::StringValue("test-callback-id")); |
| 210 handler->HandleGetEnabledStatus(&list_args); | 202 handler->HandleGetEnabledStatus(&list_args); |
| 211 | 203 |
| 212 EXPECT_EQ(3U, web_ui()->call_data().size()); | 204 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 213 | 205 |
| 214 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); | 206 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 215 EXPECT_EQ("cr.webUIResponse", data.function_name()); | 207 EXPECT_EQ("cr.webUIResponse", data.function_name()); |
| 216 | 208 |
| 217 std::string callback_id; | 209 std::string callback_id; |
| 218 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | 210 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 219 EXPECT_EQ("test-callback-id", callback_id); | 211 EXPECT_EQ("test-callback-id", callback_id); |
| 220 | 212 |
| 221 bool enabled_status = false; | 213 bool enabled_status = false; |
| 222 ASSERT_TRUE(data.arg3()->GetAsBoolean(&enabled_status)); | 214 ASSERT_TRUE(data.arg3()->GetAsBoolean(&enabled_status)); |
| 223 EXPECT_TRUE(enabled_status); | 215 EXPECT_FALSE(enabled_status); |
| 216 |
| 217 // Test the C++ -> JS push path. |
| 218 handler->SendEnabledStatus(); |
| 219 VerifyEnabledStatusCallback(2U, false); |
| 220 |
| 221 fake_easy_unlock_service()->set_is_enabled(true); |
| 222 handler->SendEnabledStatus(); |
| 223 VerifyEnabledStatusCallback(3U, true); |
| 224 } | 224 } |
| 225 | 225 |
| 226 TEST_F(EasyUnlockSettingsHandlerTest, TurnOffFlowStatus) { | 226 TEST_F(EasyUnlockSettingsHandlerTest, TurnOffFlowStatus) { |
| 227 std::unique_ptr<EasyUnlockSettingsHandler> handler; | 227 std::unique_ptr<EasyUnlockSettingsHandler> handler; |
| 228 handler.reset(new TestEasyUnlockSettingsHandler(profile())); | 228 handler.reset(new TestEasyUnlockSettingsHandler(profile())); |
| 229 handler->set_web_ui(web_ui()); | 229 handler->set_web_ui(web_ui()); |
| 230 | 230 |
| 231 // Send an initial status query to turn on service observer. | 231 // Send an initial status query to turn on service observer. |
| 232 base::ListValue list_args1; | 232 base::ListValue list_args1; |
| 233 list_args1.Append(new base::StringValue("test-callback-id-1")); | 233 list_args1.Append(new base::StringValue("test-callback-id-1")); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 255 | 255 |
| 256 base::ListValue list_args4; | 256 base::ListValue list_args4; |
| 257 list_args4.Append(new base::StringValue("test-callback-id-4")); | 257 list_args4.Append(new base::StringValue("test-callback-id-4")); |
| 258 handler->HandleGetTurnOffFlowStatus(&list_args4); | 258 handler->HandleGetTurnOffFlowStatus(&list_args4); |
| 259 VerifyTurnOffFlowStatusWebUIResponse(7U, "test-callback-id-4", | 259 VerifyTurnOffFlowStatusWebUIResponse(7U, "test-callback-id-4", |
| 260 "server-error"); | 260 "server-error"); |
| 261 } | 261 } |
| 262 | 262 |
| 263 } // namespace settings | 263 } // namespace settings |
| 264 } // namespace chromeos | 264 } // namespace chromeos |
| OLD | NEW |