Home | History | Annotate | Download | only in profiles
      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 "base/test/histogram_tester.h"
     12 #include "chrome/browser/chrome_notification_types.h"
     13 #include "chrome/browser/profiles/profile_manager.h"
     14 #include "chrome/browser/profiles/profile_metrics.h"
     15 #include "chrome/browser/profiles/profiles_state.h"
     16 #include "chrome/browser/ui/browser_dialogs.h"
     17 #include "chrome/browser/ui/browser_list.h"
     18 #include "chrome/browser/ui/views/frame/browser_view.h"
     19 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
     20 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
     21 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
     22 #include "chrome/common/chrome_paths.h"
     23 #include "chrome/common/chrome_switches.h"
     24 #include "chrome/common/pref_names.h"
     25 #include "chrome/test/base/in_process_browser_test.h"
     26 #include "chrome/test/base/test_switches.h"
     27 #include "chrome/test/base/testing_browser_process.h"
     28 #include "chrome/test/base/testing_profile_manager.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 
     33 class 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 
     47 ProfileChooserViewBrowserTest::ProfileChooserViewBrowserTest() {
     48 }
     49 
     50 ProfileChooserViewBrowserTest::~ProfileChooserViewBrowserTest() {
     51 }
     52 
     53 void ProfileChooserViewBrowserTest::SetUp() {
     54   InProcessBrowserTest::SetUp();
     55   DCHECK(switches::IsNewAvatarMenu());
     56 }
     57 
     58 void ProfileChooserViewBrowserTest::SetUpCommandLine(
     59     CommandLine* command_line) {
     60   switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess());
     61 }
     62 
     63 void 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 IN_PROC_BROWSER_TEST_F(ProfileChooserViewBrowserTest, MAYBE_ViewProfileUMA) {
     87   base::HistogramTester histograms;
     88   // If multiprofile mode is not enabled, you can't switch between profiles.
     89   if (!profiles::IsMultipleProfilesEnabled())
     90     return;
     91 
     92   Profile* profile = browser()->profile();
     93   profile->GetPrefs()->SetInteger(prefs::kProfileAvatarTutorialShown, 0);
     94 
     95   ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView());
     96 
     97   histograms.ExpectUniqueSample("Profile.NewAvatarMenu.Upgrade",
     98       ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW, 1);
     99 }
    100