Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2223)

Unified Diff: chrome/browser/cocoa/keyword_editor_cocoa_controller_unittest.mm

Issue 402066: Moved a whole pile of unittests over to CocoaTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/keyword_editor_cocoa_controller_unittest.mm
===================================================================
--- chrome/browser/cocoa/keyword_editor_cocoa_controller_unittest.mm (revision 32421)
+++ chrome/browser/cocoa/keyword_editor_cocoa_controller_unittest.mm (working copy)
@@ -14,34 +14,49 @@
@interface FakeKeywordEditorController : KeywordEditorCocoaController {
@public
- BOOL changed_;
+ BOOL modelChanged_;
}
+- (void)modelChanged;
+- (BOOL)hasModelChanged;
- (KeywordEditorModelObserver*)observer;
@end
@implementation FakeKeywordEditorController
+
- (void)modelChanged {
- changed_ = YES;
+ modelChanged_ = YES;
}
+
+- (BOOL)hasModelChanged {
+ return modelChanged_;
+}
+
- (KeywordEditorModelObserver*)observer {
return observer_.get();
}
+
@end
// TODO(rsesek): Figure out a good way to test this class (crbug.com/21640).
namespace {
-class KeywordEditorCocoaControllerTest : public PlatformTest {
+class KeywordEditorCocoaControllerTest : public CocoaTest {
public:
- void SetUp() {
+ virtual void SetUp() {
+ CocoaTest::SetUp();
TestingProfile* profile =
static_cast<TestingProfile*>(browser_helper_.profile());
profile->CreateTemplateURLModel();
- controller_.reset(
- [[FakeKeywordEditorController alloc] initWithProfile:profile]);
+
+ controller_ = [[FakeKeywordEditorController alloc] initWithProfile:profile];
}
+ virtual void TearDown() {
+ [controller_ close];
+ CocoaTest::TearDown();
+ }
+
// Helper to count the keyword editors.
NSUInteger CountKeywordEditors() {
base::ScopedNSAutoreleasePool pool;
@@ -55,58 +70,17 @@
return count;
}
- CocoaTestHelper cocoa_helper_;
BrowserTestHelper browser_helper_;
- scoped_nsobject<FakeKeywordEditorController> controller_;
+ FakeKeywordEditorController* controller_;
};
TEST_F(KeywordEditorCocoaControllerTest, TestModelChanged) {
- EXPECT_FALSE(controller_.get()->changed_);
+ EXPECT_FALSE([controller_ hasModelChanged]);
KeywordEditorModelObserver* observer = [controller_ observer];
observer->OnTemplateURLModelChanged();
- EXPECT_TRUE(controller_.get()->changed_);
+ EXPECT_TRUE([controller_ hasModelChanged]);
}
-// Test that the window shows correctly, and the controller is
-// released correctly.
-TEST_F(KeywordEditorCocoaControllerTest, ShowAndCloseWindow) {
- // |controller_| is the only reference.
- EXPECT_EQ([controller_.get() retainCount], 1U);
-
- // TODO(shess): This test verifies that it leaks no windows. Work
- // to push this expectation up into the unit testing framework.
-
- const NSUInteger initial_window_count([[NSApp windows] count]);
-
- // Explicit autorelease pool here because [NSApp windows] returns an
- // autorelease immutable NSArray, which otherwise pins the window.
- {
- base::ScopedNSAutoreleasePool pool;
-
- // -showWindow: brings up the window (which retains
- // |controller_|).
- [controller_.get() showWindow:nil];
- EXPECT_EQ([[NSApp windows] count], initial_window_count+1);
-
- // In regular usage, our scoped reference would not exist and
- // |controller_| would manage itself once -showWindow: is called.
- // This means that we need another reference to balance things
- // out.
- [controller_.get() retain];
-
- // Closing the window should leave us with the single reference.
- [controller_.get() close];
- }
-
- // |controller_| still has a handle on the window, drop the last
- // reference so we can check that we didn't leak a window.
- EXPECT_EQ([controller_.get() retainCount], 1U);
- controller_.reset();
-
- // All created windows should be gone.
- EXPECT_EQ([[NSApp windows] count], initial_window_count);
-}
-
// Test that +showKeywordEditor brings up the existing editor and
// creates one if needed.
TEST_F(KeywordEditorCocoaControllerTest, ShowKeywordEditor) {
Property changes on: chrome/browser/cocoa/keyword_editor_cocoa_controller_unittest.mm
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/cocoa/infobar_text_field_unittest.mm ('k') | chrome/browser/cocoa/location_bar_view_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698