Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(506)

Side by Side Diff: chrome/browser/ui/cocoa/browser/avatar_button_controller_unittest.mm

Issue 117533002: [Mac] Redesign of the avatar menu button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: now with less incorrect usage of initializers Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" 5 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
6 6
7 #include "base/command_line.h"
7 #include "base/mac/scoped_nsobject.h" 8 #include "base/mac/scoped_nsobject.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 10 #include "chrome/browser/profiles/profiles_state.h"
10 #include "chrome/browser/bookmarks/bookmark_test_helpers.h" 11 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/managed_mode/managed_user_service.h"
12 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
13 #include "chrome/browser/prefs/pref_service_syncable.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h"
15 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" 14 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
15 #import "chrome/browser/ui/cocoa/browser/profile_chooser_controller.h"
19 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 16 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
20 #include "chrome/browser/ui/cocoa/info_bubble_window.h" 17 #include "chrome/browser/ui/cocoa/info_bubble_window.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h" 19
23 #include "chrome/test/base/testing_profile.h" 20 const char kDefaultProfileName[] = "default";
24 21
25 class AvatarButtonControllerTest : public CocoaProfileTest { 22 class AvatarButtonControllerTest : public CocoaProfileTest {
26 public: 23 public:
27 virtual void SetUp() OVERRIDE { 24 virtual void SetUp() OVERRIDE {
25 CommandLine::ForCurrentProcess()->AppendSwitch(
26 switches::kNewProfileManagement);
27 DCHECK(CommandLine::ForCurrentProcess()->HasSwitch(
28 switches::kNewProfileManagement));
Nico 2014/01/23 00:51:33 This DCHECK seems pointless, given that the switch
noms (inactive) 2014/01/23 18:24:27 Misplaced paranoia. I've removed it. On 2014/01/23
29 DCHECK(profiles::IsMultipleProfilesEnabled());
30
28 CocoaProfileTest::SetUp(); 31 CocoaProfileTest::SetUp();
29 ASSERT_TRUE(browser()); 32 ASSERT_TRUE(browser());
30 33
31 controller_.reset( 34 controller_.reset(
32 [[AvatarButtonController alloc] initWithBrowser:browser()]); 35 [[AvatarButtonController alloc] initWithBrowser:browser()]);
33 [[controller_ view] setHidden:YES];
34 } 36 }
35 37
36 virtual void TearDown() OVERRIDE { 38 virtual void TearDown() OVERRIDE {
37 browser()->window()->Close(); 39 browser()->window()->Close();
38 CocoaProfileTest::TearDown(); 40 CocoaProfileTest::TearDown();
39 } 41 }
40 42
41 NSButton* button() { return [controller_ buttonView]; } 43 NSButton* button() { return [controller_ buttonView]; }
42 44
43 NSView* view() { return [controller_ view]; } 45 NSView* view() { return [controller_ view]; }
44 46
45 AvatarButtonController* controller() { return controller_.get(); } 47 AvatarButtonController* controller() { return controller_.get(); }
46 48
47 private: 49 private:
48 base::scoped_nsobject<AvatarButtonController> controller_; 50 base::scoped_nsobject<AvatarButtonController> controller_;
49 }; 51 };
50 52
51 TEST_F(AvatarButtonControllerTest, AddRemoveProfiles) { 53 TEST_F(AvatarButtonControllerTest, ButtonShown) {
52 EXPECT_TRUE([view() isHidden]);
53
54 testing_profile_manager()->CreateTestingProfile("one");
55
56 EXPECT_FALSE([view() isHidden]); 54 EXPECT_FALSE([view() isHidden]);
57 55 EXPECT_EQ(kDefaultProfileName, base::SysNSStringToUTF8([button() title]));
58 testing_profile_manager()->CreateTestingProfile("two");
59 EXPECT_FALSE([view() isHidden]);
60
61 testing_profile_manager()->DeleteTestingProfile("one");
62 EXPECT_FALSE([view() isHidden]);
63
64 testing_profile_manager()->DeleteTestingProfile("two");
65 EXPECT_TRUE([view() isHidden]);
66 } 56 }
67 57
68 TEST_F(AvatarButtonControllerTest, DoubleOpen) { 58 TEST_F(AvatarButtonControllerTest, DoubleOpen) {
69 // Create a second profile to enable the avatar menu.
70 testing_profile_manager()->CreateTestingProfile("p2");
71
72 EXPECT_FALSE([controller() menuController]); 59 EXPECT_FALSE([controller() menuController]);
73 60
74 [button() performClick:button()]; 61 [button() performClick:button()];
75 62
76 BaseBubbleController* menu = [controller() menuController]; 63 BaseBubbleController* menu = [controller() menuController];
77 EXPECT_TRUE(menu); 64 EXPECT_TRUE(menu);
65 EXPECT_TRUE([menu isKindOfClass:[ProfileChooserController class]]);
78 66
79 [button() performClick:button()]; 67 [button() performClick:button()];
80 EXPECT_EQ(menu, [controller() menuController]); 68 EXPECT_EQ(menu, [controller() menuController]);
81 69
82 // Do not animate out because that is hard to test around. 70 // Do not animate out because that is hard to test around.
83 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations = 71 static_cast<InfoBubbleWindow*>(menu.window).allowedAnimations =
84 info_bubble::kAnimateNone; 72 info_bubble::kAnimateNone;
85 [menu close]; 73 [menu close];
86 EXPECT_FALSE([controller() menuController]); 74 EXPECT_FALSE([controller() menuController]);
87
88 testing_profile_manager()->DeleteTestingProfile("p2");
89 } 75 }
90
91 TEST_F(AvatarButtonControllerTest, ManagedUserLabel) {
92 DCHECK(!profile()->IsManaged());
93 EXPECT_FALSE([controller() labelButtonView]);
94
95 // Create a second, managed profile to enable the avatar menu.
96 std::string name = "p2";
97 TestingProfile* profile = testing_profile_manager()->CreateTestingProfile(
98 name, scoped_ptr<PrefServiceSyncable>(), base::ASCIIToUTF16(name), 0,
99 "asdf", TestingProfile::TestingFactories());
100 EXPECT_TRUE(profile->IsManaged());
101
102 // http://crbug.com/39725
103 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
104 profile, &TemplateURLServiceFactory::BuildInstanceFor);
105 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
106 profile, &AutocompleteClassifierFactory::BuildInstanceFor);
107 profile->CreateBookmarkModel(true);
108 test::WaitForBookmarkModelToLoad(profile);
109
110 Browser* browser =
111 new Browser(Browser::CreateParams(profile, chrome::GetActiveDesktop()));
112 // Build a new controller to check if it is initialized correctly for a
113 // managed user profile.
114 base::scoped_nsobject<AvatarButtonController> controller(
115 [[AvatarButtonController alloc] initWithBrowser:browser]);
116
117 EXPECT_TRUE([controller labelButtonView]);
118
119 browser->window()->Close();
120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698