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

Side by Side Diff: chrome/browser/ui/views/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: Rebase Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/prefs/pref_service.h"
7 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/profiles/profile_manager.h" 10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/profiles/profile_metrics.h"
10 #include "chrome/browser/profiles/profiles_state.h" 12 #include "chrome/browser/profiles/profiles_state.h"
11 #include "chrome/browser/ui/browser_dialogs.h" 13 #include "chrome/browser/ui/browser_dialogs.h"
12 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/views/avatar_menu_button.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 16 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 17 #include "chrome/browser/ui/views/new_avatar_button.h"
15 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" 18 #include "chrome/browser/ui/views/profile_chooser_view.h"
16 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" 19 #include "chrome/browser/ui/views/user_manager_view.h"
17 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
18 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/profile_management_switches.h"
20 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/test_switches.h" 25 #include "chrome/test/base/test_switches.h"
22 #include "chrome/test/base/testing_browser_process.h" 26 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/uma_histogram_helper.h"
23 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
24 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
25 #include "ui/views/controls/button/label_button.h" 30 #include "ui/views/controls/button/label_button.h"
26 31
27 class NewAvatarMenuButtonTest : public InProcessBrowserTest { 32 class ProfileChooserViewBrowserTest : public InProcessBrowserTest {
28 public: 33 public:
29 NewAvatarMenuButtonTest(); 34 ProfileChooserViewBrowserTest();
30 virtual ~NewAvatarMenuButtonTest(); 35 virtual ~ProfileChooserViewBrowserTest();
31 36
32 protected: 37 protected:
33 virtual void SetUp() OVERRIDE; 38 virtual void SetUp() OVERRIDE;
34 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; 39 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
35 void CreateTestingProfile(); 40 void CreateTestingProfile();
36 void StartAvatarMenu(); 41 void OpenProfileChooserView();
37 42
38 private: 43 private:
39 DISALLOW_COPY_AND_ASSIGN(NewAvatarMenuButtonTest); 44 DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewBrowserTest);
40 }; 45 };
41 46
42 NewAvatarMenuButtonTest::NewAvatarMenuButtonTest() { 47 ProfileChooserViewBrowserTest::ProfileChooserViewBrowserTest() {
43 } 48 }
44 49
45 NewAvatarMenuButtonTest::~NewAvatarMenuButtonTest() { 50 ProfileChooserViewBrowserTest::~ProfileChooserViewBrowserTest() {
46 } 51 }
47 52
48 void NewAvatarMenuButtonTest::SetUp() { 53 void ProfileChooserViewBrowserTest::SetUp() {
49 InProcessBrowserTest::SetUp(); 54 InProcessBrowserTest::SetUp();
50 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch( 55 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
51 switches::kNewProfileManagement)); 56 switches::kNewProfileManagement));
52 } 57 }
53 58
54 void NewAvatarMenuButtonTest::SetUpCommandLine(CommandLine* command_line) { 59 void ProfileChooserViewBrowserTest::SetUpCommandLine(
60 CommandLine* command_line) {
55 command_line->AppendSwitch(switches::kNewProfileManagement); 61 command_line->AppendSwitch(switches::kNewProfileManagement);
56 } 62 }
57 63
58 void NewAvatarMenuButtonTest::CreateTestingProfile() { 64 void ProfileChooserViewBrowserTest::CreateTestingProfile() {
59 ProfileManager* profile_manager = g_browser_process->profile_manager(); 65 ProfileManager* profile_manager = g_browser_process->profile_manager();
60 EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles()); 66 EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles());
61 67
62 // Sign in the default profile 68 // Sign in the default profile
63 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 69 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
64 cache.SetUserNameOfProfileAtIndex(0, base::UTF8ToUTF16("user_name")); 70 cache.SetUserNameOfProfileAtIndex(0, base::UTF8ToUTF16("user_name"));
65 71
66 base::FilePath path; 72 base::FilePath path;
67 PathService::Get(chrome::DIR_USER_DATA, &path); 73 PathService::Get(chrome::DIR_USER_DATA, &path);
68 path = path.AppendASCII("test_profile"); 74 path = path.AppendASCII("test_profile");
69 if (!base::PathExists(path)) 75 if (!base::PathExists(path))
70 ASSERT_TRUE(base::CreateDirectory(path)); 76 ASSERT_TRUE(base::CreateDirectory(path));
71 Profile* profile = 77 Profile* profile =
72 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); 78 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
79 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarTutorialShown, 0);
73 profile_manager->RegisterTestingProfile(profile, true, false); 80 profile_manager->RegisterTestingProfile(profile, true, false);
74 EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles()); 81 EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles());
75 } 82 }
76 83
77 void NewAvatarMenuButtonTest::StartAvatarMenu() { 84 void ProfileChooserViewBrowserTest::OpenProfileChooserView() {
78 BrowserView* browser_view = reinterpret_cast<BrowserView*>( 85 BrowserView* browser_view = reinterpret_cast<BrowserView*>(
79 browser()->window()); 86 browser()->window());
87 UMAHistogramHelper histograms;
80 88
81 // Ensure that the avatar icon button is not also showing. 89 // Ensure that the avatar icon button is not also showing.
82 NewAvatarButton* button = browser_view->frame()->GetNewAvatarMenuButton(); 90 NewAvatarButton* button = browser_view->frame()->GetNewAvatarMenuButton();
83 ASSERT_TRUE(button); 91 ASSERT_TRUE(button);
84 ASSERT_FALSE(browser_view->frame()->GetAvatarMenuButton()); 92 ASSERT_FALSE(browser_view->frame()->GetAvatarMenuButton());
85 93
86 ProfileChooserView::clear_close_on_deactivate_for_testing(); 94 ProfileChooserView::clear_close_on_deactivate_for_testing();
87 ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0, 95 ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0,
88 0); 96 0);
89 button->NotifyClick(mouse_ev); 97 button->NotifyClick(mouse_ev);
90 base::MessageLoop::current()->RunUntilIdle(); 98 base::MessageLoop::current()->RunUntilIdle();
99
91 EXPECT_TRUE(ProfileChooserView::IsShowing()); 100 EXPECT_TRUE(ProfileChooserView::IsShowing());
92 } 101 }
93 102
94 #if defined(OS_CHROMEOS) || defined (OS_LINUX) || defined (OS_WIN) 103 #if defined(OS_CHROMEOS) || defined (OS_LINUX)
95 // This test doesn't make sense for ChromeOS since it has a different 104 // This test doesn't make sense for ChromeOS since it has a different
96 // multi-profiles menu in the system tray instead. 105 // multi-profiles menu in the system tray instead.
97 // 106 //
98 // Test fails flakily on Linux and Windows http://crbug.com/352710 107 // Expect tests to be flaky on Linux, since this test was copied from
99 #define MAYBE_SignOut DISABLED_SignOut 108 // new_avatar_menu_button_browsertest.cc, which quotes http://crbug.com/352710.
109 // Windows test verified as working even through the observed flaky behaviour.
110 #define MAYBE_ViewProfileUMA DISABLED_ViewProfileUMA
100 #else 111 #else
101 #define MAYBE_SignOut SignOut 112 #define MAYBE_ViewProfileUMA ViewProfileUMA
102 #endif 113 #endif
103 114
104 IN_PROC_BROWSER_TEST_F(NewAvatarMenuButtonTest, MAYBE_SignOut) { 115 IN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, MAYBE_ViewProfileUMA) {
116 UMAHistogramHelper histograms;
105 // If multiprofile mode is not enabled, you can't switch between profiles. 117 // If multiprofile mode is not enabled, you can't switch between profiles.
106 if (!profiles::IsMultipleProfilesEnabled()) 118 if (!profiles::IsMultipleProfilesEnabled())
107 return; 119 return;
108 120
109 CreateTestingProfile(); 121 CreateTestingProfile();
110 ASSERT_NO_FATAL_FAILURE(StartAvatarMenu()); 122 ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView());
111 123
112 BrowserList* browser_list = 124 histograms.Fetch();
113 BrowserList::GetInstance(chrome::GetActiveDesktop()); 125 histograms.ExpectUniqueSample("Profile.MirrorPromo",
114 EXPECT_EQ(1U, browser_list->size()); 126 ProfileMetrics::PROMO_DISPLAY, 1);
115 content::WindowedNotificationObserver window_close_observer(
116 chrome::NOTIFICATION_BROWSER_CLOSED,
117 content::Source<Browser>(browser()));
118
119 AvatarMenu* menu =
120 ProfileChooserView::profile_bubble_->avatar_menu_.get();
121 const AvatarMenu::Item& menu_item_before =
122 menu->GetItemAt(menu->GetActiveProfileIndex());
123 EXPECT_FALSE(menu_item_before.signin_required);
124
125 ui::MouseEvent mouse_ev(
126 ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0, 0);
127 ProfileChooserView::profile_bubble_->ButtonPressed(
128 ProfileChooserView::profile_bubble_->lock_button_, mouse_ev);
129
130 EXPECT_TRUE(menu->GetItemAt(menu->GetActiveProfileIndex()).signin_required);
131
132 window_close_observer.Wait(); // Rely on test timeout for failure indication.
133 EXPECT_TRUE(browser_list->empty());
134 127
135 // If the User Manager hasn't shown yet, wait for it to show up. 128 // If the User Manager hasn't shown yet, wait for it to show up.
136 if (!UserManagerView::IsShowing()) 129 if (!UserManagerView::IsShowing())
137 base::MessageLoop::current()->RunUntilIdle(); 130 base::MessageLoop::current()->RunUntilIdle();
138 131
139 // We need to hide the User Manager or else the process can't die. 132 // We need to hide the User Manager or else the process can't die.
140 chrome::HideUserManager(); 133 chrome::HideUserManager();
141 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698