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

Side by Side Diff: chrome/browser/ui/cocoa/download/download_shelf_controller_unittest.mm

Issue 2688413012: Don't animate the download shelf when entering/exiting fullscreen. (Closed)
Patch Set: Rename Show to Open more consistently. Created 3 years, 10 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
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 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" 5 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 andReturn:wrappedMockDownload.get()] wrappedMockDownload]; 164 andReturn:wrappedMockDownload.get()] wrappedMockDownload];
165 return [item_controller retain]; 165 return [item_controller retain];
166 } 166 }
167 167
168 TEST_VIEW(DownloadShelfControllerTest, [shelf_ view]); 168 TEST_VIEW(DownloadShelfControllerTest, [shelf_ view]);
169 169
170 // Removing the last download from the shelf should cause it to close 170 // Removing the last download from the shelf should cause it to close
171 // immediately. 171 // immediately.
172 TEST_F(DownloadShelfControllerTest, AddAndRemoveDownload) { 172 TEST_F(DownloadShelfControllerTest, AddAndRemoveDownload) {
173 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); 173 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
174 [shelf_ showDownloadShelf:YES 174 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
175 isUserAction:NO];
176 EXPECT_TRUE([shelf_ isVisible]); 175 EXPECT_TRUE([shelf_ isVisible]);
177 EXPECT_TRUE([shelf_ bridge]->IsShowing()); 176 EXPECT_TRUE([shelf_ bridge]->IsShowing());
178 [shelf_ add:item]; 177 [shelf_ add:item];
179 [shelf_ remove:item]; 178 [shelf_ remove:item];
180 EXPECT_FALSE([shelf_ isVisible]); 179 EXPECT_FALSE([shelf_ isVisible]);
181 EXPECT_FALSE([shelf_ bridge]->IsShowing()); 180 EXPECT_FALSE([shelf_ bridge]->IsShowing());
182 // The shelf should be closed without scheduling an autoClose. 181 // The shelf should be closed without scheduling an autoClose.
183 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); 182 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_);
184 } 183 }
185 184
186 // Test that the shelf doesn't close automatically after a removal if there are 185 // Test that the shelf doesn't close automatically after a removal if there are
187 // active download items still on the shelf. 186 // active download items still on the shelf.
188 TEST_F(DownloadShelfControllerTest, AddAndRemoveWithActiveItem) { 187 TEST_F(DownloadShelfControllerTest, AddAndRemoveWithActiveItem) {
189 base::scoped_nsobject<DownloadItemController> item1(CreateItemController()); 188 base::scoped_nsobject<DownloadItemController> item1(CreateItemController());
190 base::scoped_nsobject<DownloadItemController> item2(CreateItemController()); 189 base::scoped_nsobject<DownloadItemController> item2(CreateItemController());
191 [shelf_ showDownloadShelf:YES 190 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
192 isUserAction:NO];
193 EXPECT_TRUE([shelf_ isVisible]); 191 EXPECT_TRUE([shelf_ isVisible]);
194 [shelf_ add:item1.get()]; 192 [shelf_ add:item1.get()];
195 [shelf_ add:item2.get()]; 193 [shelf_ add:item2.get()];
196 [shelf_ remove:item1.get()]; 194 [shelf_ remove:item1.get()];
197 EXPECT_TRUE([shelf_ isVisible]); 195 EXPECT_TRUE([shelf_ isVisible]);
198 [shelf_ remove:item2.get()]; 196 [shelf_ remove:item2.get()];
199 EXPECT_FALSE([shelf_ isVisible]); 197 EXPECT_FALSE([shelf_ isVisible]);
200 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); 198 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_);
201 } 199 }
202 200
203 // DownloadShelf::Unhide() should cause the shelf to be displayed if there are 201 // DownloadShelf::Unhide() should cause the shelf to be displayed if there are
204 // active downloads on it. 202 // active downloads on it.
205 TEST_F(DownloadShelfControllerTest, HideAndUnhide) { 203 TEST_F(DownloadShelfControllerTest, HideAndUnhide) {
206 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); 204 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
207 [shelf_ showDownloadShelf:YES 205 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
208 isUserAction:NO];
209 EXPECT_TRUE([shelf_ isVisible]); 206 EXPECT_TRUE([shelf_ isVisible]);
210 [shelf_ add:item.get()]; 207 [shelf_ add:item.get()];
211 [shelf_ bridge]->Hide(); 208 [shelf_ bridge]->Hide();
212 EXPECT_FALSE([shelf_ isVisible]); 209 EXPECT_FALSE([shelf_ isVisible]);
213 [shelf_ bridge]->Unhide(); 210 [shelf_ bridge]->Unhide();
214 EXPECT_TRUE([shelf_ isVisible]); 211 EXPECT_TRUE([shelf_ isVisible]);
215 [shelf_ remove:item.get()]; 212 [shelf_ remove:item.get()];
216 EXPECT_FALSE([shelf_ isVisible]); 213 EXPECT_FALSE([shelf_ isVisible]);
217 } 214 }
218 215
219 // DownloadShelf::Unhide() shouldn't cause the shelf to be displayed if all 216 // DownloadShelf::Unhide() shouldn't cause the shelf to be displayed if all
220 // active downloads are removed from the shelf while the shelf was hidden. 217 // active downloads are removed from the shelf while the shelf was hidden.
221 TEST_F(DownloadShelfControllerTest, HideAutocloseUnhide) { 218 TEST_F(DownloadShelfControllerTest, HideAutocloseUnhide) {
222 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); 219 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
223 [shelf_ showDownloadShelf:YES 220 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
224 isUserAction:NO];
225 EXPECT_TRUE([shelf_ isVisible]); 221 EXPECT_TRUE([shelf_ isVisible]);
226 [shelf_ add:item.get()]; 222 [shelf_ add:item.get()];
227 [shelf_ bridge]->Hide(); 223 [shelf_ bridge]->Hide();
228 EXPECT_FALSE([shelf_ isVisible]); 224 EXPECT_FALSE([shelf_ isVisible]);
229 [shelf_ remove:item.get()]; 225 [shelf_ remove:item.get()];
230 EXPECT_FALSE([shelf_ isVisible]); 226 EXPECT_FALSE([shelf_ isVisible]);
231 [shelf_ bridge]->Unhide(); 227 [shelf_ bridge]->Unhide();
232 EXPECT_FALSE([shelf_ isVisible]); 228 EXPECT_FALSE([shelf_ isVisible]);
233 } 229 }
234 230
235 // Test of autoclosing behavior after opening a download item. The mouse is on 231 // Test of autoclosing behavior after opening a download item. The mouse is on
236 // the download shelf at the time the autoclose is scheduled. 232 // the download shelf at the time the autoclose is scheduled.
237 TEST_F(DownloadShelfControllerTest, AutoCloseAfterOpenWithMouseInShelf) { 233 TEST_F(DownloadShelfControllerTest, AutoCloseAfterOpenWithMouseInShelf) {
238 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); 234 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
239 [shelf_ showDownloadShelf:YES 235 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
240 isUserAction:NO];
241 EXPECT_TRUE([shelf_ isVisible]); 236 EXPECT_TRUE([shelf_ isVisible]);
242 [shelf_ add:item.get()]; 237 [shelf_ add:item.get()];
243 // Expect 2 cancelAutoClose calls: From the showDownloadShelf: call and the 238 // Expect 2 cancelAutoClose calls: From the showDownloadShelf: call and the
244 // add: call. 239 // add: call.
245 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); 240 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_);
246 shelf_.get()->cancelAutoCloseCount_ = 0; 241 shelf_.get()->cancelAutoCloseCount_ = 0;
247 242
248 // The mouse enters the shelf. 243 // The mouse enters the shelf.
249 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; 244 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
250 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); 245 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_);
(...skipping 15 matching lines...) Expand all
266 261
267 // The mouse enters the shelf again. The autoClose should be cancelled. 262 // The mouse enters the shelf again. The autoClose should be cancelled.
268 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; 263 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
269 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); 264 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_);
270 EXPECT_EQ(1, shelf_.get()->cancelAutoCloseCount_); 265 EXPECT_EQ(1, shelf_.get()->cancelAutoCloseCount_);
271 } 266 }
272 267
273 // Test of autoclosing behavior after opening a download item. 268 // Test of autoclosing behavior after opening a download item.
274 TEST_F(DownloadShelfControllerTest, AutoCloseAfterOpenWithMouseOffShelf) { 269 TEST_F(DownloadShelfControllerTest, AutoCloseAfterOpenWithMouseOffShelf) {
275 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); 270 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
276 [shelf_ showDownloadShelf:YES 271 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
277 isUserAction:NO];
278 EXPECT_TRUE([shelf_ isVisible]); 272 EXPECT_TRUE([shelf_ isVisible]);
279 [shelf_ add:item.get()]; 273 [shelf_ add:item.get()];
280 274
281 // The download is opened. 275 // The download is opened.
282 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) 276 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened())
283 .WillRepeatedly(Return(true)); 277 .WillRepeatedly(Return(true));
284 [shelf_ downloadWasOpened:item.get()]; 278 [shelf_ downloadWasOpened:item.get()];
285 279
286 // The shelf should be closed immediately since the mouse is not over the 280 // The shelf should be closed immediately since the mouse is not over the
287 // shelf. 281 // shelf.
288 EXPECT_FALSE([shelf_ isVisible]); 282 EXPECT_FALSE([shelf_ isVisible]);
289 } 283 }
290 284
291 // Test that if the shelf is closed while an autoClose is pending, the pending 285 // Test that if the shelf is closed while an autoClose is pending, the pending
292 // autoClose is cancelled. 286 // autoClose is cancelled.
293 TEST_F(DownloadShelfControllerTest, CloseWithPendingAutoClose) { 287 TEST_F(DownloadShelfControllerTest, CloseWithPendingAutoClose) {
294 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); 288 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
295 [shelf_ showDownloadShelf:YES 289 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
296 isUserAction:NO];
297 EXPECT_TRUE([shelf_ isVisible]); 290 EXPECT_TRUE([shelf_ isVisible]);
298 [shelf_ add:item.get()]; 291 [shelf_ add:item.get()];
299 // Expect 2 cancelAutoClose calls: From the showDownloadShelf: call and the 292 // Expect 2 cancelAutoClose calls: From the showDownloadShelf: call and the
300 // add: call. 293 // add: call.
301 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); 294 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_);
302 shelf_.get()->cancelAutoCloseCount_ = 0; 295 shelf_.get()->cancelAutoCloseCount_ = 0;
303 296
304 // The mouse enters the shelf. 297 // The mouse enters the shelf.
305 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; 298 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
306 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); 299 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_);
(...skipping 19 matching lines...) Expand all
326 [shelf_ remove:item]; 319 [shelf_ remove:item];
327 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); 320 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_);
328 EXPECT_EQ(1, shelf_.get()->cancelAutoCloseCount_); 321 EXPECT_EQ(1, shelf_.get()->cancelAutoCloseCount_);
329 EXPECT_FALSE([shelf_ isVisible]); 322 EXPECT_FALSE([shelf_ isVisible]);
330 } 323 }
331 324
332 // That that the shelf cancels a pending autoClose if a new download item is 325 // That that the shelf cancels a pending autoClose if a new download item is
333 // added to it. 326 // added to it.
334 TEST_F(DownloadShelfControllerTest, AddItemWithPendingAutoClose) { 327 TEST_F(DownloadShelfControllerTest, AddItemWithPendingAutoClose) {
335 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); 328 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
336 [shelf_ showDownloadShelf:YES 329 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
337 isUserAction:NO];
338 EXPECT_TRUE([shelf_ isVisible]); 330 EXPECT_TRUE([shelf_ isVisible]);
339 [shelf_ add:item.get()]; 331 [shelf_ add:item.get()];
340 // Expect 2 cancelAutoClose calls: From the showDownloadShelf: call and the 332 // Expect 2 cancelAutoClose calls: From the showDownloadShelf: call and the
341 // add: call. 333 // add: call.
342 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); 334 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_);
343 shelf_.get()->cancelAutoCloseCount_ = 0; 335 shelf_.get()->cancelAutoCloseCount_ = 0;
344 336
345 // The mouse enters the shelf. 337 // The mouse enters the shelf.
346 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; 338 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
347 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); 339 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_);
(...skipping 18 matching lines...) Expand all
366 base::scoped_nsobject<DownloadItemController> item2(CreateItemController()); 358 base::scoped_nsobject<DownloadItemController> item2(CreateItemController());
367 [shelf_ add:item.get()]; 359 [shelf_ add:item.get()];
368 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); 360 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_);
369 EXPECT_EQ(1, shelf_.get()->cancelAutoCloseCount_); 361 EXPECT_EQ(1, shelf_.get()->cancelAutoCloseCount_);
370 EXPECT_TRUE([shelf_ isVisible]); 362 EXPECT_TRUE([shelf_ isVisible]);
371 } 363 }
372 364
373 // Test that pending autoClose calls are cancelled when exiting. 365 // Test that pending autoClose calls are cancelled when exiting.
374 TEST_F(DownloadShelfControllerTest, CancelAutoCloseOnExit) { 366 TEST_F(DownloadShelfControllerTest, CancelAutoCloseOnExit) {
375 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); 367 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
376 [shelf_ showDownloadShelf:YES 368 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
377 isUserAction:NO];
378 EXPECT_TRUE([shelf_ isVisible]); 369 EXPECT_TRUE([shelf_ isVisible]);
379 [shelf_ add:item.get()]; 370 [shelf_ add:item.get()];
380 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); 371 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_);
381 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); 372 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_);
382 373
383 [shelf_ browserWillBeDestroyed]; 374 [shelf_ browserWillBeDestroyed];
384 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); 375 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_);
385 EXPECT_EQ(3, shelf_.get()->cancelAutoCloseCount_); 376 EXPECT_EQ(3, shelf_.get()->cancelAutoCloseCount_);
386 shelf_.reset(); 377 shelf_.reset();
387 } 378 }
388 379
389 // The view should not be hidden when the shelf is shown. 380 // The view should not be hidden when the shelf is shown.
390 // The view should be hidden after the closing animation. 381 // The view should be hidden after the closing animation.
391 // Failing flakily on Mac 10.9, see: crbug.com/687447. 382 // Failing flakily on Mac 10.9, see: crbug.com/687447.
392 TEST_F(DownloadShelfControllerTest, DISABLED_ViewVisibility) { 383 TEST_F(DownloadShelfControllerTest, DISABLED_ViewVisibility) {
393 [shelf_ showDownloadShelf:YES isUserAction:NO]; 384 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
394 EXPECT_FALSE([[shelf_ view] isHidden]); 385 EXPECT_FALSE([[shelf_ view] isHidden]);
395 386
396 base::RunLoop run_loop; 387 base::RunLoop run_loop;
397 base::RunLoop* const run_loop_ptr = &run_loop; 388 base::RunLoop* const run_loop_ptr = &run_loop;
398 389
399 [shelf_ setCloseAnimationHandler:^{ 390 [shelf_ setCloseAnimationHandler:^{
400 run_loop_ptr->Quit(); 391 run_loop_ptr->Quit();
401 }]; 392 }];
402 [shelf_ showDownloadShelf:NO isUserAction:NO]; 393 [shelf_ showDownloadShelf:NO isUserAction:NO animate:NO];
403 run_loop.Run(); 394 run_loop.Run();
404 EXPECT_TRUE([[shelf_ view] isHidden]); 395 EXPECT_TRUE([[shelf_ view] isHidden]);
405 396
406 [shelf_ showDownloadShelf:YES isUserAction:NO]; 397 [shelf_ showDownloadShelf:YES isUserAction:NO animate:NO];
407 EXPECT_FALSE([[shelf_ view] isHidden]); 398 EXPECT_FALSE([[shelf_ view] isHidden]);
408 } 399 }
409 400
410 } // namespace 401 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698