| 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..daeb4a7c112f77d92034f4d965172fa91e9534f8 100644
|
| --- a/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm
|
| +++ b/chrome/browser/ui/cocoa/web_intent_bubble_controller_unittest.mm
|
| @@ -2,26 +2,26 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "base/basictypes.h"
|
| #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
|
| #import "chrome/browser/ui/cocoa/hyperlink_button_cell.h"
|
| #import "chrome/browser/ui/cocoa/info_bubble_window.h"
|
| #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 +30,29 @@ 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];
|
| + // Closing |controller_| destroys |picker_|.
|
| + ignore_result(picker_.release());
|
| + }
|
| 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 +117,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 +137,23 @@ TEST_F(WebIntentBubbleControllerTest, PopulatedBubble) {
|
|
|
| CheckWindow(/*icon_count=*/2);
|
| }
|
| +
|
| +TEST_F(WebIntentBubbleControllerTest, OnCancelledWillSignalClose) {
|
| + CreatePicker();
|
| +
|
| + EXPECT_CALL(delegate_,OnCancelled());
|
| + EXPECT_CALL(delegate_,OnClosing());
|
| + picker_->OnCancelled();
|
| +
|
| + ignore_result(picker_.release()); // Closing |picker_| will self-destruct it.
|
| +}
|
| +
|
| +TEST_F(WebIntentBubbleControllerTest, CloseWillClose) {
|
| + CreateBubble();
|
| +
|
| + EXPECT_CALL(delegate_,OnCancelled());
|
| + EXPECT_CALL(delegate_,OnClosing());
|
| + picker_->Close();
|
| +
|
| + ignore_result(picker_.release()); // Closing |picker_| will self-destruct it.
|
| +}
|
|
|