| OLD | NEW |
| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "base/mac/scoped_block.h" |
| 7 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/download/download_shelf.h" | 10 #include "chrome/browser/download/download_shelf.h" |
| 10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 11 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" | 12 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 13 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
| 13 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" | 14 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" |
| 14 #include "content/public/test/mock_download_item.h" | 15 #include "content/public/test/mock_download_item.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 54 } |
| 54 - (WrappedMockDownloadItem*)wrappedMockDownload; | 55 - (WrappedMockDownloadItem*)wrappedMockDownload; |
| 55 @end | 56 @end |
| 56 | 57 |
| 57 @implementation DownloadItemController (DownloadShelfControllerTest) | 58 @implementation DownloadItemController (DownloadShelfControllerTest) |
| 58 - (WrappedMockDownloadItem*)wrappedMockDownload { | 59 - (WrappedMockDownloadItem*)wrappedMockDownload { |
| 59 return nil; | 60 return nil; |
| 60 } | 61 } |
| 61 @end | 62 @end |
| 62 | 63 |
| 64 @interface DownloadShelfController (Testing) |
| 65 - (void)animationDidEnd:(NSAnimation*)animation; |
| 66 @end |
| 67 |
| 63 // Subclass of the DownloadShelfController to override scheduleAutoClose and | 68 // Subclass of the DownloadShelfController to override scheduleAutoClose and |
| 64 // cancelAutoClose. During regular operation, a scheduled autoClose waits for 5 | 69 // cancelAutoClose. During regular operation, a scheduled autoClose waits for 5 |
| 65 // seconds before closing the shelf (unless it is cancelled during this | 70 // seconds before closing the shelf (unless it is cancelled during this |
| 66 // time). For testing purposes, we count the number of invocations of | 71 // time). For testing purposes, we count the number of invocations of |
| 67 // {schedule,cancel}AutoClose instead of actually scheduling and cancelling. | 72 // {schedule,cancel}AutoClose instead of actually scheduling and cancelling. |
| 68 @interface CountingDownloadShelfController : DownloadShelfController { | 73 @interface CountingDownloadShelfController : DownloadShelfController { |
| 69 @public | 74 @public |
| 70 int scheduleAutoCloseCount_; | 75 int scheduleAutoCloseCount_; |
| 71 int cancelAutoCloseCount_; | 76 int cancelAutoCloseCount_; |
| 77 base::mac::ScopedBlock<dispatch_block_t> closeAnimationHandler_; |
| 72 } | 78 } |
| 79 |
| 80 // Handler will be called at the end of a close animation. |
| 81 - (void)setCloseAnimationHandler:(dispatch_block_t)handler; |
| 73 @end | 82 @end |
| 74 | 83 |
| 75 @implementation CountingDownloadShelfController | 84 @implementation CountingDownloadShelfController |
| 76 | 85 |
| 77 -(void)scheduleAutoClose { | 86 -(void)scheduleAutoClose { |
| 78 ++scheduleAutoCloseCount_; | 87 ++scheduleAutoCloseCount_; |
| 79 } | 88 } |
| 80 | 89 |
| 81 -(void)cancelAutoClose { | 90 -(void)cancelAutoClose { |
| 82 ++cancelAutoCloseCount_; | 91 ++cancelAutoCloseCount_; |
| 83 } | 92 } |
| 93 |
| 94 - (void)setCloseAnimationHandler:(dispatch_block_t)handler { |
| 95 closeAnimationHandler_.reset(handler); |
| 96 } |
| 97 |
| 98 - (void)animationDidEnd:(NSAnimation*)animation { |
| 99 [super animationDidEnd:animation]; |
| 100 if (closeAnimationHandler_) |
| 101 closeAnimationHandler_.get()(); |
| 102 } |
| 103 |
| 84 @end | 104 @end |
| 85 | 105 |
| 86 namespace { | 106 namespace { |
| 87 | 107 |
| 88 class DownloadShelfControllerTest : public CocoaProfileTest { | 108 class DownloadShelfControllerTest : public CocoaProfileTest { |
| 89 public: | 109 public: |
| 90 virtual void SetUp() OVERRIDE { | 110 virtual void SetUp() OVERRIDE { |
| 91 CocoaProfileTest::SetUp(); | 111 CocoaProfileTest::SetUp(); |
| 92 ASSERT_TRUE(browser()); | 112 ASSERT_TRUE(browser()); |
| 93 | 113 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 [shelf_ add:item.get()]; | 373 [shelf_ add:item.get()]; |
| 354 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); | 374 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); |
| 355 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); | 375 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); |
| 356 | 376 |
| 357 [shelf_ exiting]; | 377 [shelf_ exiting]; |
| 358 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); | 378 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); |
| 359 EXPECT_EQ(3, shelf_.get()->cancelAutoCloseCount_); | 379 EXPECT_EQ(3, shelf_.get()->cancelAutoCloseCount_); |
| 360 shelf_.reset(); | 380 shelf_.reset(); |
| 361 } | 381 } |
| 362 | 382 |
| 383 // The view should not be hidden when the shelf is shown. |
| 384 // The view should be hidden after the closing animation. |
| 385 TEST_F(DownloadShelfControllerTest, ViewVisibility) { |
| 386 [shelf_ showDownloadShelf:YES isUserAction:NO]; |
| 387 EXPECT_FALSE([[shelf_ view] isHidden]); |
| 388 |
| 389 [shelf_ setCloseAnimationHandler:^{ |
| 390 base::MessageLoop::current()->QuitNow(); |
| 391 }]; |
| 392 [shelf_ showDownloadShelf:NO isUserAction:NO]; |
| 393 base::MessageLoop::current()->Run(); |
| 394 EXPECT_TRUE([[shelf_ view] isHidden]); |
| 395 |
| 396 [shelf_ showDownloadShelf:YES isUserAction:NO]; |
| 397 EXPECT_FALSE([[shelf_ view] isHidden]); |
| 398 } |
| 399 |
| 363 } // namespace | 400 } // namespace |
| OLD | NEW |