| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/location_bar/ev_bubble_decoration.h" | 7 #import "chrome/browser/ui/cocoa/location_bar/security_state_bubble_decoration.h
" |
| 8 | 8 |
| 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 10 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 class EVBubbleDecorationTest : public CocoaTest { | 15 class SecurityStateBubbleDecorationTest : public CocoaTest { |
| 15 public: | 16 public: |
| 16 EVBubbleDecorationTest() : decoration_(NULL) { | 17 SecurityStateBubbleDecorationTest() |
| 18 : icon_(nullptr), decoration_(&icon_, nullptr) { |
| 19 decoration_.disable_animations_during_testing_ = true; |
| 17 } | 20 } |
| 18 | 21 |
| 19 EVBubbleDecoration decoration_; | 22 LocationIconDecoration icon_; |
| 23 SecurityStateBubbleDecoration decoration_; |
| 20 }; | 24 }; |
| 21 | 25 |
| 22 // Test that the decoration gets smaller when there's not enough space | 26 // Test that the decoration gets smaller when there's not enough space |
| 23 // to fit, within bounds. | 27 // to fit, within bounds. |
| 24 TEST_F(EVBubbleDecorationTest, MiddleElide) { | 28 TEST_F(SecurityStateBubbleDecorationTest, MiddleElide) { |
| 25 NSString* kLongString = @"A very long string with spaces"; | 29 NSString* kLongString = @"A very long string with spaces"; |
| 26 const CGFloat kWide = 1000.0; // Wide enough to fit everything. | 30 const CGFloat kWide = 1000.0; // Wide enough to fit everything. |
| 27 const CGFloat kNarrow = 10.0; // Too narrow for anything. | 31 const CGFloat kNarrow = 10.0; // Too narrow for anything. |
| 28 const CGFloat kMinimumWidth = 100.0; // Never should get this small. | 32 const CGFloat kMinimumWidth = 100.0; // Never should get this small. |
| 29 | 33 |
| 30 const NSSize kImageSize = NSMakeSize(20.0, 20.0); | 34 const NSSize kImageSize = NSMakeSize(20.0, 20.0); |
| 31 base::scoped_nsobject<NSImage> image( | 35 base::scoped_nsobject<NSImage> image( |
| 32 [[NSImage alloc] initWithSize:kImageSize]); | 36 [[NSImage alloc] initWithSize:kImageSize]); |
| 33 | 37 |
| 34 decoration_.SetImage(image); | 38 decoration_.SetImage(image); |
| 35 decoration_.SetFullLabel(kLongString); | 39 decoration_.SetFullLabel(kLongString); |
| 36 | 40 |
| 37 // Lots of space, decoration not omitted. | 41 // Lots of space, decoration not omitted. |
| 38 EXPECT_NE(decoration_.GetWidthForSpace(kWide), | 42 EXPECT_NE(decoration_.GetWidthForSpace(kWide), |
| 39 LocationBarDecoration::kOmittedWidth); | 43 LocationBarDecoration::kOmittedWidth); |
| 40 | 44 |
| 41 // If the available space is of the same magnitude as the required | 45 // If the available space is of the same magnitude as the required |
| 42 // space, the decoration doesn't eat it all up. | 46 // space, the decoration doesn't eat it all up. |
| 43 const CGFloat long_width = decoration_.GetWidthForSpace(kWide); | 47 const CGFloat long_width = decoration_.GetWidthForSpace(kWide); |
| 44 EXPECT_NE(decoration_.GetWidthForSpace(long_width + 20.0), | 48 EXPECT_NE(decoration_.GetWidthForSpace(long_width + 20.0), |
| 45 LocationBarDecoration::kOmittedWidth); | 49 LocationBarDecoration::kOmittedWidth); |
| 46 EXPECT_LT(decoration_.GetWidthForSpace(long_width + 20.0), long_width); | 50 EXPECT_LT(decoration_.GetWidthForSpace(long_width + 20.0), long_width); |
| 47 | 51 |
| 48 // If there is very little space, the decoration is still relatively | 52 // If there is very little space, the decoration is still relatively |
| 49 // big. | 53 // big. |
| 50 EXPECT_NE(decoration_.GetWidthForSpace(kNarrow), | 54 EXPECT_NE(decoration_.GetWidthForSpace(kNarrow), |
| 51 LocationBarDecoration::kOmittedWidth); | 55 LocationBarDecoration::kOmittedWidth); |
| 52 EXPECT_GT(decoration_.GetWidthForSpace(kNarrow), kMinimumWidth); | 56 EXPECT_GT(decoration_.GetWidthForSpace(kNarrow), kMinimumWidth); |
| 53 } | 57 } |
| 54 | 58 |
| 55 } // namespace | 59 } // namespace |
| OLD | NEW |