profile_chooser_view_browsertest.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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(switches::IsNewAvatarMenu()); 57} 58 59void ProfileChooserViewBrowserTest::SetUpCommandLine( 60 CommandLine* command_line) { 61 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); 62} 63 64void ProfileChooserViewBrowserTest::OpenProfileChooserView() { 65 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser()); 66 NewAvatarButton* button = browser_view->frame()->GetNewAvatarMenuButton(); 67 ASSERT_TRUE(button); 68 69 ProfileChooserView::clear_close_on_deactivate_for_testing(); 70 ui::MouseEvent mouse_ev(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), 0, 71 0); 72 button->NotifyClick(mouse_ev); 73 base::MessageLoop::current()->RunUntilIdle(); 74 EXPECT_TRUE(ProfileChooserView::IsShowing()); 75} 76 77#if defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS) 78// This test doesn't make sense for ChromeOS since it has a different 79// multi-profiles menu in the system tray instead. 80// 81// Mobile platforms are also excluded due to a lack of avatar menu. 82#define MAYBE_ViewProfileUMA DISABLED_ViewProfileUMA 83#else 84#define MAYBE_ViewProfileUMA ViewProfileUMA 85#endif 86 87// TODO(mlerman): Re-enable the test to MAYBE_ViewProfileUMA once there is a 88// launch plan for EnableAccountConsistency. 89IN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, DISABLED_ViewProfileUMA) { 90 UMAHistogramHelper histograms; 91 // If multiprofile mode is not enabled, you can't switch between profiles. 92 if (!profiles::IsMultipleProfilesEnabled()) 93 return; 94 95 Profile* profile = browser()->profile(); 96 profile->GetPrefs()->SetInteger(prefs::kProfileAvatarTutorialShown, 0); 97 98 ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView()); 99 100 histograms.Fetch(); 101 histograms.ExpectUniqueSample("Profile.UpgradeEnrollment", 102 ProfileMetrics::PROFILE_ENROLLMENT_SHOW_PREVIEW_PROMO, 1); 103} 104