Chromium Code Reviews| Index: chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm |
| diff --git a/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm |
| index 4cb514605daa094022859480360b8487bc09f761..f3fe2bdd6f3e9eac3bca1050636afd325b641c56 100644 |
| --- a/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm |
| +++ b/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm |
| @@ -8,20 +8,19 @@ |
| #import "chrome/browser/ui/cocoa/web_intent_bubble_controller.h" |
| #include "chrome/browser/ui/cocoa/web_intent_picker_cocoa.h" |
| #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| namespace { |
| -class FakeIntentPickerDelegate : public WebIntentPickerDelegate { |
| +class MockIntentPickerDelegate : public WebIntentPickerDelegate { |
| public: |
| - virtual ~FakeIntentPickerDelegate() {} |
| - virtual void OnServiceChosen( |
| - size_t index, Disposition disposition) OVERRIDE {}; |
| - virtual void OnInlineDispositionWebContentsCreated( |
| - content::WebContents* web_contents) OVERRIDE {} |
| - |
| - // Callback called when the user cancels out of the dialog. |
| - virtual void OnCancelled() OVERRIDE {}; |
| - virtual void OnClosing() OVERRIDE {}; |
| + virtual ~MockIntentPickerDelegate() {} |
| + |
| + MOCK_METHOD2(OnServiceChosen,void(size_t index, Disposition disposition)); |
| + MOCK_METHOD1(OnInlineDispositionWebContentsCreated, |
| + void(content::WebContents* web_contents)); |
| + MOCK_METHOD0(OnCancelled,void()); |
| + MOCK_METHOD0(OnClosing,void()); |
| }; |
| } // namespace |
| @@ -30,14 +29,28 @@ class WebIntentBubbleControllerTest : public CocoaTest { |
| public: |
| virtual void TearDown() { |
| // Do not animate out because that is hard to test around. |
| - [window_ setDelayOnClose:NO]; |
| - [controller_ close]; |
| + if (window_) |
| + [window_ setDelayOnClose:NO]; |
| + |
| + if (picker_.get()) { |
| + EXPECT_CALL(delegate_,OnCancelled()); |
| + EXPECT_CALL(delegate_,OnClosing()); |
| + |
| + [controller_ close]; |
| + (void)picker_.release(); // Closing |controller_| will destroy |picker_| |
|
Robert Sesek
2012/02/03 23:26:51
nit: Comments end with a .
groby-ooo-7-16
2012/02/04 01:57:43
Done.
|
| + } |
| CocoaTest::TearDown(); |
| } |
| - void CreateBubble() { |
| + void CreatePicker() { |
| picker_.reset(new WebIntentPickerCocoa()); |
| picker_->delegate_ = &delegate_; |
| + window_ = nil; |
| + controller_ = nil; |
| + } |
| + |
| + void CreateBubble() { |
| + CreatePicker(); |
| NSPoint anchor=NSMakePoint(0,0); |
| controller_ = |
| @@ -102,7 +115,7 @@ class WebIntentBubbleControllerTest : public CocoaTest { |
| WebIntentBubbleController* controller_; // Weak, owns self. |
| InfoBubbleWindow* window_; // Weak, owned by controller. |
| scoped_ptr<WebIntentPickerCocoa> picker_; |
| - FakeIntentPickerDelegate delegate_; |
| + MockIntentPickerDelegate delegate_; |
| }; |
| TEST_F(WebIntentBubbleControllerTest, EmptyBubble) { |
| @@ -122,3 +135,23 @@ TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) { |
| CheckWindow(/*icon_count=*/2); |
| } |
| + |
| +TEST_F(WebIntentBubbleControllerTest, OnCancelledWillSignalClose) { |
| + CreatePicker(); |
| + |
| + EXPECT_CALL(delegate_,OnCancelled()); |
| + EXPECT_CALL(delegate_,OnClosing()); |
| + picker_->OnCancelled(); |
| + |
| + (void)picker_.release(); // Closing |picker_| will self-destruct it. |
|
Robert Sesek
2012/02/03 23:26:51
ignore_result() in base/basictypes.h.
groby-ooo-7-16
2012/02/04 01:57:43
Done.
|
| +} |
| + |
| +TEST_F(WebIntentBubbleControllerTest, CloseWillClose) { |
| + CreateBubble(); |
| + |
| + EXPECT_CALL(delegate_,OnCancelled()); |
| + EXPECT_CALL(delegate_,OnClosing()); |
| + picker_->Close(); |
| + |
| + (void)picker_.release(); // Closing |picker_| will self-destruct it. |
| +} |