OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #import <Cocoa/Cocoa.h> | |
6 | |
7 #include "base/message_loop.h" | |
8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | |
9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_hover_state.h" | |
10 #import "chrome/browser/ui/cocoa/browser_test_helper.h" | |
11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
12 | |
13 namespace { | |
14 | |
15 typedef CocoaTest BookmarkBarFolderHoverStateTest; | |
16 | |
17 // Hover state machine interface. | |
18 // A strict call order is implied with these calls. It is ONLY valid to make | |
19 // these specific state transitions. | |
20 TEST(BookmarkBarFolderHoverStateTest, HoverState) { | |
21 BrowserTestHelper helper; | |
22 scoped_nsobject<BookmarkBarFolderHoverState> bbfhs; | |
23 bbfhs.reset([[BookmarkBarFolderHoverState alloc] init]); | |
24 | |
25 // Initial state. | |
26 EXPECT_FALSE([bbfhs hoverButton]); | |
27 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); | |
28 | |
29 scoped_nsobject<BookmarkButton> button; | |
30 button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0, 0, 20, 20)]); | |
31 | |
32 // Test transition from closed to opening. | |
33 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); | |
34 [bbfhs scheduleOpenBookmarkFolderOnHoverButton:button]; | |
35 ASSERT_EQ(kHoverStateOpening, [bbfhs hoverState]); | |
36 | |
37 // Test transition from opening to closed (aka cancel open). | |
38 [bbfhs cancelPendingOpenBookmarkFolderOnHoverButton]; | |
39 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); | |
40 ASSERT_EQ(nil, [bbfhs hoverButton]); | |
41 | |
42 // Test transition from closed to opening. | |
43 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); | |
44 [bbfhs scheduleOpenBookmarkFolderOnHoverButton:button]; | |
45 ASSERT_EQ(kHoverStateOpening, [bbfhs hoverState]); | |
46 | |
47 // Test transition from opening to opened. | |
48 MessageLoop::current()->PostDelayedTask( | |
49 FROM_HERE, | |
50 new MessageLoop::QuitTask, | |
51 bookmarks::kDragHoverOpenDelay * 1000.0 * 1.5); | |
52 MessageLoop::current()->Run(); | |
53 ASSERT_EQ(kHoverStateOpen, [bbfhs hoverState]); | |
54 ASSERT_EQ(button, [bbfhs hoverButton]); | |
55 | |
56 // Test transition from opening to opened. | |
57 [bbfhs scheduleCloseBookmarkFolderOnHoverButton]; | |
58 ASSERT_EQ(kHoverStateClosing, [bbfhs hoverState]); | |
59 | |
60 // Test transition from closing to open (aka cancel close). | |
61 [bbfhs cancelPendingCloseBookmarkFolderOnHoverButton]; | |
62 ASSERT_EQ(kHoverStateOpen, [bbfhs hoverState]); | |
63 ASSERT_EQ(button, [bbfhs hoverButton]); | |
64 | |
65 // Test transition from closing to closed. | |
66 [bbfhs scheduleCloseBookmarkFolderOnHoverButton]; | |
67 ASSERT_EQ(kHoverStateClosing, [bbfhs hoverState]); | |
68 MessageLoop::current()->PostDelayedTask( | |
69 FROM_HERE, | |
70 new MessageLoop::QuitTask, | |
71 bookmarks::kDragHoverCloseDelay * 1000.0 * 1.5); | |
72 MessageLoop::current()->Run(); | |
73 ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]); | |
74 ASSERT_EQ(nil, [bbfhs hoverButton]); | |
75 } | |
76 | |
77 } // namespace | |
OLD | NEW |