| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_COCOA_COCOA_TEST_HELPER | |
| 6 #define CHROME_BROWSER_COCOA_COCOA_TEST_HELPER | |
| 7 | |
| 8 #import <Cocoa/Cocoa.h> | |
| 9 | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/mac_util.h" | |
| 12 #include "base/path_service.h" | |
| 13 | |
| 14 #if defined(GOOGLE_CHROME_BUILD) | |
| 15 #define APP_NAME "Chrome.app" | |
| 16 #else | |
| 17 #define APP_NAME "Chromium.app" | |
| 18 #endif | |
| 19 | |
| 20 // A class that initializes Cocoa and sets up resources for many of our | |
| 21 // Cocoa controller unit tests. It does several key things: | |
| 22 // - Creates and displays an empty Cocoa window for views to live in | |
| 23 // - Loads the appropriate bundle so nib loading works. When loading the | |
| 24 // nib in the class being tested, your must use |mac_util::MainAppBundle()| | |
| 25 // as the bundle. If you do not specify a bundle, your test will likely | |
| 26 // fail. | |
| 27 // It currently does not create an autorelease pool, though that can easily be | |
| 28 // added. | |
| 29 | |
| 30 class CocoaTestHelper { | |
| 31 public: | |
| 32 CocoaTestHelper() { | |
| 33 // Look in the Chromium app bundle for resources. | |
| 34 FilePath path; | |
| 35 PathService::Get(base::DIR_EXE, &path); | |
| 36 path = path.AppendASCII(APP_NAME); | |
| 37 mac_util::SetOverrideAppBundlePath(path); | |
| 38 | |
| 39 // Bootstrap Cocoa. It's very unhappy without this. | |
| 40 [NSApplication sharedApplication]; | |
| 41 | |
| 42 // Create a window. | |
| 43 NSRect frame = NSMakeRect(0, 0, 800, 600); | |
| 44 window_.reset([[NSWindow alloc] initWithContentRect:frame | |
| 45 styleMask:0 | |
| 46 backing:NSBackingStoreBuffered | |
| 47 defer:NO]); | |
| 48 [window_ orderFront:nil]; | |
| 49 } | |
| 50 | |
| 51 // Access the Cocoa window created for the test. | |
| 52 NSWindow* window() const { return window_.get(); } | |
| 53 | |
| 54 private: | |
| 55 scoped_nsobject<NSWindow> window_; | |
| 56 }; | |
| 57 | |
| 58 #endif // CHROME_BROWSER_COCOA_COCOA_TEST_HELPER | |
| OLD | NEW |