Home | History | Annotate | Download | only in location_bar
      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
      3 // found in the LICENSE file.
      4 
      5 #import <Cocoa/Cocoa.h>
      6 
      7 #import "chrome/browser/ui/cocoa/location_bar/image_decoration.h"
      8 
      9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
     10 #include "testing/gtest/include/gtest/gtest.h"
     11 
     12 namespace {
     13 
     14 class ImageDecorationTest : public CocoaTest {
     15  public:
     16   ImageDecoration decoration_;
     17 };
     18 
     19 TEST_F(ImageDecorationTest, SetGetImage) {
     20   EXPECT_FALSE(decoration_.GetImage());
     21 
     22   const NSSize kImageSize = NSMakeSize(20.0, 20.0);
     23   scoped_nsobject<NSImage> image([[NSImage alloc] initWithSize:kImageSize]);
     24 
     25   decoration_.SetImage(image);
     26   EXPECT_EQ(decoration_.GetImage(), image);
     27 
     28   decoration_.SetImage(nil);
     29   EXPECT_FALSE(decoration_.GetImage());
     30 }
     31 
     32 TEST_F(ImageDecorationTest, GetWidthForSpace) {
     33   const CGFloat kWide = 100.0;
     34   const CGFloat kNarrow = 10.0;
     35 
     36   // Decoration with no image is omitted.
     37   EXPECT_EQ(decoration_.GetWidthForSpace(kWide),
     38             LocationBarDecoration::kOmittedWidth);
     39 
     40   const NSSize kImageSize = NSMakeSize(20.0, 20.0);
     41   scoped_nsobject<NSImage> image([[NSImage alloc] initWithSize:kImageSize]);
     42 
     43   // Decoration takes up the space of the image.
     44   decoration_.SetImage(image);
     45   EXPECT_EQ(decoration_.GetWidthForSpace(kWide), kImageSize.width);
     46 
     47   // If the image doesn't fit, decoration is omitted.
     48   EXPECT_EQ(decoration_.GetWidthForSpace(kNarrow),
     49             LocationBarDecoration::kOmittedWidth);
     50 }
     51 
     52 // TODO(shess): It would be nice to test mouse clicks and dragging,
     53 // but those are hard because they require a real |owner|.
     54 
     55 }  // namespace
     56