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

Side by Side Diff: chrome/browser/ui/webui/settings/profile_info_handler_unittest.cc

Issue 1900913002: Settings People Revamp: Split Profile Info out into its own handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « chrome/browser/ui/webui/settings/profile_info_handler.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/ui/webui/settings/profile_info_handler.h"
6
7 #include <memory>
8
9 #include "chrome/test/base/testing_browser_process.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "chrome/test/base/testing_profile_manager.h"
12 #include "content/public/browser/web_ui_data_source.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "content/public/test/test_web_ui.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
19 #include "components/user_manager/fake_user_manager.h"
20 #endif
21
22 namespace settings {
23
24 namespace {
25
26 class TestProfileInfoHandler : public ProfileInfoHandler {
27 public:
28 explicit TestProfileInfoHandler(Profile* profile)
29 : ProfileInfoHandler(profile) {}
30
31 using ProfileInfoHandler::set_web_ui;
32 };
33
34 } // namespace
35
36 class ProfileInfoHandlerTest : public testing::Test {
37 public:
38 ProfileInfoHandlerTest()
39 : profile_manager_(TestingBrowserProcess::GetGlobal()),
40 #if defined(OS_CHROMEOS)
41 user_manager_(new user_manager::FakeUserManager),
42 user_manager_enabler_(user_manager_),
43 #endif
44 profile_(nullptr) {
45 }
46
47 void SetUp() override {
48 ASSERT_TRUE(profile_manager_.SetUp());
49
50 #if defined(OS_CHROMEOS)
51 profile_ = profile_manager_.CreateTestingProfile("fake_id@gmail.com");
52 #else
53 profile_ = profile_manager_.CreateTestingProfile("Profile 1");
54 #endif
55
56 handler_.reset(new TestProfileInfoHandler(profile_));
57 handler_->set_web_ui(&web_ui_);
58 }
59
60 void VerifyResponse(const base::Value* call_argument) {
61 const base::DictionaryValue* response = nullptr;
62 ASSERT_TRUE(call_argument->GetAsDictionary(&response));
63
64 std::string name;
65 std::string icon_url;
66 ASSERT_TRUE(response->GetString("name", &name));
67 ASSERT_TRUE(response->GetString("iconUrl", &icon_url));
68
69 #if defined(OS_CHROMEOS)
70 EXPECT_EQ("fake_id@gmail.com", name);
71 EXPECT_FALSE(icon_url.empty());
72 #else
73 EXPECT_EQ("Profile 1", name);
74 EXPECT_EQ("chrome://theme/IDR_PROFILE_AVATAR_0", icon_url);
75 #endif
76 }
77
78 content::TestWebUI* web_ui() { return &web_ui_; }
79 Profile* profile() const { return profile_; }
80 TestProfileInfoHandler* handler() const { return handler_.get(); }
81
82 private:
83 content::TestBrowserThreadBundle thread_bundle_;
84 TestingProfileManager profile_manager_;
85 content::TestWebUI web_ui_;
86
87 #if defined(OS_CHROMEOS)
88 // |user_manager_| is destroyed by |user_manager_enabler_|.
89 user_manager::FakeUserManager* user_manager_;
90 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
91 #endif
92
93 Profile* profile_;
94 std::unique_ptr<TestProfileInfoHandler> handler_;
95 };
96
97 TEST_F(ProfileInfoHandlerTest, GetProfileInfo) {
98 base::ListValue list_args;
99 list_args.Append(new base::StringValue("get-profile-info-callback-id"));
100 handler()->HandleGetProfileInfo(&list_args);
101
102 EXPECT_EQ(1U, web_ui()->call_data().size());
103
104 const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
105 EXPECT_EQ("cr.webUIResponse", data.function_name());
106
107 std::string callback_id;
108 ASSERT_TRUE(data.arg1()->GetAsString(&callback_id));
109 EXPECT_EQ("get-profile-info-callback-id", callback_id);
110
111 bool success = false;
112 ASSERT_TRUE(data.arg2()->GetAsBoolean(&success));
113 EXPECT_TRUE(success);
114
115 VerifyResponse(data.arg3());
116 }
117
118 TEST_F(ProfileInfoHandlerTest, PushProfileInfo) {
119 base::ListValue list_args;
120 list_args.Append(new base::StringValue("get-profile-info-callback-id"));
121 handler()->HandleGetProfileInfo(&list_args);
122
123 handler()->OnProfileAvatarChanged(base::FilePath());
124
125 EXPECT_EQ(2U, web_ui()->call_data().size());
126
127 const content::TestWebUI::CallData& data = *web_ui()->call_data().back();
128 EXPECT_EQ("cr.webUIListenerCallback", data.function_name());
129
130 std::string event_id;
131 ASSERT_TRUE(data.arg1()->GetAsString(&event_id));
132 EXPECT_EQ(ProfileInfoHandler::kProfileInfoChangedEventName, event_id);
133
134 VerifyResponse(data.arg2());
135 }
136
137 } // namespace settings
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/profile_info_handler.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698