profile_chooser_view_browsertest.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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 "ui/views/controls/button/label_button.h"
32
33class ProfileChooserViewBrowserTest : public InProcessBrowserTest {
34 public:
35  ProfileChooserViewBrowserTest();
36  virtual ~ProfileChooserViewBrowserTest();
37
38 protected:
39  virtual void SetUp() OVERRIDE;
40  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
41  void OpenProfileChooserView();
42
43 private:
44  DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewBrowserTest);
45};
46
47ProfileChooserViewBrowserTest::ProfileChooserViewBrowserTest() {
48}
49
50ProfileChooserViewBrowserTest::~ProfileChooserViewBrowserTest() {
51}
52
53void ProfileChooserViewBrowserTest::SetUp() {
54  InProcessBrowserTest::SetUp();
55  DCHECK(switches::IsNewAvatarMenu());
56}
57
58void ProfileChooserViewBrowserTest::SetUpCommandLine(
59    CommandLine* command_line) {
60  switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
61}
62
63void ProfileChooserViewBrowserTest::OpenProfileChooserView() {
64  BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
65  NewAvatarButton* button = browser_view->frame()->GetNewAvatarMenuButton();
66  ASSERT_TRUE(button);
67
68  ProfileChooserView::clear_close_on_deactivate_for_testing();
69  ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0,
70                          0);
71  button->NotifyClick(mouse_ev);
72  base::MessageLoop::current()->RunUntilIdle();
73  EXPECT_TRUE(ProfileChooserView::IsShowing());
74}
75
76#if defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS)
77// This test doesn't make sense for ChromeOS since it has a different
78// multi-profiles menu in the system tray instead.
79//
80// Mobile platforms are also excluded due to a lack of avatar menu.
81#define MAYBE_ViewProfileUMA DISABLED_ViewProfileUMA
82#else
83#define MAYBE_ViewProfileUMA ViewProfileUMA
84#endif
85
86// TODO(mlerman): Re-enable the test to MAYBE_ViewProfileUMA once there is a
87// launch plan for EnableAccountConsistency.
88IN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, DISABLED_ViewProfileUMA) {
89  // If multiprofile mode is not enabled, you can't switch between profiles.
90  if (!profiles::IsMultipleProfilesEnabled())
91    return;
92
93  Profile* profile = browser()->profile();
94  profile->GetPrefs()->SetInteger(prefs::kProfileAvatarTutorialShown, 0);
95
96  ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView());
97}
98