Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / base / ios / cru_context_menu_controller_unittest.mm
blobd7b4534129b144ff5445d274a2ce96e9ca82f649
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.
5 #import "ui/base/ios/cru_context_menu_controller.h"
7 #import <UIKit/UIKit.h>
9 #include "base/mac/scoped_nsobject.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h"
12 #import "ui/base/ios/cru_context_menu_holder.h"
14 namespace {
16 class ContextMenuControllerTest : public PlatformTest {
17  public:
18   ContextMenuControllerTest() { }
20   void SetUp() override {
21     _menuController.reset([[CRUContextMenuController alloc] init]);
22     _window.reset(
23         [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
24     [_window makeKeyAndVisible];
25   }
27  protected:
28   base::scoped_nsobject<CRUContextMenuController> _menuController;
29   base::scoped_nsobject<UIWindow> _window;
32 TEST_F(ContextMenuControllerTest, OneEntry) {
33   base::scoped_nsobject<CRUContextMenuHolder> holder(
34       [[CRUContextMenuHolder alloc] init]);
35   BOOL clicked = NO;
36   BOOL* clickedPtr = &clicked;
38   [holder appendItemWithTitle:@"foo" action:^{ *clickedPtr = YES; }];
39   [holder setMenuTitle:@"FooTitle"];
41   [_menuController showWithHolder:holder atPoint:CGPointZero inView:_window];
43   EXPECT_TRUE([_menuController isVisible]);
45   UIActionSheet* sheet = _menuController.get().sheet;
46   [sheet dismissWithClickedButtonIndex:0 animated:NO];
47   [_menuController actionSheet:sheet didDismissWithButtonIndex:0];
49   EXPECT_TRUE(clicked);
50   EXPECT_FALSE([_menuController isVisible]);
53 TEST_F(ContextMenuControllerTest, ShouldDismissImmediately) {
54   base::scoped_nsobject<CRUContextMenuHolder> holder(
55       [[CRUContextMenuHolder alloc] init]);
56   [holder appendItemWithTitle:@"foo" action:^{}];
57   [holder appendItemWithTitle:@"bar" action:^{} dismissImmediately:YES];
58   [holder appendItemWithTitle:@"baz" action:^{} dismissImmediately:NO];
60   EXPECT_FALSE([holder shouldDismissImmediatelyOnClickedAtIndex:0]);
61   EXPECT_TRUE([holder shouldDismissImmediatelyOnClickedAtIndex:1]);
62   EXPECT_FALSE([holder shouldDismissImmediatelyOnClickedAtIndex:2]);
65 }  // namespace