Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_bar_folder_hover_state_unittest.mm
blobf9a95ba956824602061484c2777f7d983dfeb1ba
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
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
7 #include "base/message_loop/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/cocoa_test_helper.h"
12 namespace {
14 class BookmarkBarFolderHoverStateTest : public CocoaTest {
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_F(BookmarkBarFolderHoverStateTest, HoverState) {
21   base::MessageLoopForUI message_loop;
22   base::scoped_nsobject<BookmarkBarFolderHoverState> bbfhs;
23   bbfhs.reset([[BookmarkBarFolderHoverState alloc] init]);
25   // Initial state.
26   EXPECT_FALSE([bbfhs hoverButton]);
27   ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]);
29   base::scoped_nsobject<BookmarkButton> button;
30   button.reset([[BookmarkButton alloc] initWithFrame:NSMakeRect(0, 0, 20, 20)]);
32   // Test transition from closed to opening.
33   ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]);
34   [bbfhs scheduleOpenBookmarkFolderOnHoverButton:button];
35   ASSERT_EQ(kHoverStateOpening, [bbfhs hoverState]);
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]);
42   // Test transition from closed to opening.
43   ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]);
44   [bbfhs scheduleOpenBookmarkFolderOnHoverButton:button];
45   ASSERT_EQ(kHoverStateOpening, [bbfhs hoverState]);
47   // Test transition from opening to opened.
48   message_loop.PostDelayedTask(
49       FROM_HERE,
50       base::MessageLoop::QuitClosure(),
51       base::TimeDelta::FromMilliseconds(
52           bookmarks::kDragHoverOpenDelay * 1000.0 * 1.5));
53   message_loop.Run();
54   ASSERT_EQ(kHoverStateOpen, [bbfhs hoverState]);
55   ASSERT_EQ(button, [bbfhs hoverButton]);
57   // Test transition from opening to opened.
58   [bbfhs scheduleCloseBookmarkFolderOnHoverButton];
59   ASSERT_EQ(kHoverStateClosing, [bbfhs hoverState]);
61   // Test transition from closing to open (aka cancel close).
62   [bbfhs cancelPendingCloseBookmarkFolderOnHoverButton];
63   ASSERT_EQ(kHoverStateOpen, [bbfhs hoverState]);
64   ASSERT_EQ(button, [bbfhs hoverButton]);
66   // Test transition from closing to closed.
67   [bbfhs scheduleCloseBookmarkFolderOnHoverButton];
68   ASSERT_EQ(kHoverStateClosing, [bbfhs hoverState]);
69   message_loop.PostDelayedTask(
70       FROM_HERE,
71       base::MessageLoop::QuitClosure(),
72       base::TimeDelta::FromMilliseconds(
73           bookmarks::kDragHoverCloseDelay * 1000.0 * 1.5));
74   message_loop.Run();
75   ASSERT_EQ(kHoverStateClosed, [bbfhs hoverState]);
76   ASSERT_EQ(nil, [bbfhs hoverButton]);
79 }  // namespace