Commit 13d54f79 authored by dmaclach@chromium.org's avatar dmaclach@chromium.org

First set of unittest fixes. Many more to come ;-)

TEST=run the unittests and watch them pass.
BUG=none

Review URL: http://codereview.chromium.org/334016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30126 0039d316-1c4b-4281-b951-d872f2087c98
parent 3a14d29c
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include "base/scoped_nsobject.h"
#include "chrome/app/chrome_dll_resource.h"
......@@ -10,8 +9,6 @@
#import "chrome/browser/cocoa/browser_window_controller.h"
#import "chrome/browser/cocoa/browser_frame_view.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"
namespace {
......@@ -29,17 +26,18 @@ NSEvent* KeyEvent(const NSUInteger flags, const NSUInteger keyCode) {
keyCode:keyCode];
}
class ChromeEventProcessingWindowTest : public PlatformTest {
class ChromeEventProcessingWindowTest : public CocoaTest {
public:
ChromeEventProcessingWindowTest() {
virtual void SetUp() {
CocoaTest::SetUp();
// Create a window.
const NSUInteger mask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask | NSResizableWindowMask;
window_.reset([[ChromeEventProcessingWindow alloc]
initWithContentRect:NSMakeRect(0, 0, 800, 600)
styleMask:mask
backing:NSBackingStoreBuffered
defer:NO]);
window_ = [[ChromeEventProcessingWindow alloc]
initWithContentRect:NSMakeRect(0, 0, 800, 600)
styleMask:mask
backing:NSBackingStoreBuffered
defer:NO];
if (DebugUtil::BeingDebugged()) {
[window_ orderFront:nil];
} else {
......@@ -47,6 +45,11 @@ class ChromeEventProcessingWindowTest : public PlatformTest {
}
}
virtual void TearDown() {
[window_ close];
CocoaTest::TearDown();
}
// Returns a canonical snapshot of the window.
NSData* WindowContentsAsTIFF() {
NSRect frame([window_ frame]);
......@@ -60,8 +63,7 @@ class ChromeEventProcessingWindowTest : public PlatformTest {
return [image TIFFRepresentation];
}
CocoaNoWindowTestHelper cocoa_helper_;
scoped_nsobject<ChromeEventProcessingWindow> window_;
ChromeEventProcessingWindow* window_;
};
// Verify that the window intercepts a particular key event and
......@@ -107,5 +109,4 @@ TEST_F(ChromeEventProcessingWindowTest, PerformKeyEquivalentNoForward) {
[delegate verify];
}
} // namespace
......@@ -2,19 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include "base/scoped_nsobject.h"
#include "chrome/browser/cocoa/browser_test_helper.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#import "chrome/browser/cocoa/extension_shelf_controller.h"
#import "chrome/browser/cocoa/view_resizer_pong.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace {
class ExtensionShelfControllerTest : public PlatformTest {
class ExtensionShelfControllerTest : public CocoaTest {
public:
ExtensionShelfControllerTest() {
resizeDelegate_.reset([[ViewResizerPong alloc] init]);
......@@ -23,14 +19,18 @@ class ExtensionShelfControllerTest : public PlatformTest {
controller_.reset([[ExtensionShelfController alloc]
initWithBrowser:helper_.browser()
resizeDelegate:resizeDelegate_.get()]);
NSView* view = [controller_ view];
EXPECT_TRUE(view);
[[test_window() contentView] addSubview:view];
}
CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
BrowserTestHelper helper_;
scoped_nsobject<ExtensionShelfController> controller_;
scoped_nsobject<ViewResizerPong> resizeDelegate_;
};
TEST_VIEW(ExtensionShelfControllerTest, [controller_ view]);
// Check that |hide:| tells the delegate to set the shelf's height to zero.
TEST_F(ExtensionShelfControllerTest, HideSetsHeightToZero) {
[resizeDelegate_ setHeight:10];
......@@ -47,10 +47,4 @@ TEST_F(ExtensionShelfControllerTest, ShowSetsHeightToHeight) {
EXPECT_EQ([controller_ height], [resizeDelegate_ height]);
}
// Test adding to the view hierarchy, mostly to ensure nothing leaks or crashes.
TEST_F(ExtensionShelfControllerTest, Add) {
[cocoa_helper_.contentView() addSubview:[controller_ view]];
[controller_ wasInsertedIntoWindow];
}
} // namespace
......@@ -5,14 +5,10 @@
#include "chrome/browser/find_bar_controller.h"
#include "chrome/browser/cocoa/cocoa_test_helper.h"
#include "chrome/browser/cocoa/find_bar_bridge.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace {
class FindBarBridgeTest : public PlatformTest {
protected:
CocoaTestHelper helper_;
class FindBarBridgeTest : public CocoaTest {
};
TEST_F(FindBarBridgeTest, Creation) {
......
......@@ -2,40 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/infobar_gradient_view.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace {
class InfoBarGradientViewTest : public PlatformTest {
class InfoBarGradientViewTest : public CocoaTest {
public:
InfoBarGradientViewTest() {
NSRect frame = NSMakeRect(0, 0, 100, 30);
view_.reset([[InfoBarGradientView alloc] initWithFrame:frame]);
[cocoa_helper_.contentView() addSubview:view_.get()];
scoped_nsobject<InfoBarGradientView> view(
[[InfoBarGradientView alloc] initWithFrame:frame]);
view_ = view.get();
[[test_window() contentView] addSubview:view_];
}
CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
scoped_nsobject<InfoBarGradientView> view_;
InfoBarGradientView* view_; // Weak. Retained by view hierarchy.
};
// Test adding/removing from the view hierarchy, mostly to ensure nothing
// leaks or crashes.
TEST_F(InfoBarGradientViewTest, 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(InfoBarGradientViewTest, Display) {
[view_ display];
}
TEST_VIEW(InfoBarGradientViewTest, view_);
// Assert that the view is non-opaque, because otherwise we will end
// up with findbar painting issues.
......
......@@ -2,44 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/clickhold_button_cell.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#import "chrome/browser/cocoa/menu_button.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace {
class MenuButtonTest : public PlatformTest {
class MenuButtonTest : public CocoaTest {
public:
MenuButtonTest() {
NSRect frame = NSMakeRect(0, 0, 50, 30);
button_.reset([[MenuButton alloc] initWithFrame:frame]);
scoped_nsobject<MenuButton> button(
[[MenuButton alloc] initWithFrame:frame]);
button_ = button.get();
scoped_nsobject<ClickHoldButtonCell> cell(
[[ClickHoldButtonCell alloc] initTextCell:@"Testing"]);
[button_ setCell:cell.get()];
[cocoa_helper_.contentView() addSubview:button_.get()];
[[test_window() contentView] addSubview:button_];
}
scoped_nsobject<MenuButton> button_;
CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc.
MenuButton* button_;
};
// Test adding/removing from the view hierarchy, mostly to ensure nothing leaks
// or crashes.
TEST_F(MenuButtonTest, AddRemove) {
EXPECT_EQ(cocoa_helper_.contentView(), [button_ superview]);
[button_.get() removeFromSuperview];
EXPECT_FALSE([button_ superview]);
}
// Test drawing, mostly to ensure nothing leaks or crashes.
TEST_F(MenuButtonTest, Display) {
[button_ display];
}
TEST_VIEW(MenuButtonTest, button_);
// Test assigning a menu, again mostly to ensure nothing leaks or crashes.
TEST_F(MenuButtonTest, MenuAssign) {
......@@ -50,7 +36,7 @@ TEST_F(MenuButtonTest, MenuAssign) {
[menu insertItemWithTitle:@"foo" action:nil keyEquivalent:@"" atIndex:1];
[menu insertItemWithTitle:@"bar" action:nil keyEquivalent:@"" atIndex:2];
[menu insertItemWithTitle:@"baz" action:nil keyEquivalent:@"" atIndex:3];
[button_ setAttachedMenu:menu];
EXPECT_TRUE([button_ attachedMenu]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment