Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / browser_actions_container_view_unittest.mm
blob18e0f92f2bf45ab0e0d32ef9e374855d0637f6f8
1 // Copyright (c) 2011 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 #include "base/mac/scoped_nsobject.h"
6 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
7 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/platform_test.h"
11 namespace {
13 const CGFloat kContainerHeight = 15.0;
14 const CGFloat kMinimumContainerWidth = 3.0;
15 const CGFloat kMaxAllowedWidthForTest = 50.0;
17 class BrowserActionsContainerTestDelegate
18     : public BrowserActionsContainerViewSizeDelegate {
19  public:
20   BrowserActionsContainerTestDelegate() {}
21   ~BrowserActionsContainerTestDelegate() override {}
23   CGFloat GetMaxAllowedWidth() override { return kMaxAllowedWidthForTest; }
25  private:
26   DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainerTestDelegate);
29 class BrowserActionsContainerViewTest : public CocoaTest {
30  public:
31   void SetUp() override {
32     CocoaTest::SetUp();
33     view_.reset([[BrowserActionsContainerView alloc]
34         initWithFrame:NSMakeRect(0, 0, 0, kContainerHeight)]);
35   }
37   base::scoped_nsobject<BrowserActionsContainerView> view_;
40 TEST_F(BrowserActionsContainerViewTest, BasicTests) {
41   EXPECT_TRUE([view_ canDragLeft]);
42   EXPECT_TRUE([view_ canDragRight]);
43   EXPECT_TRUE([view_ isHidden]);
46 TEST_F(BrowserActionsContainerViewTest, SetWidthTests) {
47   // Try setting below the minimum width (10 pixels).
48   [view_ resizeToWidth:kMinimumContainerWidth - 1 animate:NO];
49   EXPECT_EQ(kMinimumContainerWidth, NSWidth([view_ frame])) << "Frame width is "
50       << "less than the minimum allowed.";
52   [view_ resizeToWidth:35.0 animate:NO];
53   EXPECT_EQ(35.0, NSWidth([view_ frame]));
55   [view_ resizeToWidth:20.0 animate:NO];
56   EXPECT_EQ(20.0, NSWidth([view_ frame]));
58   // Resize the view with animation. It shouldn't immediately take the new
59   // value, but the animationEndFrame should reflect the pending change.
60   [view_ resizeToWidth:40.0 animate:YES];
61   EXPECT_LE(NSWidth([view_ frame]), 40.0);
62   EXPECT_EQ(40.0, NSWidth([view_ animationEndFrame]));
64   // The container should be able to be resized while animating (simply taking
65   // the newest target width).
66   [view_ resizeToWidth:30.0 animate:YES];
67   EXPECT_EQ(30.0, NSWidth([view_ animationEndFrame]));
69   // Test with no animation again. The animationEndFrame should also reflect
70   // the current frame, if no animation is pending.
71   [view_ resizeToWidth:35.0 animate:NO];
72   EXPECT_EQ(35.0, NSWidth([view_ frame]));
73   EXPECT_EQ(35.0, NSWidth([view_ animationEndFrame]));
75   BrowserActionsContainerTestDelegate delegate;
76   [view_ setDelegate:&delegate];
77   [view_ resizeToWidth:kMaxAllowedWidthForTest + 10.0 animate:NO];
78   EXPECT_EQ(kMaxAllowedWidthForTest, NSWidth([view_ frame]));
79   [view_ setDelegate:nil];
82 }  // namespace