| 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 "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/signin/easy_unlock_service.h" | 10 #include "chrome/browser/signin/easy_unlock_service.h" |
| 9 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 11 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 11 #include "content/public/browser/web_ui_data_source.h" | 13 #include "content/public/browser/web_ui_data_source.h" |
| 12 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "content/public/test/test_web_ui.h" | 15 #include "content/public/test/test_web_ui.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 namespace chromeos { | 18 namespace chromeos { |
| 17 namespace settings { | 19 namespace settings { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 class TestEasyUnlockSettingsHandler : public EasyUnlockSettingsHandler { | 89 class TestEasyUnlockSettingsHandler : public EasyUnlockSettingsHandler { |
| 88 public: | 90 public: |
| 89 explicit TestEasyUnlockSettingsHandler(Profile* profile) | 91 explicit TestEasyUnlockSettingsHandler(Profile* profile) |
| 90 : EasyUnlockSettingsHandler(profile) {} | 92 : EasyUnlockSettingsHandler(profile) {} |
| 91 | 93 |
| 92 using EasyUnlockSettingsHandler::set_web_ui; | 94 using EasyUnlockSettingsHandler::set_web_ui; |
| 93 }; | 95 }; |
| 94 | 96 |
| 95 scoped_ptr<KeyedService> CreateEasyUnlockServiceForTest( | 97 std::unique_ptr<KeyedService> CreateEasyUnlockServiceForTest( |
| 96 content::BrowserContext* context) { | 98 content::BrowserContext* context) { |
| 97 return make_scoped_ptr( | 99 return base::WrapUnique( |
| 98 new FakeEasyUnlockService(Profile::FromBrowserContext(context))); | 100 new FakeEasyUnlockService(Profile::FromBrowserContext(context))); |
| 99 } | 101 } |
| 100 | 102 |
| 101 } // namespace | 103 } // namespace |
| 102 | 104 |
| 103 class EasyUnlockSettingsHandlerTest : public testing::Test { | 105 class EasyUnlockSettingsHandlerTest : public testing::Test { |
| 104 public: | 106 public: |
| 105 EasyUnlockSettingsHandlerTest() {} | 107 EasyUnlockSettingsHandlerTest() {} |
| 106 | 108 |
| 107 void SetUp() override { | 109 void SetUp() override { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | 166 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 165 EXPECT_EQ(expected_callback_id, callback_id); | 167 EXPECT_EQ(expected_callback_id, callback_id); |
| 166 | 168 |
| 167 std::string actual_status; | 169 std::string actual_status; |
| 168 ASSERT_TRUE(data.arg3()->GetAsString(&actual_status)); | 170 ASSERT_TRUE(data.arg3()->GetAsString(&actual_status)); |
| 169 EXPECT_EQ(expected_status, actual_status); | 171 EXPECT_EQ(expected_status, actual_status); |
| 170 } | 172 } |
| 171 | 173 |
| 172 private: | 174 private: |
| 173 content::TestBrowserThreadBundle thread_bundle_; | 175 content::TestBrowserThreadBundle thread_bundle_; |
| 174 scoped_ptr<TestingProfile> profile_; | 176 std::unique_ptr<TestingProfile> profile_; |
| 175 content::TestWebUI web_ui_; | 177 content::TestWebUI web_ui_; |
| 176 }; | 178 }; |
| 177 | 179 |
| 178 TEST_F(EasyUnlockSettingsHandlerTest, OnlyCreatedWhenEasyUnlockAllowed) { | 180 TEST_F(EasyUnlockSettingsHandlerTest, OnlyCreatedWhenEasyUnlockAllowed) { |
| 179 scoped_ptr<EasyUnlockSettingsHandler> handler; | 181 std::unique_ptr<EasyUnlockSettingsHandler> handler; |
| 180 content::WebUIDataSource* data_source = | 182 content::WebUIDataSource* data_source = |
| 181 content::WebUIDataSource::Create("test-data-source"); | 183 content::WebUIDataSource::Create("test-data-source"); |
| 182 content::WebUIDataSource::Add(profile(), data_source); | 184 content::WebUIDataSource::Add(profile(), data_source); |
| 183 handler.reset( | 185 handler.reset( |
| 184 EasyUnlockSettingsHandler::Create(data_source, profile())); | 186 EasyUnlockSettingsHandler::Create(data_source, profile())); |
| 185 EXPECT_TRUE(handler.get()); | 187 EXPECT_TRUE(handler.get()); |
| 186 | 188 |
| 187 fake_easy_unlock_service()->set_is_allowed(false); | 189 fake_easy_unlock_service()->set_is_allowed(false); |
| 188 handler.reset(EasyUnlockSettingsHandler::Create(data_source, profile())); | 190 handler.reset(EasyUnlockSettingsHandler::Create(data_source, profile())); |
| 189 EXPECT_FALSE(handler.get()); | 191 EXPECT_FALSE(handler.get()); |
| 190 } | 192 } |
| 191 | 193 |
| 192 TEST_F(EasyUnlockSettingsHandlerTest, EnabledStatus) { | 194 TEST_F(EasyUnlockSettingsHandlerTest, EnabledStatus) { |
| 193 scoped_ptr<EasyUnlockSettingsHandler> handler; | 195 std::unique_ptr<EasyUnlockSettingsHandler> handler; |
| 194 handler.reset(new TestEasyUnlockSettingsHandler(profile())); | 196 handler.reset(new TestEasyUnlockSettingsHandler(profile())); |
| 195 handler->set_web_ui(web_ui()); | 197 handler->set_web_ui(web_ui()); |
| 196 | 198 |
| 197 // Test the C++ -> JS push path. | 199 // Test the C++ -> JS push path. |
| 198 handler->SendEnabledStatus(); | 200 handler->SendEnabledStatus(); |
| 199 VerifyEnabledStatusCallback(1U, false); | 201 VerifyEnabledStatusCallback(1U, false); |
| 200 | 202 |
| 201 fake_easy_unlock_service()->set_is_enabled(true); | 203 fake_easy_unlock_service()->set_is_enabled(true); |
| 202 handler->SendEnabledStatus(); | 204 handler->SendEnabledStatus(); |
| 203 VerifyEnabledStatusCallback(2U, true); | 205 VerifyEnabledStatusCallback(2U, true); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 215 std::string callback_id; | 217 std::string callback_id; |
| 216 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | 218 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 217 EXPECT_EQ("test-callback-id", callback_id); | 219 EXPECT_EQ("test-callback-id", callback_id); |
| 218 | 220 |
| 219 bool enabled_status = false; | 221 bool enabled_status = false; |
| 220 ASSERT_TRUE(data.arg3()->GetAsBoolean(&enabled_status)); | 222 ASSERT_TRUE(data.arg3()->GetAsBoolean(&enabled_status)); |
| 221 EXPECT_TRUE(enabled_status); | 223 EXPECT_TRUE(enabled_status); |
| 222 } | 224 } |
| 223 | 225 |
| 224 TEST_F(EasyUnlockSettingsHandlerTest, TurnOffFlowStatus) { | 226 TEST_F(EasyUnlockSettingsHandlerTest, TurnOffFlowStatus) { |
| 225 scoped_ptr<EasyUnlockSettingsHandler> handler; | 227 std::unique_ptr<EasyUnlockSettingsHandler> handler; |
| 226 handler.reset(new TestEasyUnlockSettingsHandler(profile())); | 228 handler.reset(new TestEasyUnlockSettingsHandler(profile())); |
| 227 handler->set_web_ui(web_ui()); | 229 handler->set_web_ui(web_ui()); |
| 228 | 230 |
| 229 // Send an initial status query to turn on service observer. | 231 // Send an initial status query to turn on service observer. |
| 230 base::ListValue list_args1; | 232 base::ListValue list_args1; |
| 231 list_args1.Append(new base::StringValue("test-callback-id-1")); | 233 list_args1.Append(new base::StringValue("test-callback-id-1")); |
| 232 handler->HandleGetEnabledStatus(&list_args1); | 234 handler->HandleGetEnabledStatus(&list_args1); |
| 233 EXPECT_EQ(1U, web_ui()->call_data().size()); | 235 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 234 | 236 |
| 235 base::ListValue list_args2; | 237 base::ListValue list_args2; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 253 | 255 |
| 254 base::ListValue list_args4; | 256 base::ListValue list_args4; |
| 255 list_args4.Append(new base::StringValue("test-callback-id-4")); | 257 list_args4.Append(new base::StringValue("test-callback-id-4")); |
| 256 handler->HandleGetTurnOffFlowStatus(&list_args4); | 258 handler->HandleGetTurnOffFlowStatus(&list_args4); |
| 257 VerifyTurnOffFlowStatusWebUIResponse(7U, "test-callback-id-4", | 259 VerifyTurnOffFlowStatusWebUIResponse(7U, "test-callback-id-4", |
| 258 "server-error"); | 260 "server-error"); |
| 259 } | 261 } |
| 260 | 262 |
| 261 } // namespace settings | 263 } // namespace settings |
| 262 } // namespace chromeos | 264 } // namespace chromeos |
| OLD | NEW |