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

Side by Side Diff: chrome/browser/notifications/login_state_notification_blocker_chromeos_browsertest.cc

Issue 270563002: Componentize LoginManagerTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move parameter from ctor to fn Created 6 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "ash/shell.h" 5 #include "ash/shell.h"
6 #include "ash/system/system_notifier.h" 6 #include "ash/system/system_notifier.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/chromeos/login/login_manager_test.h" 8 #include "chrome/browser/chromeos/login/login_manager_test_helper.h"
9 #include "chrome/browser/chromeos/login/startup_utils.h" 9 #include "chrome/browser/chromeos/login/startup_utils.h"
10 #include "chrome/browser/chromeos/login/user_adding_screen.h" 10 #include "chrome/browser/chromeos/login/user_adding_screen.h"
11 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h" 11 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/in_process_browser_test.h"
13 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
14 #include "ui/message_center/message_center.h" 15 #include "ui/message_center/message_center.h"
15 16
16 using namespace testing; 17 using namespace testing;
17 18
18 namespace { 19 namespace {
19 20
20 const char* kTestUsers[] = {"test-user@gmail.com", 21 const char* kTestUsers[] = {"test-user@gmail.com",
21 "test-user1@gmail.com"}; 22 "test-user1@gmail.com"};
22 23
23 } // anonymous namespace 24 } // anonymous namespace
24 25
25 class LoginStateNotificationBlockerChromeOSBrowserTest 26 class LoginStateNotificationBlockerChromeOSBrowserTest
26 : public chromeos::LoginManagerTest, 27 : public InProcessBrowserTest,
27 public message_center::NotificationBlocker::Observer { 28 public message_center::NotificationBlocker::Observer {
28 public: 29 public:
29 LoginStateNotificationBlockerChromeOSBrowserTest() 30 LoginStateNotificationBlockerChromeOSBrowserTest()
30 : chromeos::LoginManagerTest(false), 31 : login_manager_test_helper_(new chromeos::LoginManagerTestHelper),
31 state_changed_count_(0) {} 32 state_changed_count_(0) {
33 set_exit_when_last_browser_closes(false);
34 }
35
32 virtual ~LoginStateNotificationBlockerChromeOSBrowserTest() {} 36 virtual ~LoginStateNotificationBlockerChromeOSBrowserTest() {}
33 37
34 // InProcessBrowserTest overrides: 38 // InProcessBrowserTest overrides:
35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 39 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
36 LoginManagerTest::SetUpCommandLine(command_line); 40 login_manager_test_helper_->SetUpCommandLine(command_line);
37 command_line->AppendSwitch(::switches::kMultiProfiles); 41 command_line->AppendSwitch(::switches::kMultiProfiles);
38 } 42 }
39 43
40 virtual void SetUpOnMainThread() OVERRIDE { 44 virtual void SetUpOnMainThread() OVERRIDE {
41 chromeos::LoginState::Get()->set_always_logged_in(false); 45 chromeos::LoginState::Get()->set_always_logged_in(false);
46 login_manager_test_helper_->SetUp();
47 }
48
49 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
50 login_manager_test_helper_->SetUpLoginUtils(false);
42 } 51 }
43 52
44 virtual void CleanUpOnMainThread() OVERRIDE { 53 virtual void CleanUpOnMainThread() OVERRIDE {
45 if (blocker_) 54 if (blocker_)
46 blocker_->RemoveObserver(this); 55 blocker_->RemoveObserver(this);
47 blocker_.reset(); 56 blocker_.reset();
48 chromeos::LoginManagerTest::CleanUpOnMainThread(); 57 login_manager_test_helper_->CleanUp();
49 } 58 }
50 59
51 protected: 60 protected:
52 void CreateBlocker() { 61 void CreateBlocker() {
53 blocker_.reset(new LoginStateNotificationBlockerChromeOS( 62 blocker_.reset(new LoginStateNotificationBlockerChromeOS(
54 message_center::MessageCenter::Get())); 63 message_center::MessageCenter::Get()));
55 blocker_->AddObserver(this); 64 blocker_->AddObserver(this);
56 } 65 }
57 66
58 // message_center::NotificationBlocker::Observer ovverrides: 67 // message_center::NotificationBlocker::Observer ovverrides:
59 virtual void OnBlockingStateChanged( 68 virtual void OnBlockingStateChanged(
60 message_center::NotificationBlocker* blocker) OVERRIDE { 69 message_center::NotificationBlocker* blocker) OVERRIDE {
61 state_changed_count_++; 70 state_changed_count_++;
62 } 71 }
63 72
64 int GetStateChangedCountAndReset() { 73 int GetStateChangedCountAndReset() {
65 int result = state_changed_count_; 74 int result = state_changed_count_;
66 state_changed_count_ = 0; 75 state_changed_count_ = 0;
67 return result; 76 return result;
68 } 77 }
69 78
70 bool ShouldShowNotificationAsPopup( 79 bool ShouldShowNotificationAsPopup(
71 const message_center::NotifierId& notifier_id) { 80 const message_center::NotifierId& notifier_id) {
72 return blocker_->ShouldShowNotificationAsPopup(notifier_id); 81 return blocker_->ShouldShowNotificationAsPopup(notifier_id);
73 } 82 }
74 83
84 protected:
85 scoped_ptr<chromeos::LoginManagerTestHelper> login_manager_test_helper_;
86
75 private: 87 private:
76 int state_changed_count_; 88 int state_changed_count_;
77 scoped_ptr<message_center::NotificationBlocker> blocker_; 89 scoped_ptr<message_center::NotificationBlocker> blocker_;
78 90
79 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSBrowserTest); 91 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSBrowserTest);
80 }; 92 };
81 93
82 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, 94 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
83 PRE_BaseTest) { 95 PRE_BaseTest) {
84 RegisterUser(kTestUsers[0]); 96 login_manager_test_helper_->RegisterUser(kTestUsers[0]);
85 RegisterUser(kTestUsers[1]); 97 login_manager_test_helper_->RegisterUser(kTestUsers[1]);
86 chromeos::StartupUtils::MarkOobeCompleted(); 98 chromeos::StartupUtils::MarkOobeCompleted();
87 } 99 }
88 100
89 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, 101 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
90 BaseTest) { 102 BaseTest) {
91 CreateBlocker(); 103 CreateBlocker();
92 message_center::NotifierId notifier_id( 104 message_center::NotifierId notifier_id(
93 message_center::NotifierId::APPLICATION, "test-notifier"); 105 message_center::NotifierId::APPLICATION, "test-notifier");
94 106
95 // Logged in as a normal user. 107 // Logged in as a normal user.
96 EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1); 108 EXPECT_CALL(login_manager_test_helper_->login_utils(),
97 LoginUser(kTestUsers[0]); 109 DoBrowserLaunch(_, _)).Times(1);
110 login_manager_test_helper_->LogInUser(kTestUsers[0]);
98 EXPECT_EQ(1, GetStateChangedCountAndReset()); 111 EXPECT_EQ(1, GetStateChangedCountAndReset());
99 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 112 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
100 113
101 // Multi-login user switch. 114 // Multi-login user switch.
102 chromeos::UserAddingScreen::Get()->Start(); 115 chromeos::UserAddingScreen::Get()->Start();
103 content::RunAllPendingInMessageLoop(); 116 content::RunAllPendingInMessageLoop();
104 EXPECT_EQ(1, GetStateChangedCountAndReset()); 117 EXPECT_EQ(1, GetStateChangedCountAndReset());
105 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id)); 118 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id));
106 119
107 // Multi-login user switch off. 120 // Multi-login user switch off.
108 chromeos::UserAddingScreen::Get()->Cancel(); 121 chromeos::UserAddingScreen::Get()->Cancel();
109 content::RunAllPendingInMessageLoop(); 122 content::RunAllPendingInMessageLoop();
110 EXPECT_EQ(1, GetStateChangedCountAndReset()); 123 EXPECT_EQ(1, GetStateChangedCountAndReset());
111 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 124 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
112 } 125 }
113 126
114 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, 127 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
115 PRE_AlwaysAllowedNotifier) { 128 PRE_AlwaysAllowedNotifier) {
116 RegisterUser(kTestUsers[0]); 129 login_manager_test_helper_->RegisterUser(kTestUsers[0]);
117 RegisterUser(kTestUsers[1]); 130 login_manager_test_helper_->RegisterUser(kTestUsers[1]);
118 chromeos::StartupUtils::MarkOobeCompleted(); 131 chromeos::StartupUtils::MarkOobeCompleted();
119 } 132 }
120 133
121 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, 134 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
122 AlwaysAllowedNotifier) { 135 AlwaysAllowedNotifier) {
123 CreateBlocker(); 136 CreateBlocker();
124 137
125 // NOTIFIER_DISPLAY is allowed to shown in the login screen. 138 // NOTIFIER_DISPLAY is allowed to shown in the login screen.
126 message_center::NotifierId notifier_id( 139 message_center::NotifierId notifier_id(
127 message_center::NotifierId::SYSTEM_COMPONENT, 140 message_center::NotifierId::SYSTEM_COMPONENT,
128 ash::system_notifier::kNotifierDisplay); 141 ash::system_notifier::kNotifierDisplay);
129 142
130 // Logged in as a normal user. 143 // Logged in as a normal user.
131 EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1); 144 EXPECT_CALL(login_manager_test_helper_->login_utils(),
132 LoginUser(kTestUsers[0]); 145 DoBrowserLaunch(_, _)).Times(1);
146 login_manager_test_helper_->LogInUser(kTestUsers[0]);
133 EXPECT_EQ(1, GetStateChangedCountAndReset()); 147 EXPECT_EQ(1, GetStateChangedCountAndReset());
134 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 148 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
135 149
136 // Multi-login user switch. 150 // Multi-login user switch.
137 chromeos::UserAddingScreen::Get()->Start(); 151 chromeos::UserAddingScreen::Get()->Start();
138 content::RunAllPendingInMessageLoop(); 152 content::RunAllPendingInMessageLoop();
139 EXPECT_EQ(1, GetStateChangedCountAndReset()); 153 EXPECT_EQ(1, GetStateChangedCountAndReset());
140 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 154 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
141 155
142 // Multi-login user switch off. 156 // Multi-login user switch off.
143 chromeos::UserAddingScreen::Get()->Cancel(); 157 chromeos::UserAddingScreen::Get()->Cancel();
144 content::RunAllPendingInMessageLoop(); 158 content::RunAllPendingInMessageLoop();
145 EXPECT_EQ(1, GetStateChangedCountAndReset()); 159 EXPECT_EQ(1, GetStateChangedCountAndReset());
146 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 160 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
147 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698