| 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 "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> |
| 11 | 11 |
| 12 #import "base/mac/scoped_block.h" | 12 #import "base/mac/scoped_block.h" |
| 13 #import "base/mac/scoped_nsobject.h" | 13 #import "base/mac/scoped_nsobject.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "chrome/browser/download/download_item_model.h" |
| 15 #include "chrome/browser/download/download_shelf.h" | 16 #include "chrome/browser/download/download_shelf.h" |
| 16 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 17 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 17 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" | 18 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" |
| 18 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" | 19 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" |
| 19 #include "content/public/test/mock_download_item.h" | 20 #include "content/public/test/mock_download_item.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
| 22 #import "third_party/ocmock/OCMock/OCMock.h" | 23 #import "third_party/ocmock/OCMock/OCMock.h" |
| 23 #import "third_party/ocmock/gtest_support.h" | 24 #import "third_party/ocmock/gtest_support.h" |
| 24 #import "ui/events/test/cocoa_test_event_utils.h" | 25 #import "ui/events/test/cocoa_test_event_utils.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); | 246 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); |
| 246 shelf_.get()->cancelAutoCloseCount_ = 0; | 247 shelf_.get()->cancelAutoCloseCount_ = 0; |
| 247 | 248 |
| 248 // The mouse enters the shelf. | 249 // The mouse enters the shelf. |
| 249 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; | 250 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; |
| 250 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); | 251 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); |
| 251 | 252 |
| 252 // The download opens. | 253 // The download opens. |
| 253 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) | 254 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) |
| 254 .WillRepeatedly(Return(true)); | 255 .WillRepeatedly(Return(true)); |
| 255 [shelf_ downloadWasOpened:item.get()]; | 256 [shelf_ downloadWasOpenedOrShown:item.get()]; |
| 256 | 257 |
| 257 // The shelf should now be waiting for the mouse to exit. | 258 // The shelf should now be waiting for the mouse to exit. |
| 258 EXPECT_TRUE([shelf_ isVisible]); | 259 EXPECT_TRUE([shelf_ isVisible]); |
| 259 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); | 260 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); |
| 260 EXPECT_EQ(0, shelf_.get()->cancelAutoCloseCount_); | 261 EXPECT_EQ(0, shelf_.get()->cancelAutoCloseCount_); |
| 261 | 262 |
| 262 // The mouse exits the shelf. autoClose should be scheduled now. | 263 // The mouse exits the shelf. autoClose should be scheduled now. |
| 263 [shelf_ mouseExited:cocoa_test_event_utils::ExitEvent()]; | 264 [shelf_ mouseExited:cocoa_test_event_utils::ExitEvent()]; |
| 264 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); | 265 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); |
| 265 EXPECT_EQ(0, shelf_.get()->cancelAutoCloseCount_); | 266 EXPECT_EQ(0, shelf_.get()->cancelAutoCloseCount_); |
| 266 | 267 |
| 267 // The mouse enters the shelf again. The autoClose should be cancelled. | 268 // The mouse enters the shelf again. The autoClose should be cancelled. |
| 268 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; | 269 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; |
| 269 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); | 270 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); |
| 270 EXPECT_EQ(1, shelf_.get()->cancelAutoCloseCount_); | 271 EXPECT_EQ(1, shelf_.get()->cancelAutoCloseCount_); |
| 271 } | 272 } |
| 272 | 273 |
| 273 // Test of autoclosing behavior after opening a download item. | 274 // Test of autoclosing behavior after opening a download item. |
| 274 TEST_F(DownloadShelfControllerTest, AutoCloseAfterOpenWithMouseOffShelf) { | 275 TEST_F(DownloadShelfControllerTest, AutoCloseAfterOpenWithMouseOffShelf) { |
| 275 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); | 276 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); |
| 276 [shelf_ showDownloadShelf:YES | 277 [shelf_ showDownloadShelf:YES |
| 277 isUserAction:NO]; | 278 isUserAction:NO]; |
| 278 EXPECT_TRUE([shelf_ isVisible]); | 279 EXPECT_TRUE([shelf_ isVisible]); |
| 279 [shelf_ add:item.get()]; | 280 [shelf_ add:item.get()]; |
| 280 | 281 |
| 281 // The download is opened. | 282 // The download is opened. |
| 282 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) | 283 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) |
| 283 .WillRepeatedly(Return(true)); | 284 .WillRepeatedly(Return(true)); |
| 284 [shelf_ downloadWasOpened:item.get()]; | 285 [shelf_ downloadWasOpenedOrShown:item.get()]; |
| 285 | 286 |
| 286 // The shelf should be closed immediately since the mouse is not over the | 287 // The shelf should be closed immediately since the mouse is not over the |
| 287 // shelf. | 288 // shelf. |
| 288 EXPECT_FALSE([shelf_ isVisible]); | 289 EXPECT_FALSE([shelf_ isVisible]); |
| 289 } | 290 } |
| 290 | 291 |
| 291 // Test that if the shelf is closed while an autoClose is pending, the pending | 292 // Test that if the shelf is closed while an autoClose is pending, the pending |
| 292 // autoClose is cancelled. | 293 // autoClose is cancelled. |
| 293 TEST_F(DownloadShelfControllerTest, CloseWithPendingAutoClose) { | 294 TEST_F(DownloadShelfControllerTest, CloseWithPendingAutoClose) { |
| 294 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); | 295 base::scoped_nsobject<DownloadItemController> item(CreateItemController()); |
| 295 [shelf_ showDownloadShelf:YES | 296 [shelf_ showDownloadShelf:YES |
| 296 isUserAction:NO]; | 297 isUserAction:NO]; |
| 297 EXPECT_TRUE([shelf_ isVisible]); | 298 EXPECT_TRUE([shelf_ isVisible]); |
| 298 [shelf_ add:item.get()]; | 299 [shelf_ add:item.get()]; |
| 299 // Expect 2 cancelAutoClose calls: From the showDownloadShelf: call and the | 300 // Expect 2 cancelAutoClose calls: From the showDownloadShelf: call and the |
| 300 // add: call. | 301 // add: call. |
| 301 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); | 302 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); |
| 302 shelf_.get()->cancelAutoCloseCount_ = 0; | 303 shelf_.get()->cancelAutoCloseCount_ = 0; |
| 303 | 304 |
| 304 // The mouse enters the shelf. | 305 // The mouse enters the shelf. |
| 305 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; | 306 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; |
| 306 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); | 307 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); |
| 307 | 308 |
| 308 // The download opens. | 309 // The download opens. |
| 309 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) | 310 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) |
| 310 .WillRepeatedly(Return(true)); | 311 .WillRepeatedly(Return(true)); |
| 311 [shelf_ downloadWasOpened:item.get()]; | 312 [shelf_ downloadWasOpenedOrShown:item.get()]; |
| 312 | 313 |
| 313 // The shelf should now be waiting for the mouse to exit. autoClose should not | 314 // The shelf should now be waiting for the mouse to exit. autoClose should not |
| 314 // be scheduled yet. | 315 // be scheduled yet. |
| 315 EXPECT_TRUE([shelf_ isVisible]); | 316 EXPECT_TRUE([shelf_ isVisible]); |
| 316 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); | 317 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); |
| 317 EXPECT_EQ(0, shelf_.get()->cancelAutoCloseCount_); | 318 EXPECT_EQ(0, shelf_.get()->cancelAutoCloseCount_); |
| 318 | 319 |
| 319 // The mouse exits the shelf. autoClose should be scheduled now. | 320 // The mouse exits the shelf. autoClose should be scheduled now. |
| 320 [shelf_ mouseExited:cocoa_test_event_utils::ExitEvent()]; | 321 [shelf_ mouseExited:cocoa_test_event_utils::ExitEvent()]; |
| 321 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); | 322 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 342 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); | 343 EXPECT_EQ(2, shelf_.get()->cancelAutoCloseCount_); |
| 343 shelf_.get()->cancelAutoCloseCount_ = 0; | 344 shelf_.get()->cancelAutoCloseCount_ = 0; |
| 344 | 345 |
| 345 // The mouse enters the shelf. | 346 // The mouse enters the shelf. |
| 346 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; | 347 [shelf_ mouseEntered:cocoa_test_event_utils::EnterEvent()]; |
| 347 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); | 348 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); |
| 348 | 349 |
| 349 // The download opens. | 350 // The download opens. |
| 350 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) | 351 EXPECT_CALL(*[[item wrappedMockDownload] mockDownload], GetOpened()) |
| 351 .WillRepeatedly(Return(true)); | 352 .WillRepeatedly(Return(true)); |
| 352 [shelf_ downloadWasOpened:item.get()]; | 353 [shelf_ downloadWasOpenedOrShown:item.get()]; |
| 353 | 354 |
| 354 // The shelf should now be waiting for the mouse to exit. autoClose should not | 355 // The shelf should now be waiting for the mouse to exit. autoClose should not |
| 355 // be scheduled yet. | 356 // be scheduled yet. |
| 356 EXPECT_TRUE([shelf_ isVisible]); | 357 EXPECT_TRUE([shelf_ isVisible]); |
| 357 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); | 358 EXPECT_EQ(0, shelf_.get()->scheduleAutoCloseCount_); |
| 358 EXPECT_EQ(0, shelf_.get()->cancelAutoCloseCount_); | 359 EXPECT_EQ(0, shelf_.get()->cancelAutoCloseCount_); |
| 359 | 360 |
| 360 // The mouse exits the shelf. autoClose should be scheduled now. | 361 // The mouse exits the shelf. autoClose should be scheduled now. |
| 361 [shelf_ mouseExited:cocoa_test_event_utils::ExitEvent()]; | 362 [shelf_ mouseExited:cocoa_test_event_utils::ExitEvent()]; |
| 362 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); | 363 EXPECT_EQ(1, shelf_.get()->scheduleAutoCloseCount_); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 }]; | 401 }]; |
| 401 [shelf_ showDownloadShelf:NO isUserAction:NO]; | 402 [shelf_ showDownloadShelf:NO isUserAction:NO]; |
| 402 run_loop.Run(); | 403 run_loop.Run(); |
| 403 EXPECT_TRUE([[shelf_ view] isHidden]); | 404 EXPECT_TRUE([[shelf_ view] isHidden]); |
| 404 | 405 |
| 405 [shelf_ showDownloadShelf:YES isUserAction:NO]; | 406 [shelf_ showDownloadShelf:YES isUserAction:NO]; |
| 406 EXPECT_FALSE([[shelf_ view] isHidden]); | 407 EXPECT_FALSE([[shelf_ view] isHidden]); |
| 407 } | 408 } |
| 408 | 409 |
| 409 } // namespace | 410 } // namespace |
| OLD | NEW |