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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view_browsertest.cc

Issue 227083007: UMA for New Profile Management. Track User-Menu Tutorial actions with Histograms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits and update for unit tests; update histograms.xml Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_chooser_view.cc ('k') | chrome/chrome_tests.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 2014 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 "base/command_line.h"
6 #include "base/path_service.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/profiles/profile_metrics.h"
12 #include "chrome/browser/profiles/profiles_state.h"
13 #include "chrome/browser/ui/browser_dialogs.h"
14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/views/frame/browser_view.h"
16 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
17 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
18 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
19 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
20 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/test_switches.h"
25 #include "chrome/test/base/testing_browser_process.h"
26 #include "chrome/test/base/uma_histogram_helper.h"
27 #include "components/signin/core/common/profile_management_switches.h"
28 #include "content/public/test/test_utils.h"
29 #include "grit/generated_resources.h"
30 #include "ui/views/controls/button/label_button.h"
31
32 class ProfileChooserViewBrowserTest : public InProcessBrowserTest {
33 public:
34 ProfileChooserViewBrowserTest();
35 virtual ~ProfileChooserViewBrowserTest();
36
37 protected:
38 virtual void SetUp() OVERRIDE;
39 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
40 void CreateTestingProfile();
41 void OpenProfileChooserView();
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewBrowserTest);
45 };
46
47 ProfileChooserViewBrowserTest::ProfileChooserViewBrowserTest() {
48 }
49
50 ProfileChooserViewBrowserTest::~ProfileChooserViewBrowserTest() {
51 }
52
53 void ProfileChooserViewBrowserTest::SetUp() {
54 InProcessBrowserTest::SetUp();
55 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
56 switches::kNewAvatarMenu));
57 }
58
59 void ProfileChooserViewBrowserTest::SetUpCommandLine(
60 CommandLine* command_line) {
61 command_line->AppendSwitch(switches::kNewAvatarMenu);
62 }
63
64 void ProfileChooserViewBrowserTest::CreateTestingProfile() {
65 ProfileManager* profile_manager = g_browser_process->profile_manager();
66 EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles());
67
68 // Sign in the default profile
69 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
70 cache.SetUserNameOfProfileAtIndex(0, base::UTF8ToUTF16("user_name"));
71
72 base::FilePath path;
73 PathService::Get(chrome::DIR_USER_DATA, &path);
74 path = path.AppendASCII("test_profile");
75 if (!base::PathExists(path))
76 ASSERT_TRUE(base::CreateDirectory(path));
77 Profile* profile =
78 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
79 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarTutorialShown, 0);
80 profile_manager->RegisterTestingProfile(profile, true, false);
81 EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles());
82 }
83
84 void ProfileChooserViewBrowserTest::OpenProfileChooserView() {
85 BrowserView* browser_view = reinterpret_cast<BrowserView*>(
86 browser()->window());
87
88 // Ensure that the avatar icon button is not also showing.
89 NewAvatarButton* button = browser_view->frame()->GetNewAvatarMenuButton();
90 ASSERT_TRUE(button);
91
92 ProfileChooserView::clear_close_on_deactivate_for_testing();
93 ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0,
94 0);
95 button->NotifyClick(mouse_ev);
96 base::MessageLoop::current()->RunUntilIdle();
97 EXPECT_TRUE(ProfileChooserView::IsShowing());
98 }
99
100 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS)
101 // This test doesn't make sense for ChromeOS since it has a different
102 // multi-profiles menu in the system tray instead.
103 //
104 // Mobile platforms are also excluded due to a lack of avatar menu.
105 #define MAYBE_ViewProfileUMA DISABLED_ViewProfileUMA
106 #else
107 #define MAYBE_ViewProfileUMA ViewProfileUMA
108 #endif
109
110 IN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, MAYBE_ViewProfileUMA) {
noms (inactive) 2014/04/29 20:33:48 This shouldn't be a MAYBE_, if it's not flaky :)
Mike Lerman 2014/04/29 20:39:07 Discuss in person - we'll keep the current structu
111 UMAHistogramHelper histograms;
112 // If multiprofile mode is not enabled, you can't switch between profiles.
113 if (!profiles::IsMultipleProfilesEnabled())
114 return;
115
116 CreateTestingProfile();
117 ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView());
118
119 histograms.Fetch();
120 histograms.ExpectUniqueSample("Profile.MirrorEnrollment",
121 ProfileMetrics::PROFILE_ENROLLMENT_SHOW_PREVIEW_PROMO, 1);
122
123 // If the User Manager hasn't shown yet, wait for it to show up.
124 if (!UserManagerView::IsShowing())
noms (inactive) 2014/04/29 20:33:48 You're just showing the bubble, which has nothing
Mike Lerman 2014/04/29 20:39:07 Done.
125 base::MessageLoop::current()->RunUntilIdle();
126
127 // We need to hide the User Manager or else the process can't die.
128 chrome::HideUserManager();
129 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/profiles/profile_chooser_view.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698