Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: chrome/browser/ui/cocoa/notifications/balloon_controller_unittest.mm

Issue 231213003: notification balloons: Remove views and cocoa implementations of BalloonCollection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/notifications/balloon.h"
8 #include "chrome/browser/notifications/balloon_collection.h"
9 #include "chrome/browser/notifications/notification.h"
10 #include "chrome/browser/notifications/notification_object_proxy.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
13 #include "chrome/browser/ui/cocoa/notifications/balloon_controller.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/test_browser_window.h"
16 #include "chrome/test/base/testing_profile.h"
17
18 // Subclass balloon controller and mock out the initialization of the RVH.
19 @interface TestBalloonController : BalloonController {
20 }
21 - (void)initializeHost;
22 @end
23
24 @implementation TestBalloonController
25 - (void)initializeHost {}
26 @end
27
28 namespace {
29
30 // Use a dummy balloon collection for testing.
31 class MockBalloonCollection : public BalloonCollection {
32 virtual void Add(const Notification& notification,
33 Profile* profile) OVERRIDE {}
34 virtual const Notification* FindById(const std::string& id) const OVERRIDE {
35 return NULL;
36 }
37 virtual bool RemoveById(const std::string& id) OVERRIDE { return false; }
38 virtual bool RemoveBySourceOrigin(const GURL& origin) OVERRIDE {
39 return false;
40 }
41 virtual bool RemoveByProfile(Profile* profile) OVERRIDE { return false; }
42 virtual void RemoveAll() OVERRIDE {}
43 virtual bool HasSpace() const OVERRIDE { return true; }
44 virtual void ResizeBalloon(
45 Balloon* balloon,
46 const gfx::Size& size) OVERRIDE {
47 }
48 virtual void DisplayChanged() OVERRIDE {}
49 virtual void SetPositionPreference(PositionPreference preference) OVERRIDE {}
50 virtual void OnBalloonClosed(Balloon* source) OVERRIDE {};
51 virtual const Balloons& GetActiveBalloons() OVERRIDE {
52 NOTREACHED();
53 return balloons_;
54 }
55 private:
56 Balloons balloons_;
57 };
58
59 class BalloonControllerTest : public ChromeRenderViewHostTestHarness {
60 virtual void SetUp() OVERRIDE {
61 ChromeRenderViewHostTestHarness::SetUp();
62 CocoaTest::BootstrapCocoa();
63 Browser::CreateParams native_params(profile(), chrome::GetActiveDesktop());
64 browser_.reset(
65 chrome::CreateBrowserWithTestWindowForParams(&native_params));
66 collection_.reset(new MockBalloonCollection());
67 }
68
69 virtual void TearDown() OVERRIDE {
70 collection_.reset();
71 browser_.reset();
72 ChromeRenderViewHostTestHarness::TearDown();
73 }
74
75 protected:
76 scoped_ptr<Browser> browser_;
77 scoped_ptr<BalloonCollection> collection_;
78 };
79
80 TEST_F(BalloonControllerTest, ShowAndCloseTest) {
81 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"),
82 base::ASCIIToUTF16("http://www.google.com"), base::string16(),
83 new NotificationObjectProxy(-1, -1, -1, false));
84 scoped_ptr<Balloon> balloon(
85 new Balloon(n, profile(), collection_.get()));
86 balloon->SetPosition(gfx::Point(1, 1), false);
87 balloon->set_content_size(gfx::Size(100, 100));
88
89 BalloonController* controller =
90 [[TestBalloonController alloc] initWithBalloon:balloon.get()];
91
92 [controller showWindow:nil];
93 [controller closeBalloon:YES];
94 }
95
96 TEST_F(BalloonControllerTest, SizesTest) {
97 Notification n(GURL("http://www.google.com"), GURL("http://www.google.com"),
98 base::ASCIIToUTF16("http://www.google.com"), base::string16(),
99 new NotificationObjectProxy(-1, -1, -1, false));
100 scoped_ptr<Balloon> balloon(
101 new Balloon(n, profile(), collection_.get()));
102 balloon->SetPosition(gfx::Point(1, 1), false);
103 balloon->set_content_size(gfx::Size(100, 100));
104
105 BalloonController* controller =
106 [[TestBalloonController alloc] initWithBalloon:balloon.get()];
107
108 [controller showWindow:nil];
109
110 EXPECT_TRUE([controller desiredTotalWidth] > 100);
111 EXPECT_TRUE([controller desiredTotalHeight] > 100);
112
113 [controller closeBalloon:YES];
114 }
115
116 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/notifications/balloon_controller.mm ('k') | chrome/browser/ui/cocoa/notifications/balloon_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698