| OLD | NEW |
| 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" |
| 8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" | 11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" |
| 10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 11 | 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 class BookmarkBarFolderHoverStateTest : public CocoaTest { | 16 class BookmarkBarFolderHoverStateTest : public CocoaTest { |
| 15 }; | 17 }; |
| 16 | 18 |
| 17 // Hover state machine interface. | 19 // Hover state machine interface. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 38 [bbfhs cancelPendingOpenBookmarkFolderOnHoverButton]; | 40 [bbfhs cancelPendingOpenBookmarkFolderOnHoverButton]; |
| 39 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); | 41 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); |
| 40 ASSERT_EQ(nil, [bbfhs hoverButton]); | 42 ASSERT_EQ(nil, [bbfhs hoverButton]); |
| 41 | 43 |
| 42 // Test transition from closed to opening. | 44 // Test transition from closed to opening. |
| 43 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); | 45 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); |
| 44 [bbfhs scheduleOpenBookmarkFolderOnHoverButton:button]; | 46 [bbfhs scheduleOpenBookmarkFolderOnHoverButton:button]; |
| 45 ASSERT_EQ(kHoverStateOpening, [bbfhs hoverState]); | 47 ASSERT_EQ(kHoverStateOpening, [bbfhs hoverState]); |
| 46 | 48 |
| 47 // Test transition from opening to opened. | 49 // Test transition from opening to opened. |
| 48 message_loop.PostDelayedTask( | 50 { |
| 49 FROM_HERE, | 51 base::RunLoop run_loop; |
| 50 base::MessageLoop::QuitWhenIdleClosure(), | 52 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 51 base::TimeDelta::FromMilliseconds( | 53 FROM_HERE, run_loop.QuitWhenIdleClosure(), |
| 52 bookmarks::kDragHoverOpenDelay * 1000.0 * 1.5)); | 54 base::TimeDelta::FromMilliseconds(bookmarks::kDragHoverOpenDelay * |
| 53 message_loop.Run(); | 55 1000.0 * 1.5)); |
| 54 ASSERT_EQ(kHoverStateOpen, [bbfhs hoverState]); | 56 run_loop.Run(); |
| 55 ASSERT_EQ(button, [bbfhs hoverButton]); | 57 ASSERT_EQ(kHoverStateOpen, [bbfhs hoverState]); |
| 58 ASSERT_EQ(button, [bbfhs hoverButton]); |
| 59 } |
| 56 | 60 |
| 57 // Test transition from opening to opened. | 61 // Test transition from opening to opened. |
| 58 [bbfhs scheduleCloseBookmarkFolderOnHoverButton]; | 62 [bbfhs scheduleCloseBookmarkFolderOnHoverButton]; |
| 59 ASSERT_EQ(kHoverStateClosing, [bbfhs hoverState]); | 63 ASSERT_EQ(kHoverStateClosing, [bbfhs hoverState]); |
| 60 | 64 |
| 61 // Test transition from closing to open (aka cancel close). | 65 // Test transition from closing to open (aka cancel close). |
| 62 [bbfhs cancelPendingCloseBookmarkFolderOnHoverButton]; | 66 [bbfhs cancelPendingCloseBookmarkFolderOnHoverButton]; |
| 63 ASSERT_EQ(kHoverStateOpen, [bbfhs hoverState]); | 67 ASSERT_EQ(kHoverStateOpen, [bbfhs hoverState]); |
| 64 ASSERT_EQ(button, [bbfhs hoverButton]); | 68 ASSERT_EQ(button, [bbfhs hoverButton]); |
| 65 | 69 |
| 66 // Test transition from closing to closed. | 70 // Test transition from closing to closed. |
| 67 [bbfhs scheduleCloseBookmarkFolderOnHoverButton]; | 71 { |
| 68 ASSERT_EQ(kHoverStateClosing, [bbfhs hoverState]); | 72 base::RunLoop run_loop; |
| 69 message_loop.PostDelayedTask( | 73 [bbfhs scheduleCloseBookmarkFolderOnHoverButton]; |
| 70 FROM_HERE, | 74 ASSERT_EQ(kHoverStateClosing, [bbfhs hoverState]); |
| 71 base::MessageLoop::QuitWhenIdleClosure(), | 75 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 72 base::TimeDelta::FromMilliseconds( | 76 FROM_HERE, run_loop.QuitWhenIdleClosure(), |
| 73 bookmarks::kDragHoverCloseDelay * 1000.0 * 1.5)); | 77 base::TimeDelta::FromMilliseconds(bookmarks::kDragHoverCloseDelay * |
| 74 message_loop.Run(); | 78 1000.0 * 1.5)); |
| 75 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); | 79 run_loop.Run(); |
| 76 ASSERT_EQ(nil, [bbfhs hoverButton]); | 80 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); |
| 81 ASSERT_EQ(nil, [bbfhs hoverButton]); |
| 82 } |
| 77 } | 83 } |
| 78 | 84 |
| 79 } // namespace | 85 } // namespace |
| OLD | NEW |