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() { |
| 64 collection_.reset(); |
| 65 browser_.reset(); |
65 MessageLoop::current()->RunAllPending(); | 66 MessageLoop::current()->RunAllPending(); |
66 RenderViewHostTestHarness::TearDown(); | 67 ChromeRenderViewHostTestHarness::TearDown(); |
67 } | 68 } |
68 | 69 |
69 protected: | 70 protected: |
70 BrowserThread ui_thread_; | 71 BrowserThread ui_thread_; |
71 BrowserThread io_thread_; | 72 BrowserThread io_thread_; |
72 scoped_ptr<TestingProfile> profile_; | |
73 scoped_ptr<Browser> browser_; | 73 scoped_ptr<Browser> browser_; |
74 scoped_ptr<BalloonCollection> collection_; | 74 scoped_ptr<BalloonCollection> collection_; |
75 }; | 75 }; |
76 | 76 |
77 TEST_F(BalloonControllerTest, ShowAndCloseTest) { | 77 TEST_F(BalloonControllerTest, ShowAndCloseTest) { |
78 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), | 78 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), |
79 ASCIIToUTF16("http://www.google.com"), string16(), | 79 ASCIIToUTF16("http://www.google.com"), string16(), |
80 new NotificationObjectProxy(-1, -1, -1, false)); | 80 new NotificationObjectProxy(-1, -1, -1, false)); |
81 scoped_ptr<Balloon> balloon( | 81 scoped_ptr<Balloon> balloon( |
82 new Balloon(n, profile_.get(), collection_.get())); | 82 new Balloon(n, profile(), collection_.get())); |
83 balloon->SetPosition(gfx::Point(1, 1), false); | 83 balloon->SetPosition(gfx::Point(1, 1), false); |
84 balloon->set_content_size(gfx::Size(100, 100)); | 84 balloon->set_content_size(gfx::Size(100, 100)); |
85 | 85 |
86 BalloonController* controller = | 86 BalloonController* controller = |
87 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; | 87 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; |
88 | 88 |
89 [controller showWindow:nil]; | 89 [controller showWindow:nil]; |
90 [controller closeBalloon:YES]; | 90 [controller closeBalloon:YES]; |
91 } | 91 } |
92 | 92 |
93 TEST_F(BalloonControllerTest, SizesTest) { | 93 TEST_F(BalloonControllerTest, SizesTest) { |
94 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), | 94 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"), |
95 ASCIIToUTF16("http://www.google.com"), string16(), | 95 ASCIIToUTF16("http://www.google.com"), string16(), |
96 new NotificationObjectProxy(-1, -1, -1, false)); | 96 new NotificationObjectProxy(-1, -1, -1, false)); |
97 scoped_ptr<Balloon> balloon( | 97 scoped_ptr<Balloon> balloon( |
98 new Balloon(n, profile_.get(), collection_.get())); | 98 new Balloon(n, profile(), collection_.get())); |
99 balloon->SetPosition(gfx::Point(1, 1), false); | 99 balloon->SetPosition(gfx::Point(1, 1), false); |
100 balloon->set_content_size(gfx::Size(100, 100)); | 100 balloon->set_content_size(gfx::Size(100, 100)); |
101 | 101 |
102 BalloonController* controller = | 102 BalloonController* controller = |
103 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; | 103 [[TestBalloonController alloc] initWithBalloon:balloon.get()]; |
104 | 104 |
105 [controller showWindow:nil]; | 105 [controller showWindow:nil]; |
106 | 106 |
107 EXPECT_TRUE([controller desiredTotalWidth] > 100); | 107 EXPECT_TRUE([controller desiredTotalWidth] > 100); |
108 EXPECT_TRUE([controller desiredTotalHeight] > 100); | 108 EXPECT_TRUE([controller desiredTotalHeight] > 100); |
109 | 109 |
110 [controller closeBalloon:YES]; | 110 [controller closeBalloon:YES]; |
111 } | 111 } |
112 | 112 |
113 } | 113 } |
OLD | NEW |