Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / avatar_menu_button_browsertest.cc
blobdb3f3097905c41d88ef1e59323555bad0c0a5363
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/views/avatar_menu_button.h"
7 #include "base/command_line.h"
8 #include "base/path_service.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/profiles/profiles_state.h"
12 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/test_switches.h"
19 #include "chrome/test/base/testing_browser_process.h"
20 #include "grit/generated_resources.h"
22 class AvatarMenuButtonTest : public InProcessBrowserTest {
23 public:
24 AvatarMenuButtonTest();
25 virtual ~AvatarMenuButtonTest();
27 protected:
28 void CreateTestingProfile();
29 AvatarMenuButton* GetAvatarMenuButton();
30 void StartAvatarMenu();
32 private:
33 DISALLOW_COPY_AND_ASSIGN(AvatarMenuButtonTest);
36 AvatarMenuButtonTest::AvatarMenuButtonTest() {
39 AvatarMenuButtonTest::~AvatarMenuButtonTest() {
42 void AvatarMenuButtonTest::CreateTestingProfile() {
43 ProfileManager* profile_manager = g_browser_process->profile_manager();
44 EXPECT_EQ(1u, profile_manager->GetNumberOfProfiles());
46 base::FilePath path;
47 PathService::Get(chrome::DIR_USER_DATA, &path);
48 path = path.AppendASCII("test_profile");
49 if (!base::PathExists(path))
50 ASSERT_TRUE(base::CreateDirectory(path));
51 Profile* profile =
52 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
53 profile_manager->RegisterTestingProfile(profile, true, false);
54 EXPECT_EQ(2u, profile_manager->GetNumberOfProfiles());
57 AvatarMenuButton* AvatarMenuButtonTest::GetAvatarMenuButton() {
58 BrowserView* browser_view = reinterpret_cast<BrowserView*>(
59 browser()->window());
60 return browser_view->frame()->GetAvatarMenuButton();
63 void AvatarMenuButtonTest::StartAvatarMenu() {
64 AvatarMenuButton* button = GetAvatarMenuButton();
65 ASSERT_TRUE(button);
67 AvatarMenuBubbleView::clear_close_on_deactivate_for_testing();
68 static_cast<views::MenuButtonListener*>(button)->OnMenuButtonClicked(
69 NULL, gfx::Point());
70 base::MessageLoop::current()->RunUntilIdle();
71 EXPECT_TRUE(AvatarMenuBubbleView::IsShowing());
74 // See http://crbug.com/315732
75 #if defined(OS_WIN)
76 #define MAYBE_HideOnSecondClick DISABLED_HideOnSecondClick
77 #else
78 #define MAYBE_HideOnSecondClick HideOnSecondClick
79 #endif
81 IN_PROC_BROWSER_TEST_F(AvatarMenuButtonTest, MAYBE_HideOnSecondClick) {
82 #if defined(OS_WIN) && defined(USE_ASH)
83 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
84 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
85 return;
86 #endif
88 // If multiprofile mode is not enabled, you can't switch between profiles.
89 if (!profiles::IsMultipleProfilesEnabled())
90 return;
92 CreateTestingProfile();
93 ASSERT_NO_FATAL_FAILURE(StartAvatarMenu());
95 // Verify that clicking again doesn't reshow it.
96 AvatarMenuButton* button = GetAvatarMenuButton();
97 static_cast<views::MenuButtonListener*>(button)->OnMenuButtonClicked(
98 NULL, gfx::Point());
99 // Hide the bubble manually. In the browser this would normally happen during
100 // the event processing.
101 AvatarMenuBubbleView::Hide();
102 base::MessageLoop::current()->RunUntilIdle();
103 EXPECT_FALSE(AvatarMenuBubbleView::IsShowing());