summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 22:28:31 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-21 22:28:31 +0000
commitee8a362d225a9a495154dad3d005f9c4080d5adc (patch)
tree8dba889b6e232172ca7f2bcb4d023448507e2712 /chrome/browser/cocoa
parent255790a7a6c27dc4c00dd43c578fc39e179a6b1f (diff)
downloadchromium_src-ee8a362d225a9a495154dad3d005f9c4080d5adc.zip
chromium_src-ee8a362d225a9a495154dad3d005f9c4080d5adc.tar.gz
chromium_src-ee8a362d225a9a495154dad3d005f9c4080d5adc.tar.bz2
[Mac] Use gmock rather than manual mock for autocomplete tests.
Review URL: http://codereview.chromium.org/209053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26753 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm9
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_unittest.mm28
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h26
3 files changed, 23 insertions, 40 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
index 6d42964..bdb4962 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor_unittest.mm
@@ -33,6 +33,9 @@ bool ClipboardContainsText(NSPasteboard* pb, NSString* cmp) {
return [clipboard_text isEqualToString:cmp];
}
+// TODO(shess): Very similar to AutocompleteTextFieldTest. Maybe
+// those can be shared.
+
class AutocompleteTextFieldEditorTest : public PlatformTest {
public:
AutocompleteTextFieldEditorTest()
@@ -78,7 +81,7 @@ class AutocompleteTextFieldEditorTest : public PlatformTest {
CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
scoped_nsobject<AutocompleteTextFieldEditor> editor_;
scoped_nsobject<AutocompleteTextField> field_;
- AutocompleteTextFieldObserverMock field_observer_;
+ MockAutocompleteTextFieldObserver field_observer_;
scoped_nsobject<AutocompleteTextFieldWindowTestDelegate> window_delegate_;
private:
@@ -149,10 +152,8 @@ TEST_F(AutocompleteTextFieldEditorTest, Display) {
// Test that -paste: is correctly delegated to the observer.
TEST_F(AutocompleteTextFieldEditorTest, Paste) {
- field_observer_.Reset();
- EXPECT_FALSE(field_observer_.on_paste_called_);
+ EXPECT_CALL(field_observer_, OnPaste());
[editor_.get() paste:nil];
- EXPECT_TRUE(field_observer_.on_paste_called_);
}
} // namespace
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
index 6e8dbfc..52fe284 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
@@ -14,6 +14,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
+using ::testing::InSequence;
+
@interface AutocompleteTextFieldTestDelegate : NSObject {
BOOL receivedControlTextDidBeginEditing_;
BOOL receivedControlTextShouldEndEditing_;
@@ -65,7 +67,7 @@ class AutocompleteTextFieldTest : public PlatformTest {
CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
scoped_nsobject<AutocompleteTextField> field_;
- AutocompleteTextFieldObserverMock field_observer_;
+ MockAutocompleteTextFieldObserver field_observer_;
scoped_nsobject<AutocompleteTextFieldWindowTestDelegate> window_delegate_;
};
@@ -117,19 +119,15 @@ TEST_F(AutocompleteTextFieldTest, Display) {
}
TEST_F(AutocompleteTextFieldTest, FlagsChanged) {
+ InSequence dummy; // Call mock in exactly the order specified.
+
// Test without Control key down, but some other modifier down.
- field_observer_.Reset();
- EXPECT_FALSE(field_observer_.on_control_key_changed_called_);
+ EXPECT_CALL(field_observer_, OnControlKeyChanged(false));
[field_ flagsChanged:KeyDownEventWithFlags(NSShiftKeyMask)];
- EXPECT_TRUE(field_observer_.on_control_key_changed_called_);
- EXPECT_FALSE(field_observer_.on_control_key_changed_value_);
// Test with Control key down.
- field_observer_.Reset();
- EXPECT_FALSE(field_observer_.on_control_key_changed_called_);
+ EXPECT_CALL(field_observer_, OnControlKeyChanged(true));
[field_ flagsChanged:KeyDownEventWithFlags(NSControlKeyMask)];
- EXPECT_TRUE(field_observer_.on_control_key_changed_called_);
- EXPECT_TRUE(field_observer_.on_control_key_changed_value_);
}
// This test is here rather than in the editor's tests because the
@@ -140,19 +138,15 @@ TEST_F(AutocompleteTextFieldTest, FieldEditorFlagsChanged) {
NSResponder* firstResponder = [[field_ window] firstResponder];
EXPECT_EQ(firstResponder, [field_ currentEditor]);
+ InSequence dummy; // Call mock in exactly the order specified.
+
// Test without Control key down, but some other modifier down.
- field_observer_.Reset();
- EXPECT_FALSE(field_observer_.on_control_key_changed_called_);
+ EXPECT_CALL(field_observer_, OnControlKeyChanged(false));
[firstResponder flagsChanged:KeyDownEventWithFlags(NSShiftKeyMask)];
- EXPECT_TRUE(field_observer_.on_control_key_changed_called_);
- EXPECT_FALSE(field_observer_.on_control_key_changed_value_);
// Test with Control key down.
- field_observer_.Reset();
- EXPECT_FALSE(field_observer_.on_control_key_changed_called_);
+ EXPECT_CALL(field_observer_, OnControlKeyChanged(true));
[firstResponder flagsChanged:KeyDownEventWithFlags(NSControlKeyMask)];
- EXPECT_TRUE(field_observer_.on_control_key_changed_called_);
- EXPECT_TRUE(field_observer_.on_control_key_changed_value_);
}
// Test that the field editor is reset correctly when search keyword
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h b/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h
index ae5cb1c..378cc00 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h
@@ -9,6 +9,7 @@
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/autocomplete_text_field.h"
+#include "testing/gmock/include/gmock/gmock.h"
@class AutocompleteTextFieldEditor;
@@ -23,27 +24,14 @@
namespace {
// Allow monitoring calls into AutocompleteTextField's observer.
+// Being in a .h file with an anonymous namespace is strange, but this
+// is here so the mock interface doesn't have to change in multiple
+// places.
-class AutocompleteTextFieldObserverMock : public AutocompleteTextFieldObserver {
+class MockAutocompleteTextFieldObserver : public AutocompleteTextFieldObserver {
public:
- virtual void OnControlKeyChanged(bool pressed) {
- on_control_key_changed_called_ = true;
- on_control_key_changed_value_ = pressed;
- }
-
- virtual void OnPaste() {
- on_paste_called_ = true;
- }
-
- void Reset() {
- on_control_key_changed_called_ = false;
- on_control_key_changed_value_ = false;
- on_paste_called_ = false;
- }
-
- bool on_control_key_changed_called_;
- bool on_control_key_changed_value_;
- bool on_paste_called_;
+ MOCK_METHOD1(OnControlKeyChanged, void(bool pressed));
+ MOCK_METHOD0(OnPaste, void());
};
} // namespace