summaryrefslogtreecommitdiffstats
path: root/ui/base/ios/cru_context_menu_controller_unittest.mm
blob: 31863d78648d010ef36bc05b6d90cbeb051cf2c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "ui/base/ios/cru_context_menu_controller.h"

#import <UIKit/UIKit.h>

#include "base/mac/scoped_nsobject.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "ui/base/ios/cru_context_menu_holder.h"

namespace {

class ContextMenuControllerTest : public PlatformTest {
 public:
  ContextMenuControllerTest() { }

  void SetUp() override {
    _menuController.reset([[CRUContextMenuController alloc] init]);
    _window.reset(
        [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
    [_window makeKeyAndVisible];
  }

 protected:
  base::scoped_nsobject<CRUContextMenuController> _menuController;
  base::scoped_nsobject<UIWindow> _window;
};

TEST_F(ContextMenuControllerTest, OneEntry) {
  base::scoped_nsobject<CRUContextMenuHolder> holder(
      [[CRUContextMenuHolder alloc] init]);
  BOOL clicked = NO;
  BOOL* clickedPtr = &clicked;

  [holder appendItemWithTitle:@"foo" action:^{ *clickedPtr = YES; }];
  [holder setMenuTitle:@"FooTitle"];

  [_menuController showWithHolder:holder atPoint:CGPointZero inView:_window];

  EXPECT_TRUE([_menuController isVisible]);
}

TEST_F(ContextMenuControllerTest, ShouldDismissImmediately) {
  base::scoped_nsobject<CRUContextMenuHolder> holder(
      [[CRUContextMenuHolder alloc] init]);
  [holder appendItemWithTitle:@"foo" action:^{}];
  [holder appendItemWithTitle:@"bar" action:^{} dismissImmediately:YES];
  [holder appendItemWithTitle:@"baz" action:^{} dismissImmediately:NO];

  EXPECT_FALSE([holder shouldDismissImmediatelyOnClickedAtIndex:0]);
  EXPECT_TRUE([holder shouldDismissImmediatelyOnClickedAtIndex:1]);
  EXPECT_FALSE([holder shouldDismissImmediatelyOnClickedAtIndex:2]);
}

}  // namespace