| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/scoped_nsobject.h" | 5 #include "base/scoped_nsobject.h" |
| 6 #include "chrome/browser/cocoa/browser_test_helper.h" | 6 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 7 #include "chrome/browser/cocoa/cocoa_test_helper.h" | 7 #include "chrome/browser/cocoa/cocoa_test_helper.h" |
| 8 #include "chrome/browser/cocoa/notifications/balloon_controller.h" | 8 #include "chrome/browser/cocoa/notifications/balloon_controller.h" |
| 9 #include "chrome/browser/notifications/balloon.h" | 9 #include "chrome/browser/notifications/balloon.h" |
| 10 #include "chrome/browser/notifications/balloon_collection.h" | 10 #include "chrome/browser/notifications/balloon_collection.h" |
| 11 #include "chrome/browser/notifications/notification.h" | 11 #include "chrome/browser/notifications/notification.h" |
| 12 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 12 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 13 #include "chrome/test/testing_profile.h" | 13 #include "chrome/test/testing_profile.h" |
| 14 #import "third_party/ocmock/OCMock/OCMock.h" | 14 #import "third_party/ocmock/OCMock/OCMock.h" |
| 15 | 15 |
| 16 // Subclass balloon controller and mock out the initialization of the RVH. |
| 17 @interface TestBalloonController : BalloonController { |
| 18 } |
| 19 - (void)initializeHost; |
| 20 @end |
| 21 |
| 22 @implementation TestBalloonController |
| 23 - (void)initializeHost {} |
| 24 @end |
| 25 |
| 16 namespace { | 26 namespace { |
| 17 | 27 |
| 18 // Use a dummy balloon collection for testing. | 28 // Use a dummy balloon collection for testing. |
| 19 class MockBalloonCollection : public BalloonCollection { | 29 class MockBalloonCollection : public BalloonCollection { |
| 20 virtual void Add(const Notification& notification, | 30 virtual void Add(const Notification& notification, |
| 21 Profile* profile) {} | 31 Profile* profile) {} |
| 22 virtual bool Remove(const Notification& notification) { return false; } | 32 virtual bool Remove(const Notification& notification) { return false; } |
| 23 virtual bool HasSpace() const { return true; } | 33 virtual bool HasSpace() const { return true; } |
| 24 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) {}; | 34 virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) {}; |
| 25 virtual void DisplayChanged() {} | 35 virtual void DisplayChanged() {} |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 scoped_ptr<Browser> browser_; | 70 scoped_ptr<Browser> browser_; |
| 61 scoped_ptr<BalloonCollection> collection_; | 71 scoped_ptr<BalloonCollection> collection_; |
| 62 }; | 72 }; |
| 63 | 73 |
| 64 TEST_F(BalloonControllerTest, ShowAndCloseTest) { | 74 TEST_F(BalloonControllerTest, ShowAndCloseTest) { |
| 65 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), | 75 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), |
| 66 L"http://www.google.com", ASCIIToUTF16(""), | 76 L"http://www.google.com", ASCIIToUTF16(""), |
| 67 new NotificationObjectProxy(-1, -1, -1, false)); | 77 new NotificationObjectProxy(-1, -1, -1, false)); |
| 68 scoped_ptr<Balloon> balloon( | 78 scoped_ptr<Balloon> balloon( |
| 69 new Balloon(n, profile_.get(), collection_.get())); | 79 new Balloon(n, profile_.get(), collection_.get())); |
| 80 balloon->SetPosition(gfx::Point(1, 1), false); |
| 81 balloon->set_content_size(gfx::Size(100, 100)); |
| 70 | 82 |
| 71 BalloonController* controller = [BalloonController alloc]; | 83 BalloonController* controller = |
| 84 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; |
| 72 | 85 |
| 73 id mock = [OCMockObject partialMockForObject:controller]; | |
| 74 [[mock expect] initializeHost]; | |
| 75 | |
| 76 [controller initWithBalloon:balloon.get()]; | |
| 77 [controller showWindow:nil]; | 86 [controller showWindow:nil]; |
| 78 [controller closeBalloon:YES]; | 87 [controller closeBalloon:YES]; |
| 79 | |
| 80 [mock verify]; | |
| 81 [controller release]; | |
| 82 } | 88 } |
| 83 | 89 |
| 84 TEST_F(BalloonControllerTest, SizesTest) { | 90 TEST_F(BalloonControllerTest, SizesTest) { |
| 85 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), | 91 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), |
| 86 L"http://www.google.com", ASCIIToUTF16(""), | 92 L"http://www.google.com", ASCIIToUTF16(""), |
| 87 new NotificationObjectProxy(-1, -1, -1, false)); | 93 new NotificationObjectProxy(-1, -1, -1, false)); |
| 88 scoped_ptr<Balloon> balloon( | 94 scoped_ptr<Balloon> balloon( |
| 89 new Balloon(n, profile_.get(), collection_.get())); | 95 new Balloon(n, profile_.get(), collection_.get())); |
| 96 balloon->SetPosition(gfx::Point(1, 1), false); |
| 90 balloon->set_content_size(gfx::Size(100, 100)); | 97 balloon->set_content_size(gfx::Size(100, 100)); |
| 91 | 98 |
| 92 BalloonController* controller = [BalloonController alloc]; | 99 BalloonController* controller = |
| 93 | 100 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; |
| 94 id mock = [OCMockObject partialMockForObject:controller]; | |
| 95 [[mock expect] initializeHost]; | |
| 96 | 101 |
| 97 [controller initWithBalloon:balloon.get()]; | 102 [controller initWithBalloon:balloon.get()]; |
| 103 [controller showWindow:nil]; |
| 98 | 104 |
| 99 EXPECT_TRUE([controller desiredTotalWidth] > 100); | 105 EXPECT_TRUE([controller desiredTotalWidth] > 100); |
| 100 EXPECT_TRUE([controller desiredTotalHeight] > 100); | 106 EXPECT_TRUE([controller desiredTotalHeight] > 100); |
| 101 [mock verify]; | 107 |
| 102 [controller release]; | 108 [controller closeBalloon:YES]; |
| 103 } | 109 } |
| 104 | 110 |
| 105 } | 111 } |
| OLD | NEW |