Chromium Code Reviews| Index: chrome/browser/ui/cocoa/confirm_bubble_controller_unittest.mm |
| =================================================================== |
| --- chrome/browser/ui/cocoa/confirm_bubble_controller_unittest.mm (revision 122469) |
| +++ chrome/browser/ui/cocoa/confirm_bubble_controller_unittest.mm (working copy) |
| @@ -22,6 +22,10 @@ |
| // updates its status when ConfirmBubbleController calls its methods. |
| class TestConfirmBubbleModel : public ConfirmBubbleModel { |
| public: |
| + TestConfirmBubbleModel(bool* model_deleted, |
| + bool* accept_clicked, |
| + bool* cancel_clicked, |
| + bool* link_clicked); |
| TestConfirmBubbleModel(); |
| virtual ~TestConfirmBubbleModel() OVERRIDE; |
| virtual string16 GetTitle() const OVERRIDE; |
| @@ -34,23 +38,25 @@ |
| virtual string16 GetLinkText() const OVERRIDE; |
| virtual void LinkClicked() OVERRIDE; |
| - bool accept_clicked() const { return accept_clicked_; } |
| - bool cancel_clicked() const { return cancel_clicked_; } |
| - bool link_clicked() const { return link_clicked_; } |
| - |
| private: |
| - bool accept_clicked_; |
| - bool cancel_clicked_; |
| - bool link_clicked_; |
| + bool* model_deleted_; |
| + bool* accept_clicked_; |
| + bool* cancel_clicked_; |
| + bool* link_clicked_; |
| }; |
| -TestConfirmBubbleModel::TestConfirmBubbleModel() : |
| - accept_clicked_(false), |
| - cancel_clicked_(false), |
| - link_clicked_(false) { |
| +TestConfirmBubbleModel::TestConfirmBubbleModel(bool* model_deleted, |
| + bool* accept_clicked, |
| + bool* cancel_clicked, |
| + bool* link_clicked) |
| + : model_deleted_(model_deleted), |
| + accept_clicked_(accept_clicked), |
| + cancel_clicked_(cancel_clicked), |
| + link_clicked_(link_clicked) { |
| } |
| TestConfirmBubbleModel::~TestConfirmBubbleModel() { |
| + *model_deleted_ = true; |
| } |
| string16 TestConfirmBubbleModel::GetTitle() const { |
| @@ -75,11 +81,11 @@ |
| } |
| void TestConfirmBubbleModel::Accept() { |
| - accept_clicked_ = true; |
| + *accept_clicked_ = true; |
| } |
| void TestConfirmBubbleModel::Cancel() { |
| - cancel_clicked_ = true; |
| + *cancel_clicked_ = true; |
| } |
| string16 TestConfirmBubbleModel::GetLinkText() const { |
| @@ -87,7 +93,7 @@ |
| } |
| void TestConfirmBubbleModel::LinkClicked() { |
| - link_clicked_ = true; |
| + *link_clicked_ = true; |
| } |
| } // namespace |
| @@ -96,12 +102,15 @@ |
| public: |
| ConfirmBubbleControllerTest() { |
| NSView* view = [test_window() contentView]; |
| - model_.reset(new TestConfirmBubbleModel); |
| + model_ = new TestConfirmBubbleModel(&model_deleted_, |
|
Robert Sesek
2012/02/17 15:24:25
Comment: // Owned by the controller.
Hironori Bono
2012/02/22 07:22:50
Done.
|
| + &accept_clicked_, |
| + &cancel_clicked_, |
| + &link_clicked_); |
| gfx::Point origin(0, 0); |
| controller_ = |
| [[ConfirmBubbleController alloc] initWithParent:view |
| origin:origin.ToCGPoint() |
| - model:model_.get()]; |
| + model:model_]; |
| [view addSubview:[controller_ view] |
| positioned:NSWindowAbove |
| relativeTo:nil]; |
| @@ -111,13 +120,19 @@ |
| return (ConfirmBubbleView*)[controller_ view]; |
| } |
| - TestConfirmBubbleModel* model() const { |
| - return model_.get(); |
| - } |
| + TestConfirmBubbleModel* model() const { return model_; } |
| + bool model_deleted() const { return model_deleted_; } |
| + bool accept_clicked() const { return accept_clicked_; } |
| + bool cancel_clicked() const { return cancel_clicked_; } |
| + bool link_clicked() const { return link_clicked_; } |
| private: |
| ConfirmBubbleController* controller_; // weak; owns self |
| - scoped_ptr<TestConfirmBubbleModel> model_; |
| + TestConfirmBubbleModel* model_; // weak |
| + bool model_deleted_; |
| + bool accept_clicked_; |
| + bool cancel_clicked_; |
| + bool link_clicked_; |
| }; |
| // Verify clicking a button or a link removes the ConfirmBubbleView object and |
| @@ -134,9 +149,10 @@ |
| contains_bubble_view = [[view subviews] containsObject:bubble_view]; |
| EXPECT_FALSE(contains_bubble_view); |
| - EXPECT_TRUE(model()->accept_clicked()); |
| - EXPECT_FALSE(model()->cancel_clicked()); |
| - EXPECT_FALSE(model()->link_clicked()); |
| + EXPECT_TRUE(model_deleted()); |
| + EXPECT_TRUE(accept_clicked()); |
| + EXPECT_FALSE(cancel_clicked()); |
| + EXPECT_FALSE(link_clicked()); |
| } |
| TEST_F(ConfirmBubbleControllerTest, ClickCancel) { |
| @@ -151,9 +167,10 @@ |
| contains_bubble_view = [[view subviews] containsObject:bubble_view]; |
| EXPECT_FALSE(contains_bubble_view); |
| - EXPECT_FALSE(model()->accept_clicked()); |
| - EXPECT_TRUE(model()->cancel_clicked()); |
| - EXPECT_FALSE(model()->link_clicked()); |
| + EXPECT_TRUE(model_deleted()); |
| + EXPECT_FALSE(accept_clicked()); |
| + EXPECT_TRUE(cancel_clicked()); |
| + EXPECT_FALSE(link_clicked()); |
| } |
| TEST_F(ConfirmBubbleControllerTest, ClickLink) { |
| @@ -168,7 +185,8 @@ |
| contains_bubble_view = [[view subviews] containsObject:bubble_view]; |
| EXPECT_FALSE(contains_bubble_view); |
| - EXPECT_FALSE(model()->accept_clicked()); |
| - EXPECT_FALSE(model()->cancel_clicked()); |
| - EXPECT_TRUE(model()->link_clicked()); |
| + EXPECT_TRUE(model_deleted()); |
| + EXPECT_FALSE(accept_clicked()); |
| + EXPECT_FALSE(cancel_clicked()); |
| + EXPECT_TRUE(link_clicked()); |
| } |