summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/profiles/profile_chooser_view_browsertest.cc
blob: af8fc1e2711c976fcaceaf6f60299e5cbf3fa700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/profiles/profile_chooser_view.h"

#include "base/command_line.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_metrics.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
#include "chrome/browser/ui/views/profiles/new_avatar_button.h"
#include "chrome/browser/ui/views/profiles/user_manager_view.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "chrome/test/base/uma_histogram_helper.h"
#include "components/signin/core/common/profile_management_switches.h"
#include "content/public/test/test_utils.h"
#include "grit/generated_resources.h"
#include "ui/views/controls/button/label_button.h"

class ProfileChooserViewBrowserTest : public InProcessBrowserTest {
 public:
  ProfileChooserViewBrowserTest();
  virtual ~ProfileChooserViewBrowserTest();

 protected:
  virtual void SetUp() OVERRIDE;
  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
  void OpenProfileChooserView();

 private:
  DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewBrowserTest);
};

ProfileChooserViewBrowserTest::ProfileChooserViewBrowserTest() {
}

ProfileChooserViewBrowserTest::~ProfileChooserViewBrowserTest() {
}

void ProfileChooserViewBrowserTest::SetUp() {
  InProcessBrowserTest::SetUp();
  DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
      switches::kNewAvatarMenu));
}

void ProfileChooserViewBrowserTest::SetUpCommandLine(
    CommandLine* command_line) {
  command_line->AppendSwitch(switches::kNewAvatarMenu);
}

void ProfileChooserViewBrowserTest::OpenProfileChooserView() {
  BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
  NewAvatarButton* button = browser_view->frame()->GetNewAvatarMenuButton();
  ASSERT_TRUE(button);

  ProfileChooserView::clear_close_on_deactivate_for_testing();
  ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0,
                          0);
  button->NotifyClick(mouse_ev);
  base::MessageLoop::current()->RunUntilIdle();
  EXPECT_TRUE(ProfileChooserView::IsShowing());
}

#if defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS)
// This test doesn't make sense for ChromeOS since it has a different
// multi-profiles menu in the system tray instead.
//
// Mobile platforms are also excluded due to a lack of avatar menu.
#define MAYBE_ViewProfileUMA DISABLED_ViewProfileUMA
#else
#define MAYBE_ViewProfileUMA ViewProfileUMA
#endif

IN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, MAYBE_ViewProfileUMA) {
  UMAHistogramHelper histograms;
  // If multiprofile mode is not enabled, you can't switch between profiles.
  if (!profiles::IsMultipleProfilesEnabled())
    return;

  Profile* profile = browser()->profile();
  profile->GetPrefs()->SetInteger(prefs::kProfileAvatarTutorialShown, 0);

  ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView());

  histograms.Fetch();
  histograms.ExpectUniqueSample("Profile.UpgradeEnrollment",
      ProfileMetrics::PROFILE_ENROLLMENT_SHOW_PREVIEW_PROMO, 1);
}