| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_nsobject.h" | 5 #include "base/memory/scoped_nsobject.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/notifications/balloon.h" | 7 #include "chrome/browser/notifications/balloon.h" |
| 8 #include "chrome/browser/notifications/balloon_collection.h" | 8 #include "chrome/browser/notifications/balloon_collection.h" |
| 9 #include "chrome/browser/notifications/notification.h" | 9 #include "chrome/browser/notifications/notification.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 11 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 12 #include "chrome/browser/ui/cocoa/notifications/balloon_controller.h" | 12 #include "chrome/browser/ui/cocoa/notifications/balloon_controller.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 14 #include "content/browser/renderer_host/test_render_view_host.h" | |
| 15 | 15 |
| 16 // Subclass balloon controller and mock out the initialization of the RVH. | 16 // Subclass balloon controller and mock out the initialization of the RVH. |
| 17 @interface TestBalloonController : BalloonController { | 17 @interface TestBalloonController : BalloonController { |
| 18 } | 18 } |
| 19 - (void)initializeHost; | 19 - (void)initializeHost; |
| 20 @end | 20 @end |
| 21 | 21 |
| 22 @implementation TestBalloonController | 22 @implementation TestBalloonController |
| 23 - (void)initializeHost {} | 23 - (void)initializeHost {} |
| 24 @end | 24 @end |
| (...skipping 13 matching lines...) Expand all Loading... |
| 38 virtual void SetPositionPreference(PositionPreference preference) {} | 38 virtual void SetPositionPreference(PositionPreference preference) {} |
| 39 virtual void OnBalloonClosed(Balloon* source) {}; | 39 virtual void OnBalloonClosed(Balloon* source) {}; |
| 40 virtual const Balloons& GetActiveBalloons() { | 40 virtual const Balloons& GetActiveBalloons() { |
| 41 NOTREACHED(); | 41 NOTREACHED(); |
| 42 return balloons_; | 42 return balloons_; |
| 43 } | 43 } |
| 44 private: | 44 private: |
| 45 Balloons balloons_; | 45 Balloons balloons_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 class BalloonControllerTest : public RenderViewHostTestHarness { | 48 class BalloonControllerTest : public ChromeRenderViewHostTestHarness { |
| 49 public: | 49 public: |
| 50 BalloonControllerTest() : | 50 BalloonControllerTest() : |
| 51 ui_thread_(BrowserThread::UI, MessageLoop::current()), | 51 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| 52 io_thread_(BrowserThread::IO, MessageLoop::current()) { | 52 io_thread_(BrowserThread::IO, MessageLoop::current()) { |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual void SetUp() { | 55 virtual void SetUp() { |
| 56 RenderViewHostTestHarness::SetUp(); | 56 ChromeRenderViewHostTestHarness::SetUp(); |
| 57 CocoaTest::BootstrapCocoa(); | 57 CocoaTest::BootstrapCocoa(); |
| 58 profile_.reset(new TestingProfile()); | 58 profile()->CreateRequestContext(); |
| 59 profile_->CreateRequestContext(); | 59 browser_.reset(new Browser(Browser::TYPE_TABBED, profile())); |
| 60 browser_.reset(new Browser(Browser::TYPE_TABBED, profile_.get())); | |
| 61 collection_.reset(new MockBalloonCollection()); | 60 collection_.reset(new MockBalloonCollection()); |
| 62 } | 61 } |
| 63 | 62 |
| 64 virtual void TearDown() { | 63 virtual void TearDown() { |
| 65 MessageLoop::current()->RunAllPending(); | 64 MessageLoop::current()->RunAllPending(); |
| 66 RenderViewHostTestHarness::TearDown(); | 65 ChromeRenderViewHostTestHarness::TearDown(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 protected: | 68 protected: |
| 70 BrowserThread ui_thread_; | 69 BrowserThread ui_thread_; |
| 71 BrowserThread io_thread_; | 70 BrowserThread io_thread_; |
| 72 scoped_ptr<TestingProfile> profile_; | |
| 73 scoped_ptr<Browser> browser_; | 71 scoped_ptr<Browser> browser_; |
| 74 scoped_ptr<BalloonCollection> collection_; | 72 scoped_ptr<BalloonCollection> collection_; |
| 75 }; | 73 }; |
| 76 | 74 |
| 77 TEST_F(BalloonControllerTest, ShowAndCloseTest) { | 75 TEST_F(BalloonControllerTest, ShowAndCloseTest) { |
| 78 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), | 76 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), |
| 79 ASCIIToUTF16("http://www.google.com"), string16(), | 77 ASCIIToUTF16("http://www.google.com"), string16(), |
| 80 new NotificationObjectProxy(-1, -1, -1, false)); | 78 new NotificationObjectProxy(-1, -1, -1, false)); |
| 81 scoped_ptr<Balloon> balloon( | 79 scoped_ptr<Balloon> balloon( |
| 82 new Balloon(n, profile_.get(), collection_.get())); | 80 new Balloon(n, profile(), collection_.get())); |
| 83 balloon->SetPosition(gfx::Point(1, 1), false); | 81 balloon->SetPosition(gfx::Point(1, 1), false); |
| 84 balloon->set_content_size(gfx::Size(100, 100)); | 82 balloon->set_content_size(gfx::Size(100, 100)); |
| 85 | 83 |
| 86 BalloonController* controller = | 84 BalloonController* controller = |
| 87 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; | 85 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; |
| 88 | 86 |
| 89 [controller showWindow:nil]; | 87 [controller showWindow:nil]; |
| 90 [controller closeBalloon:YES]; | 88 [controller closeBalloon:YES]; |
| 91 } | 89 } |
| 92 | 90 |
| 93 TEST_F(BalloonControllerTest, SizesTest) { | 91 TEST_F(BalloonControllerTest, SizesTest) { |
| 94 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), | 92 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), |
| 95 ASCIIToUTF16("http://www.google.com"), string16(), | 93 ASCIIToUTF16("http://www.google.com"), string16(), |
| 96 new NotificationObjectProxy(-1, -1, -1, false)); | 94 new NotificationObjectProxy(-1, -1, -1, false)); |
| 97 scoped_ptr<Balloon> balloon( | 95 scoped_ptr<Balloon> balloon( |
| 98 new Balloon(n, profile_.get(), collection_.get())); | 96 new Balloon(n, profile(), collection_.get())); |
| 99 balloon->SetPosition(gfx::Point(1, 1), false); | 97 balloon->SetPosition(gfx::Point(1, 1), false); |
| 100 balloon->set_content_size(gfx::Size(100, 100)); | 98 balloon->set_content_size(gfx::Size(100, 100)); |
| 101 | 99 |
| 102 BalloonController* controller = | 100 BalloonController* controller = |
| 103 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; | 101 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; |
| 104 | 102 |
| 105 [controller showWindow:nil]; | 103 [controller showWindow:nil]; |
| 106 | 104 |
| 107 EXPECT_TRUE([controller desiredTotalWidth] > 100); | 105 EXPECT_TRUE([controller desiredTotalWidth] > 100); |
| 108 EXPECT_TRUE([controller desiredTotalHeight] > 100); | 106 EXPECT_TRUE([controller desiredTotalHeight] > 100); |
| 109 | 107 |
| 110 [controller closeBalloon:YES]; | 108 [controller closeBalloon:YES]; |
| 111 } | 109 } |
| 112 | 110 |
| 113 } | 111 } |
| OLD | NEW |