From 7a54688883ec2f15fbf5da68a5c011d322ff6292 Mon Sep 17 00:00:00 2001 From: "pinkerton@chromium.org" Date: Tue, 21 Apr 2009 14:24:54 +0000 Subject: Unit tests for button cells we use in the UI. Review URL: http://codereview.chromium.org/87023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14098 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/cocoa/tab_cell_unittest.mm | 41 +++++++++++++++++++++ .../browser/cocoa/toolbar_button_cell_unittest.mm | 42 ++++++++++++++++++++++ chrome/chrome.gyp | 2 ++ 3 files changed, 85 insertions(+) create mode 100644 chrome/browser/cocoa/tab_cell_unittest.mm create mode 100644 chrome/browser/cocoa/toolbar_button_cell_unittest.mm diff --git a/chrome/browser/cocoa/tab_cell_unittest.mm b/chrome/browser/cocoa/tab_cell_unittest.mm new file mode 100644 index 0000000..c27c197 --- /dev/null +++ b/chrome/browser/cocoa/tab_cell_unittest.mm @@ -0,0 +1,41 @@ +// Copyright (c) 2009 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 + +#include "base/scoped_nsobject.h" +#import "chrome/browser/cocoa/tab_cell.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class TabCellTest : public testing::Test { + public: + TabCellTest() { + NSRect frame = NSMakeRect(0, 0, 50, 30); + view_.reset([[NSButton alloc] initWithFrame:frame]); + scoped_nsobject cell([[TabCell alloc] initTextCell:@"Testing"]); + [view_ setCell:cell.get()]; + [cocoa_helper_.contentView() addSubview:view_.get()]; + } + + CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... + scoped_nsobject view_; +}; + +// Test adding/removing from the view hierarchy, mostly to ensure nothing +// leaks or crashes. +TEST_F(TabCellTest, AddRemove) { + EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]); + [view_.get() removeFromSuperview]; + EXPECT_FALSE([view_ superview]); +} + +// Test drawing, mostly to ensure nothing leaks or crashes. +TEST_F(TabCellTest, Display) { + [view_ display]; +} + +} // namespace diff --git a/chrome/browser/cocoa/toolbar_button_cell_unittest.mm b/chrome/browser/cocoa/toolbar_button_cell_unittest.mm new file mode 100644 index 0000000..e1cb467 --- /dev/null +++ b/chrome/browser/cocoa/toolbar_button_cell_unittest.mm @@ -0,0 +1,42 @@ +// Copyright (c) 2009 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 + +#include "base/scoped_nsobject.h" +#import "chrome/browser/cocoa/toolbar_button_cell.h" +#import "chrome/browser/cocoa/cocoa_test_helper.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class ToolbarButtonCellTest : public testing::Test { + public: + ToolbarButtonCellTest() { + NSRect frame = NSMakeRect(0, 0, 50, 30); + view_.reset([[NSButton alloc] initWithFrame:frame]); + scoped_nsobject cell([[ToolbarButtonCell alloc] + initTextCell:@"Testing"]); + [view_ setCell:cell.get()]; + [cocoa_helper_.contentView() addSubview:view_.get()]; + } + + CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... + scoped_nsobject view_; +}; + +// Test adding/removing from the view hierarchy, mostly to ensure nothing +// leaks or crashes. +TEST_F(ToolbarButtonCellTest, AddRemove) { + EXPECT_EQ(cocoa_helper_.contentView(), [view_ superview]); + [view_.get() removeFromSuperview]; + EXPECT_FALSE([view_ superview]); +} + +// Test drawing, mostly to ensure nothing leaks or crashes. +TEST_F(ToolbarButtonCellTest, Display) { + [view_ display]; +} + +} // namespace diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index eb3a63a..da398e1 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -2148,9 +2148,11 @@ 'browser/cocoa/location_bar_view_mac_unittest.mm', 'browser/cocoa/grow_box_view_unittest.mm', 'browser/cocoa/status_bubble_mac_unittest.mm', + 'browser/cocoa/tab_cell_unittest.mm', 'browser/cocoa/tab_controller_unittest.mm', 'browser/cocoa/tab_strip_view_unittest.mm', 'browser/cocoa/tab_view_unittest.mm', + 'browser/cocoa/toolbar_button_cell_unittest.mm', 'browser/cocoa/toolbar_controller_unittest.mm', 'browser/cocoa/toolbar_view_unittest.mm', 'browser/command_updater_unittest.cc', -- cgit v1.1