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

Side by Side Diff: chrome/browser/managed_mode/managed_mode_unittest.cc

Issue 16296002: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 (c) 2012 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 "chrome/browser/managed_mode/managed_mode.h" 5 #include "chrome/browser/managed_mode/managed_mode.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 ui_thread_(content::BrowserThread::UI, &message_loop_), 122 ui_thread_(content::BrowserThread::UI, &message_loop_),
123 io_thread_(content::BrowserThread::IO, &message_loop_) { 123 io_thread_(content::BrowserThread::IO, &message_loop_) {
124 } 124 }
125 125
126 scoped_refptr<MockCallback> CreateCallback() { 126 scoped_refptr<MockCallback> CreateCallback() {
127 return new StrictMock<MockCallback>(&managed_mode_); 127 return new StrictMock<MockCallback>(&managed_mode_);
128 } 128 }
129 129
130 base::Callback<void(bool)> CreateExpectedCallback(bool success) { 130 base::Callback<void(bool)> CreateExpectedCallback(bool success) {
131 scoped_refptr<MockCallback> callback = CreateCallback(); 131 scoped_refptr<MockCallback> callback = CreateCallback();
132 EXPECT_CALL(*callback, DidEnterManagedMode(success)); 132 EXPECT_CALL(*callback.get(), DidEnterManagedMode(success));
133 return base::Bind(&MockCallback::CheckManagedMode, callback); 133 return base::Bind(&MockCallback::CheckManagedMode, callback);
134 } 134 }
135 135
136 protected: 136 protected:
137 base::MessageLoop message_loop_; 137 base::MessageLoop message_loop_;
138 content::TestBrowserThread ui_thread_; 138 content::TestBrowserThread ui_thread_;
139 content::TestBrowserThread io_thread_; 139 content::TestBrowserThread io_thread_;
140 TestingProfile managed_mode_profile_; 140 TestingProfile managed_mode_profile_;
141 TestingProfile other_profile_; 141 TestingProfile other_profile_;
142 FakeManagedMode managed_mode_; 142 FakeManagedMode managed_mode_;
(...skipping 28 matching lines...) Expand all
171 BrowserFixture other_browser(&managed_mode_, &other_profile_); 171 BrowserFixture other_browser(&managed_mode_, &other_profile_);
172 172
173 EXPECT_CALL(*other_browser.window(), Close()); 173 EXPECT_CALL(*other_browser.window(), Close());
174 managed_mode_.EnterManagedModeForTesting( 174 managed_mode_.EnterManagedModeForTesting(
175 &managed_mode_profile_, 175 &managed_mode_profile_,
176 base::Bind(&MockCallback::CheckManagedMode, callback)); 176 base::Bind(&MockCallback::CheckManagedMode, callback));
177 managed_mode_.EnterManagedModeForTesting( 177 managed_mode_.EnterManagedModeForTesting(
178 &managed_mode_profile_, 178 &managed_mode_profile_,
179 base::Bind(&MockCallback::CheckManagedMode, callback)); 179 base::Bind(&MockCallback::CheckManagedMode, callback));
180 // The callbacks should run as soon as |other_browser| is closed. 180 // The callbacks should run as soon as |other_browser| is closed.
181 EXPECT_CALL(*callback, DidEnterManagedMode(true)).Times(2); 181 EXPECT_CALL(*callback.get(), DidEnterManagedMode(true)).Times(2);
182 } 182 }
183 183
184 TEST_F(ManagedModeTest, OpenNewBrowser) { 184 TEST_F(ManagedModeTest, OpenNewBrowser) {
185 BrowserFixture managed_mode_browser(&managed_mode_, &managed_mode_profile_); 185 BrowserFixture managed_mode_browser(&managed_mode_, &managed_mode_profile_);
186 BrowserFixture other_browser(&managed_mode_, &other_profile_); 186 BrowserFixture other_browser(&managed_mode_, &other_profile_);
187 187
188 scoped_refptr<MockCallback> callback = CreateCallback(); 188 scoped_refptr<MockCallback> callback = CreateCallback();
189 EXPECT_CALL(*other_browser.window(), Close()); 189 EXPECT_CALL(*other_browser.window(), Close());
190 managed_mode_.EnterManagedModeForTesting( 190 managed_mode_.EnterManagedModeForTesting(
191 &managed_mode_profile_, 191 &managed_mode_profile_,
192 base::Bind(&MockCallback::CheckManagedMode, callback)); 192 base::Bind(&MockCallback::CheckManagedMode, callback));
193 193
194 // Opening another browser with the managed profile should not cancel entering 194 // Opening another browser with the managed profile should not cancel entering
195 // managed mode. 195 // managed mode.
196 BrowserFixture other_managed_mode_browser(&managed_mode_, 196 BrowserFixture other_managed_mode_browser(&managed_mode_,
197 &managed_mode_profile_); 197 &managed_mode_profile_);
198 198
199 // Opening another browser should cancel entering managed mode. 199 // Opening another browser should cancel entering managed mode.
200 EXPECT_CALL(*callback, DidEnterManagedMode(false)); 200 EXPECT_CALL(*callback.get(), DidEnterManagedMode(false));
201 BrowserFixture yet_another_browser(&managed_mode_, &other_profile_); 201 BrowserFixture yet_another_browser(&managed_mode_, &other_profile_);
202 } 202 }
203 203
204 TEST_F(ManagedModeTest, DifferentProfile) { 204 TEST_F(ManagedModeTest, DifferentProfile) {
205 BrowserFixture managed_mode_browser(&managed_mode_, &managed_mode_profile_); 205 BrowserFixture managed_mode_browser(&managed_mode_, &managed_mode_profile_);
206 206
207 // Keep this before the other browser is constructed, so we verify its 207 // Keep this before the other browser is constructed, so we verify its
208 // expectations after the browser is destroyed. 208 // expectations after the browser is destroyed.
209 scoped_refptr<MockCallback> callback = CreateCallback(); 209 scoped_refptr<MockCallback> callback = CreateCallback();
210 BrowserFixture other_browser(&managed_mode_, &other_profile_); 210 BrowserFixture other_browser(&managed_mode_, &other_profile_);
211 211
212 EXPECT_CALL(*other_browser.window(), Close()); 212 EXPECT_CALL(*other_browser.window(), Close());
213 managed_mode_.EnterManagedModeForTesting( 213 managed_mode_.EnterManagedModeForTesting(
214 &managed_mode_profile_, 214 &managed_mode_profile_,
215 base::Bind(&MockCallback::CheckManagedMode, callback)); 215 base::Bind(&MockCallback::CheckManagedMode, callback));
216 216
217 // Trying to enter managed mode with a different profile should fail 217 // Trying to enter managed mode with a different profile should fail
218 // immediately. 218 // immediately.
219 managed_mode_.EnterManagedModeForTesting(&other_profile_, 219 managed_mode_.EnterManagedModeForTesting(&other_profile_,
220 CreateExpectedCallback(false)); 220 CreateExpectedCallback(false));
221 221
222 // The first request should still succeed as soon as the other browser is 222 // The first request should still succeed as soon as the other browser is
223 // closed. 223 // closed.
224 EXPECT_CALL(*callback, DidEnterManagedMode(true)); 224 EXPECT_CALL(*callback.get(), DidEnterManagedMode(true));
225 } 225 }
226 226
227 TEST_F(ManagedModeTest, Cancelled) { 227 TEST_F(ManagedModeTest, Cancelled) {
228 BrowserFixture managed_mode_browser(&managed_mode_, &managed_mode_profile_); 228 BrowserFixture managed_mode_browser(&managed_mode_, &managed_mode_profile_);
229 BrowserFixture other_browser(&managed_mode_, &other_profile_); 229 BrowserFixture other_browser(&managed_mode_, &other_profile_);
230 230
231 // If the user cancelled entering managed mode, it should fail immediately. 231 // If the user cancelled entering managed mode, it should fail immediately.
232 managed_mode_.set_should_cancel_enter(true); 232 managed_mode_.set_should_cancel_enter(true);
233 managed_mode_.EnterManagedModeForTesting(&managed_mode_profile_, 233 managed_mode_.EnterManagedModeForTesting(&managed_mode_profile_,
234 CreateExpectedCallback(false)); 234 CreateExpectedCallback(false));
235 } 235 }
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | chrome/browser/managed_mode/managed_user_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698