| 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/settings_manage_profile_handler.h" | 5 #include "chrome/browser/ui/webui/settings/settings_manage_profile_handler.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
| 9 #include "chrome/test/base/testing_browser_process.h" | 9 #include "chrome/test/base/testing_browser_process.h" |
| 10 #include "chrome/test/base/testing_profile_manager.h" | 10 #include "chrome/test/base/testing_profile_manager.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 profile_(nullptr) {} | 35 profile_(nullptr) {} |
| 36 | 36 |
| 37 void SetUp() override { | 37 void SetUp() override { |
| 38 ASSERT_TRUE(profile_manager_.SetUp()); | 38 ASSERT_TRUE(profile_manager_.SetUp()); |
| 39 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); | 39 profile_ = profile_manager_.CreateTestingProfile("Profile 1"); |
| 40 | 40 |
| 41 handler_.reset(new TestManageProfileHandler(profile_)); | 41 handler_.reset(new TestManageProfileHandler(profile_)); |
| 42 handler_->set_web_ui(&web_ui_); | 42 handler_->set_web_ui(&web_ui_); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void VerifyIconList(const base::Value* value) { |
| 46 const base::ListValue* icon_urls = nullptr; |
| 47 ASSERT_TRUE(value->GetAsList(&icon_urls)); |
| 48 |
| 49 // Expect the list of icon URLs to be a non-empty list of non-empty strings. |
| 50 EXPECT_FALSE(icon_urls->empty()); |
| 51 for (size_t i = 0; i < icon_urls->GetSize(); ++i) { |
| 52 std::string icon_url; |
| 53 EXPECT_TRUE(icon_urls->GetString(i, &icon_url)); |
| 54 EXPECT_FALSE(icon_url.empty()); |
| 55 } |
| 56 } |
| 57 |
| 45 content::TestWebUI* web_ui() { return &web_ui_; } | 58 content::TestWebUI* web_ui() { return &web_ui_; } |
| 46 Profile* profile() const { return profile_; } | 59 Profile* profile() const { return profile_; } |
| 47 TestManageProfileHandler* handler() const { return handler_.get(); } | 60 TestManageProfileHandler* handler() const { return handler_.get(); } |
| 48 | 61 |
| 49 private: | 62 private: |
| 50 content::TestBrowserThreadBundle thread_bundle_; | 63 content::TestBrowserThreadBundle thread_bundle_; |
| 51 TestingProfileManager profile_manager_; | 64 TestingProfileManager profile_manager_; |
| 52 content::TestWebUI web_ui_; | 65 content::TestWebUI web_ui_; |
| 53 | 66 |
| 54 Profile* profile_; | 67 Profile* profile_; |
| 55 scoped_ptr<TestManageProfileHandler> handler_; | 68 scoped_ptr<TestManageProfileHandler> handler_; |
| 56 }; | 69 }; |
| 57 | 70 |
| 58 TEST_F(ManageProfileHandlerTest, SetProfileIconAndName) { | 71 TEST_F(ManageProfileHandlerTest, HandleSetProfileIconAndName) { |
| 59 base::ListValue list_args; | 72 base::ListValue list_args; |
| 60 list_args.Append( | 73 list_args.Append( |
| 61 new base::StringValue("chrome://theme/IDR_PROFILE_AVATAR_15")); | 74 new base::StringValue("chrome://theme/IDR_PROFILE_AVATAR_15")); |
| 62 list_args.Append(new base::StringValue("New Profile Name")); | 75 list_args.Append(new base::StringValue("New Profile Name")); |
| 63 handler()->HandleSetProfileIconAndName(&list_args); | 76 handler()->HandleSetProfileIconAndName(&list_args); |
| 64 | 77 |
| 65 PrefService* pref_service = profile()->GetPrefs(); | 78 PrefService* pref_service = profile()->GetPrefs(); |
| 66 | 79 |
| 67 EXPECT_EQ(15, pref_service->GetInteger(prefs::kProfileAvatarIndex)); | 80 EXPECT_EQ(15, pref_service->GetInteger(prefs::kProfileAvatarIndex)); |
| 68 EXPECT_FALSE(pref_service->GetBoolean(prefs::kProfileUsingDefaultAvatar)); | 81 EXPECT_FALSE(pref_service->GetBoolean(prefs::kProfileUsingDefaultAvatar)); |
| 69 EXPECT_FALSE(pref_service->GetBoolean(prefs::kProfileUsingGAIAAvatar)); | 82 EXPECT_FALSE(pref_service->GetBoolean(prefs::kProfileUsingGAIAAvatar)); |
| 70 EXPECT_EQ("New Profile Name", pref_service->GetString(prefs::kProfileName)); | 83 EXPECT_EQ("New Profile Name", pref_service->GetString(prefs::kProfileName)); |
| 71 } | 84 } |
| 72 | 85 |
| 73 TEST_F(ManageProfileHandlerTest, GetAvailableIcons) { | 86 TEST_F(ManageProfileHandlerTest, HandleGetAvailableIcons) { |
| 74 handler()->HandleGetAvailableIcons(nullptr); | 87 base::ListValue list_args; |
| 88 list_args.Append(new base::StringValue("get-icons-callback-id")); |
| 89 handler()->HandleGetAvailableIcons(&list_args); |
| 90 |
| 91 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 92 |
| 93 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 94 EXPECT_EQ("cr.webUIResponse", data.function_name()); |
| 95 |
| 96 std::string callback_id; |
| 97 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); |
| 98 EXPECT_EQ("get-icons-callback-id", callback_id); |
| 99 |
| 100 VerifyIconList(data.arg3()); |
| 101 } |
| 102 |
| 103 TEST_F(ManageProfileHandlerTest, ProfileAvatarChangedWebUIEvent) { |
| 104 handler()->OnProfileAvatarChanged(base::FilePath()); |
| 75 | 105 |
| 76 EXPECT_EQ(1U, web_ui()->call_data().size()); | 106 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 77 | 107 |
| 78 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); | 108 const content::TestWebUI::CallData& data = *web_ui()->call_data().back(); |
| 79 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); | 109 EXPECT_EQ("cr.webUIListenerCallback", data.function_name()); |
| 80 | 110 |
| 81 std::string callback_id; | 111 std::string event_id; |
| 82 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id)); | 112 ASSERT_TRUE(data.arg1()->GetAsString(&event_id)); |
| 83 EXPECT_EQ("available-icons-changed", callback_id); | 113 EXPECT_EQ("available-icons-changed", event_id); |
| 84 | 114 |
| 85 const base::ListValue* icon_urls = nullptr; | 115 VerifyIconList(data.arg2()); |
| 86 ASSERT_TRUE(data.arg2()->GetAsList(&icon_urls)); | |
| 87 | |
| 88 // Expect the list of icon URLs to be a non-empty list of non-empty strings. | |
| 89 EXPECT_FALSE(icon_urls->empty()); | |
| 90 for (size_t i = 0; i < icon_urls->GetSize(); ++i) { | |
| 91 std::string icon_url; | |
| 92 EXPECT_TRUE(icon_urls->GetString(i, &icon_url)); | |
| 93 EXPECT_FALSE(icon_url.empty()); | |
| 94 } | |
| 95 } | 116 } |
| 96 | 117 |
| 97 } // namespace settings | 118 } // namespace settings |
| OLD | NEW |