summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/cocoa_test_helper.h
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-16 15:07:37 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-16 15:07:37 +0000
commitbeb3f472cb71a4ba25968a35b1c3dfeca59fc541 (patch)
tree2fe560cb292cf04a49c2b1720926476fa301821e /chrome/browser/cocoa/cocoa_test_helper.h
parentb1bf13e8638c4c2505b8169ee56c0552d957ff7b (diff)
downloadchromium_src-beb3f472cb71a4ba25968a35b1c3dfeca59fc541.zip
chromium_src-beb3f472cb71a4ba25968a35b1c3dfeca59fc541.tar.gz
chromium_src-beb3f472cb71a4ba25968a35b1c3dfeca59fc541.tar.bz2
Add a helper, and add the test file that broke the build.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13839 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/cocoa_test_helper.h')
-rw-r--r--chrome/browser/cocoa/cocoa_test_helper.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/cocoa_test_helper.h b/chrome/browser/cocoa/cocoa_test_helper.h
new file mode 100644
index 0000000..54d56b8
--- /dev/null
+++ b/chrome/browser/cocoa/cocoa_test_helper.h
@@ -0,0 +1,58 @@
+// 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.
+
+#ifndef CHROME_BROWSER_COCOA_COCOA_TEST_HELPER
+#define CHROME_BROWSER_COCOA_COCOA_TEST_HELPER
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/file_path.h"
+#include "base/mac_util.h"
+#include "base/path_service.h"
+
+#if defined(GOOGLE_CHROME_BUILD)
+#define APP_NAME "Chrome.app"
+#else
+#define APP_NAME "Chromium.app"
+#endif
+
+// A class that initializes Cocoa and sets up resources for many of our
+// Cocoa controller unit tests. It does several key things:
+// - Creates and displays an empty Cocoa window for views to live in
+// - Loads the appropriate bundle so nib loading works. When loading the
+// nib in the class being tested, your must use |mac_util::MainAppBundle()|
+// as the bundle. If you do not specify a bundle, your test will likely
+// fail.
+// It currently does not create an autorelease pool, though that can easily be
+// added.
+
+class CocoaTestHelper {
+ public:
+ CocoaTestHelper() {
+ // Look in the Chromium app bundle for resources.
+ FilePath path;
+ PathService::Get(base::DIR_EXE, &path);
+ path = path.AppendASCII(APP_NAME);
+ mac_util::SetOverrideAppBundlePath(path);
+
+ // Bootstrap Cocoa. It's very unhappy without this.
+ [NSApplication sharedApplication];
+
+ // Create a window.
+ NSRect frame = NSMakeRect(0, 0, 800, 600);
+ window_.reset([[NSWindow alloc] initWithContentRect:frame
+ styleMask:0
+ backing:NSBackingStoreBuffered
+ defer:NO]);
+ [window_ orderFront:nil];
+ }
+
+ // Access the Cocoa window created for the test.
+ NSWindow* window() const { return window_.get(); }
+
+ private:
+ scoped_nsobject<NSWindow> window_;
+};
+
+#endif // CHROME_BROWSER_COCOA_COCOA_TEST_HELPER