1010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// found in the LICENSE file.
4010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
5010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
7010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/command_line.h"
8010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/path_service.h"
9010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/prefs/pref_service.h"
10010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "base/strings/utf_string_conversions.h"
1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "base/test/histogram_tester.h"
12010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/chrome_notification_types.h"
13010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
14010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/profiles/profile_metrics.h"
15010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/profiles/profiles_state.h"
16010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/browser_dialogs.h"
17010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/browser_list.h"
18010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/views/frame/browser_view.h"
19010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
20010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/views/profiles/new_avatar_button.h"
21010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/browser/ui/views/profiles/user_manager_view.h"
22010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/common/chrome_paths.h"
23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/common/chrome_switches.h"
24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/common/pref_names.h"
25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/test/base/test_switches.h"
27010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/test/base/testing_browser_process.h"
28010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "chrome/test/base/testing_profile_manager.h"
29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "components/signin/core/common/profile_management_switches.h"
30010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/public/test/test_utils.h"
31010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ui/views/controls/button/label_button.h"
32010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
33010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class ProfileChooserViewBrowserTest : public InProcessBrowserTest {
34010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) public:
35010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ProfileChooserViewBrowserTest();
36010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual ~ProfileChooserViewBrowserTest();
37010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
38010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) protected:
39010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void SetUp() OVERRIDE;
40010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
41010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  void OpenProfileChooserView();
42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) private:
44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewBrowserTest);
45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)};
46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)ProfileChooserViewBrowserTest::ProfileChooserViewBrowserTest() {
48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)ProfileChooserViewBrowserTest::~ProfileChooserViewBrowserTest() {
51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
52010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
53010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void ProfileChooserViewBrowserTest::SetUp() {
54010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  InProcessBrowserTest::SetUp();
555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DCHECK(switches::IsNewAvatarMenu());
56010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
57010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
58010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void ProfileChooserViewBrowserTest::SetUpCommandLine(
59010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    CommandLine* command_line) {
605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
61010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
62010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
63010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void ProfileChooserViewBrowserTest::OpenProfileChooserView() {
64010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
65010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  NewAvatarButton* button = browser_view->frame()->GetNewAvatarMenuButton();
66010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ASSERT_TRUE(button);
67010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
68010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ProfileChooserView::clear_close_on_deactivate_for_testing();
69010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0,
70010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                          0);
71010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  button->NotifyClick(mouse_ev);
72010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  base::MessageLoop::current()->RunUntilIdle();
73010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(ProfileChooserView::IsShowing());
74010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
75010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
76010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#if defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS)
77010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// This test doesn't make sense for ChromeOS since it has a different
78010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// multi-profiles menu in the system tray instead.
79010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)//
80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)// Mobile platforms are also excluded due to a lack of avatar menu.
81010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#define MAYBE_ViewProfileUMA DISABLED_ViewProfileUMA
82010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#else
83010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#define MAYBE_ViewProfileUMA ViewProfileUMA
84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#endif
85010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciIN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, MAYBE_ViewProfileUMA) {
871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::HistogramTester histograms;
881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // If multiprofile mode is not enabled, you can't switch between profiles.
89010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  if (!profiles::IsMultipleProfilesEnabled())
90010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    return;
91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
92010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  Profile* profile = browser()->profile();
93010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  profile->GetPrefs()->SetInteger(prefs::kProfileAvatarTutorialShown, 0);
94010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
95010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView());
961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  histograms.ExpectUniqueSample("Profile.NewAvatarMenu.Upgrade",
981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW, 1);
99010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
100