summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-26 23:40:22 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-26 23:40:22 +0000
commit13d54f79c040c2e6beeed94e096d1fcf2b0f7101 (patch)
treee1f4ff9d2dc345dc8010b18d57b7120fa3464c7f /chrome
parent3a14d29c7fbb32f44e84c0b5c25e8d618ed000a0 (diff)
downloadchromium_src-13d54f79c040c2e6beeed94e096d1fcf2b0f7101.zip
chromium_src-13d54f79c040c2e6beeed94e096d1fcf2b0f7101.tar.gz
chromium_src-13d54f79c040c2e6beeed94e096d1fcf2b0f7101.tar.bz2
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
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cocoa/chrome_event_processing_window_unittest.mm27
-rw-r--r--chrome/browser/cocoa/extension_shelf_controller_unittest.mm18
-rw-r--r--chrome/browser/cocoa/find_bar_bridge_unittest.mm6
-rw-r--r--chrome/browser/cocoa/infobar_gradient_view_unittest.mm28
-rw-r--r--chrome/browser/cocoa/menu_button_unittest.mm30
5 files changed, 36 insertions, 73 deletions
diff --git a/chrome/browser/cocoa/chrome_event_processing_window_unittest.mm b/chrome/browser/cocoa/chrome_event_processing_window_unittest.mm
index 817cf4c..48c8d23 100644
--- a/chrome/browser/cocoa/chrome_event_processing_window_unittest.mm
+++ b/chrome/browser/cocoa/chrome_event_processing_window_unittest.mm
@@ -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
diff --git a/chrome/browser/cocoa/extension_shelf_controller_unittest.mm b/chrome/browser/cocoa/extension_shelf_controller_unittest.mm
index ddbca2a..765f9af 100644
--- a/chrome/browser/cocoa/extension_shelf_controller_unittest.mm
+++ b/chrome/browser/cocoa/extension_shelf_controller_unittest.mm
@@ -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
diff --git a/chrome/browser/cocoa/find_bar_bridge_unittest.mm b/chrome/browser/cocoa/find_bar_bridge_unittest.mm
index f945d50..c0cf6b4 100644
--- a/chrome/browser/cocoa/find_bar_bridge_unittest.mm
+++ b/chrome/browser/cocoa/find_bar_bridge_unittest.mm
@@ -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) {
diff --git a/chrome/browser/cocoa/infobar_gradient_view_unittest.mm b/chrome/browser/cocoa/infobar_gradient_view_unittest.mm
index fafa206..2c1ec21 100644
--- a/chrome/browser/cocoa/infobar_gradient_view_unittest.mm
+++ b/chrome/browser/cocoa/infobar_gradient_view_unittest.mm
@@ -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.
diff --git a/chrome/browser/cocoa/menu_button_unittest.mm b/chrome/browser/cocoa/menu_button_unittest.mm
index 321a3bb4..6b7ba2b 100644
--- a/chrome/browser/cocoa/menu_button_unittest.mm
+++ b/chrome/browser/cocoa/menu_button_unittest.mm
@@ -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]);