OLD | NEW |
| (Empty) |
1 // Copyright 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. | |
4 | |
5 #import "ios/chrome/browser/ui/context_menu/context_menu_controller.h" | |
6 | |
7 #import <UIKit/UIKit.h> | |
8 | |
9 #include "base/mac/scoped_nsobject.h" | |
10 #import "ios/chrome/browser/ui/context_menu/context_menu_holder.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "testing/platform_test.h" | |
13 | |
14 namespace { | |
15 | |
16 class ContextMenuControllerTest : public PlatformTest { | |
17 public: | |
18 ContextMenuControllerTest() { | |
19 _menuController.reset([[ContextMenuController alloc] init]); | |
20 _window.reset( | |
21 [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]); | |
22 [_window makeKeyAndVisible]; | |
23 } | |
24 | |
25 protected: | |
26 base::scoped_nsobject<ContextMenuController> _menuController; | |
27 base::scoped_nsobject<UIWindow> _window; | |
28 }; | |
29 | |
30 TEST_F(ContextMenuControllerTest, OneEntry) { | |
31 base::scoped_nsobject<ContextMenuHolder> holder( | |
32 [[ContextMenuHolder alloc] init]); | |
33 BOOL clicked = NO; | |
34 BOOL* clickedPtr = &clicked; | |
35 | |
36 [holder appendItemWithTitle:@"foo" action:^{ | |
37 *clickedPtr = YES; | |
38 }]; | |
39 [holder setMenuTitle:@"FooTitle"]; | |
40 | |
41 [_menuController showWithHolder:holder atPoint:CGPointZero inView:_window]; | |
42 | |
43 EXPECT_TRUE([_menuController isVisible]); | |
44 } | |
45 | |
46 TEST_F(ContextMenuControllerTest, ShouldDismissImmediately) { | |
47 base::scoped_nsobject<ContextMenuHolder> holder( | |
48 [[ContextMenuHolder alloc] init]); | |
49 [holder appendItemWithTitle:@"foo" action:^{}]; | |
50 [holder appendItemWithTitle:@"bar" action:^{} dismissImmediately:YES]; | |
51 [holder appendItemWithTitle:@"baz" action:^{} dismissImmediately:NO]; | |
52 | |
53 EXPECT_FALSE([holder shouldDismissImmediatelyOnClickedAtIndex:0]); | |
54 EXPECT_TRUE([holder shouldDismissImmediatelyOnClickedAtIndex:1]); | |
55 EXPECT_FALSE([holder shouldDismissImmediatelyOnClickedAtIndex:2]); | |
56 } | |
57 | |
58 } // namespace | |
OLD | NEW |