summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-17 20:43:24 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-17 20:43:24 +0000
commita05d223dccc3f04067f0a12f8b6b8f60a4dd8290 (patch)
treec7b1cfe39309fb1b62eba750126d2d2c9a27314c /chrome/browser/cocoa
parentbb1d3cabef77556677416988c9293a3b72d9c7cf (diff)
downloadchromium_src-a05d223dccc3f04067f0a12f8b6b8f60a4dd8290.zip
chromium_src-a05d223dccc3f04067f0a12f8b6b8f60a4dd8290.tar.gz
chromium_src-a05d223dccc3f04067f0a12f8b6b8f60a4dd8290.tar.bz2
Fix a few pasteboard-related things in the Mac unit_tests. Most of these
changes are non-functional or minimally functional. There are a couple of functional changes in here too. Hopefully this will resolve some of the Valgrind failures. BUG=21479 TEST=unit_tests Review URL: http://codereview.chromium.org/210006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26479 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm20
-rw-r--r--chrome/browser/cocoa/bookmark_editor_controller_unittest.mm1
-rw-r--r--chrome/browser/cocoa/browser_test_helper.h27
-rw-r--r--chrome/browser/cocoa/cocoa_test_helper.h10
-rw-r--r--chrome/browser/cocoa/download_util_mac_unittest.mm25
5 files changed, 41 insertions, 42 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
index 7e33bc1..d09eb84 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
@@ -20,6 +20,7 @@
@end
namespace {
+
int NumTypesOnPasteboard(NSPasteboard* pb) {
return [[pb types] count];
}
@@ -41,22 +42,16 @@ bool ClipboardContainsText(NSPasteboard* pb, NSString* cmp) {
class AutocompleteTextFieldEditorTest : public PlatformTest {
public:
- AutocompleteTextFieldEditorTest() {
+ AutocompleteTextFieldEditorTest()
+ : pb_([NSPasteboard pasteboardWithUniqueName]) {
NSRect frame = NSMakeRect(0, 0, 50, 30);
editor_.reset([[AutocompleteTextFieldEditor alloc] initWithFrame:frame]);
[editor_ setString:@"Testing"];
[cocoa_helper_.contentView() addSubview:editor_.get()];
}
- virtual void SetUp() {
- PlatformTest::SetUp();
- pb_ = [NSPasteboard pasteboardWithUniqueName];
- }
-
- virtual void TearDown() {
+ virtual ~AutocompleteTextFieldEditorTest() {
[pb_ releaseGlobally];
- pb_ = nil;
- PlatformTest::TearDown();
}
NSPasteboard *clipboard() {
@@ -87,8 +82,7 @@ TEST_F(AutocompleteTextFieldEditorTest, CutCopyTest) {
ASSERT_TRUE(NoRichTextOnClipboard(clipboard()));
// Check that copying it works and we only get plain text.
- NSPasteboard* pb = clipboard();
- [editor_.get() performCopy:pb];
+ [editor_.get() performCopy:clipboard()];
ASSERT_TRUE(NoRichTextOnClipboard(clipboard()));
ASSERT_TRUE(ClipboardContainsText(clipboard(), test_string_1));
@@ -96,7 +90,7 @@ TEST_F(AutocompleteTextFieldEditorTest, CutCopyTest) {
[editor_.get() setString:test_string_2];
[editor_.get() selectAll:nil];
[editor_.get() alignLeft:nil]; // Add a rich text attribute.
- [editor_.get() performCut:pb];
+ [editor_.get() performCut:clipboard()];
ASSERT_TRUE(NoRichTextOnClipboard(clipboard()));
ASSERT_TRUE(ClipboardContainsText(clipboard(), test_string_2));
ASSERT_EQ([[editor_.get() textStorage] length], 0U);
@@ -137,7 +131,7 @@ TEST_F(AutocompleteTextFieldEditorTest, TextShouldPaste) {
EXPECT_TRUE([shouldNotPaste receivedTextShouldPaste]);
}
-} // namespace
+} // namespace
@implementation AutocompleteTextFieldEditorTestDelegate
diff --git a/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm b/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm
index 01c969f..947095e 100644
--- a/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm
+++ b/chrome/browser/cocoa/bookmark_editor_controller_unittest.mm
@@ -15,7 +15,6 @@ class BookmarkEditorControllerTest : public PlatformTest {
public:
CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
BrowserTestHelper helper_;
- scoped_nsobject<BookmarkEditorController> bar_;
};
TEST_F(BookmarkEditorControllerTest, NoNodeNoTree) {
diff --git a/chrome/browser/cocoa/browser_test_helper.h b/chrome/browser/cocoa/browser_test_helper.h
index 19ce3b5..bf3ffa7 100644
--- a/chrome/browser/cocoa/browser_test_helper.h
+++ b/chrome/browser/cocoa/browser_test_helper.h
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#ifndef CHROME_BROWSER_COCOA_BROWSER_TEST_HELPER_H_
+#define CHROME_BROWSER_COCOA_BROWSER_TEST_HELPER_H_
+
#include "chrome/browser/browser.h"
#include "chrome/browser/profile.h"
#include "chrome/test/testing_profile.h"
@@ -16,23 +19,19 @@
class BrowserTestHelper {
public:
BrowserTestHelper() {
- TestingProfile *testing_profile = new TestingProfile();
- testing_profile->CreateBookmarkModel(true);
- testing_profile->BlockUntilBookmarkModelLoaded();
- profile_ = testing_profile;
- browser_ = new Browser(Browser::TYPE_NORMAL, profile_);
- }
-
- ~BrowserTestHelper() {
- delete browser_;
- delete profile_;
+ profile_.reset(new TestingProfile());
+ profile_->CreateBookmarkModel(true);
+ profile_->BlockUntilBookmarkModelLoaded();
+ browser_.reset(new Browser(Browser::TYPE_NORMAL, profile_.get()));
}
- Browser* browser() { return browser_; }
- Profile* profile() { return profile_; }
+ TestingProfile* profile() const { return profile_.get(); }
+ Browser* browser() const { return browser_.get(); }
private:
- Browser* browser_;
- Profile* profile_;
+ scoped_ptr<TestingProfile> profile_;
+ scoped_ptr<Browser> browser_;
MessageLoopForUI message_loop_;
};
+
+#endif // CHROME_BROWSER_COCOA_BROWSER_TEST_HELPER_H_
diff --git a/chrome/browser/cocoa/cocoa_test_helper.h b/chrome/browser/cocoa/cocoa_test_helper.h
index 7fdcb45..282db9c 100644
--- a/chrome/browser/cocoa/cocoa_test_helper.h
+++ b/chrome/browser/cocoa/cocoa_test_helper.h
@@ -2,8 +2,8 @@
// 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
+#ifndef CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_
+#define CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_
#import <Cocoa/Cocoa.h>
@@ -23,7 +23,7 @@
BOOL pretendIsKeyWindow_;
}
-// Init a borderless non-defered window with backing store.
+// Init a borderless non-deferred window with a backing store.
- (id)initWithContentRect:(NSRect)contentRect;
// Init with a default frame.
@@ -44,7 +44,7 @@
// 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. If your test wants one, it can derrive from PlatformTest instead of
+// added. If your test wants one, it can derive from PlatformTest instead of
// testing::Test.
class CocoaTestHelper {
@@ -93,4 +93,4 @@ class CocoaTestHelper {
scoped_nsobject<CocoaTestHelperWindow> window_;
};
-#endif // CHROME_BROWSER_COCOA_COCOA_TEST_HELPER
+#endif // CHROME_BROWSER_COCOA_COCOA_TEST_HELPER_H_
diff --git a/chrome/browser/cocoa/download_util_mac_unittest.mm b/chrome/browser/cocoa/download_util_mac_unittest.mm
index 0f61704..8d1939c 100644
--- a/chrome/browser/cocoa/download_util_mac_unittest.mm
+++ b/chrome/browser/cocoa/download_util_mac_unittest.mm
@@ -1,7 +1,7 @@
// 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.
-//
+
// Download utility test for Mac OS X.
#include "base/path_service.h"
@@ -16,14 +16,23 @@ namespace {
class DownloadUtilTest : public PlatformTest {
public:
+ DownloadUtilTest() {
+ pasteboard_ = [NSPasteboard pasteboardWithUniqueName];
+ }
+
+ virtual ~DownloadUtilTest() {
+ [pasteboard_ releaseGlobally];
+ }
+
+ const NSPasteboard* const pasteboard() { return pasteboard_; }
+
+ private:
CocoaTestHelper cocoa_helper_;
+ NSPasteboard* pasteboard_;
};
// Ensure adding files to the pasteboard methods works as expected.
TEST_F(DownloadUtilTest, AddFileToPasteboardTest) {
- // Create a pasteboard.
- NSPasteboard* pasteboard = [NSPasteboard pasteboardWithUniqueName];
-
// Get a download test file for addition to the pasteboard.
FilePath testPath;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &testPath));
@@ -31,21 +40,19 @@ TEST_F(DownloadUtilTest, AddFileToPasteboardTest) {
testPath = testPath.Append(testFile);
// Add a test file to the pasteboard via the download_util method.
- download_util::AddFileToPasteboard(pasteboard, testPath);
+ download_util::AddFileToPasteboard(pasteboard(), testPath);
// Test to see that the object type for dragging files is available.
NSArray* types = [NSArray arrayWithObject:NSFilenamesPboardType];
- NSString* available = [pasteboard availableTypeFromArray:types];
+ NSString* available = [pasteboard() availableTypeFromArray:types];
EXPECT_TRUE(available != nil);
// Ensure the path is what we expect.
- NSArray* files = [pasteboard propertyListForType:NSFilenamesPboardType];
+ NSArray* files = [pasteboard() propertyListForType:NSFilenamesPboardType];
ASSERT_TRUE(files != nil);
NSString* expectedPath = [files objectAtIndex:0];
NSString* realPath = base::SysWideToNSString(testPath.ToWStringHack());
EXPECT_TRUE([expectedPath isEqualToString:realPath]);
-
- [pasteboard releaseGlobally];
}
} // namespace