profile_chooser_view_browsertest.cc revision 010d83a9304c5a91596085d917d248abff47903a
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 "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6
7#include "base/command_line.h"
8#include "base/path_service.h"
9#include "base/prefs/pref_service.h"
10#include "base/strings/utf_string_conversions.h"
11#include "chrome/browser/chrome_notification_types.h"
12#include "chrome/browser/profiles/profile_manager.h"
13#include "chrome/browser/profiles/profile_metrics.h"
14#include "chrome/browser/profiles/profiles_state.h"
15#include "chrome/browser/ui/browser_dialogs.h"
16#include "chrome/browser/ui/browser_list.h"
17#include "chrome/browser/ui/views/frame/browser_view.h"
18#include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
19#include "chrome/browser/ui/views/profiles/new_avatar_button.h"
20#include "chrome/browser/ui/views/profiles/user_manager_view.h"
21#include "chrome/common/chrome_paths.h"
22#include "chrome/common/chrome_switches.h"
23#include "chrome/common/pref_names.h"
24#include "chrome/test/base/in_process_browser_test.h"
25#include "chrome/test/base/test_switches.h"
26#include "chrome/test/base/testing_browser_process.h"
27#include "chrome/test/base/testing_profile_manager.h"
28#include "chrome/test/base/uma_histogram_helper.h"
29#include "components/signin/core/common/profile_management_switches.h"
30#include "content/public/test/test_utils.h"
31#include "grit/generated_resources.h"
32#include "ui/views/controls/button/label_button.h"
33
34class ProfileChooserViewBrowserTest : public InProcessBrowserTest {
35 public:
36  ProfileChooserViewBrowserTest();
37  virtual ~ProfileChooserViewBrowserTest();
38
39 protected:
40  virtual void SetUp() OVERRIDE;
41  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
42  void OpenProfileChooserView();
43
44 private:
45  DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewBrowserTest);
46};
47
48ProfileChooserViewBrowserTest::ProfileChooserViewBrowserTest() {
49}
50
51ProfileChooserViewBrowserTest::~ProfileChooserViewBrowserTest() {
52}
53
54void ProfileChooserViewBrowserTest::SetUp() {
55  InProcessBrowserTest::SetUp();
56  DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
57      switches::kNewAvatarMenu));
58}
59
60void ProfileChooserViewBrowserTest::SetUpCommandLine(
61    CommandLine* command_line) {
62  command_line->AppendSwitch(switches::kNewAvatarMenu);
63}
64
65void ProfileChooserViewBrowserTest::OpenProfileChooserView() {
66  BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
67  NewAvatarButton* button = browser_view->frame()->GetNewAvatarMenuButton();
68  ASSERT_TRUE(button);
69
70  ProfileChooserView::clear_close_on_deactivate_for_testing();
71  ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0,
72                          0);
73  button->NotifyClick(mouse_ev);
74  base::MessageLoop::current()->RunUntilIdle();
75  EXPECT_TRUE(ProfileChooserView::IsShowing());
76}
77
78#if defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS)
79// This test doesn't make sense for ChromeOS since it has a different
80// multi-profiles menu in the system tray instead.
81//
82// Mobile platforms are also excluded due to a lack of avatar menu.
83#define MAYBE_ViewProfileUMA DISABLED_ViewProfileUMA
84#else
85#define MAYBE_ViewProfileUMA ViewProfileUMA
86#endif
87
88IN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, MAYBE_ViewProfileUMA) {
89  UMAHistogramHelper histograms;
90  // If multiprofile mode is not enabled, you can't switch between profiles.
91  if (!profiles::IsMultipleProfilesEnabled())
92    return;
93
94  Profile* profile = browser()->profile();
95  profile->GetPrefs()->SetInteger(prefs::kProfileAvatarTutorialShown, 0);
96
97  ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView());
98
99  histograms.Fetch();
100  histograms.ExpectUniqueSample("Profile.UpgradeEnrollment",
101      ProfileMetrics::PROFILE_ENROLLMENT_SHOW_PREVIEW_PROMO, 1);
102}
103