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

Side by Side Diff: chrome/browser/cocoa/browser_window_cocoa_unittest.mm

Issue 402066: Moved a whole pile of unittests over to CocoaTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/scoped_nsautorelease_pool.h" 6 #include "base/scoped_nsautorelease_pool.h"
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/bookmarks/bookmark_utils.h" 9 #include "chrome/browser/bookmarks/bookmark_utils.h"
10 #include "chrome/browser/cocoa/browser_test_helper.h" 10 #include "chrome/browser/cocoa/browser_test_helper.h"
11 #include "chrome/browser/cocoa/browser_window_cocoa.h" 11 #include "chrome/browser/cocoa/browser_window_cocoa.h"
12 #include "chrome/browser/cocoa/browser_window_controller.h" 12 #include "chrome/browser/cocoa/browser_window_controller.h"
13 #include "chrome/browser/cocoa/cocoa_test_helper.h" 13 #include "chrome/browser/cocoa/cocoa_test_helper.h"
14 #include "chrome/common/notification_type.h" 14 #include "chrome/common/notification_type.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 // A BrowserWindowCocoa that goes PONG when 17 // A BrowserWindowCocoa that goes PONG when
18 // BOOKMARK_BAR_VISIBILITY_PREF_CHANGED is sent. This is so we can be 18 // BOOKMARK_BAR_VISIBILITY_PREF_CHANGED is sent. This is so we can be
19 // sure we are observing it. 19 // sure we are observing it.
20 class BrowserWindowCocoaPong : public BrowserWindowCocoa { 20 class BrowserWindowCocoaPong : public BrowserWindowCocoa {
21 public: 21 public:
22 BrowserWindowCocoaPong(Browser* browser, 22 BrowserWindowCocoaPong(Browser* browser,
23 BrowserWindowController* controller, 23 BrowserWindowController* controller) :
24 NSWindow* window) : 24 BrowserWindowCocoa(browser, controller, [controller window]) {
25 BrowserWindowCocoa(browser, controller, window) {
26 pong_ = false; 25 pong_ = false;
27 } 26 }
28 virtual ~BrowserWindowCocoaPong() { } 27 virtual ~BrowserWindowCocoaPong() { }
29 28
30 void Observe(NotificationType type, 29 void Observe(NotificationType type,
31 const NotificationSource& source, 30 const NotificationSource& source,
32 const NotificationDetails& details) { 31 const NotificationDetails& details) {
33 if (type.value == NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED) 32 if (type.value == NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED)
34 pong_ = true; 33 pong_ = true;
35 BrowserWindowCocoa::Observe(type, source, details); 34 BrowserWindowCocoa::Observe(type, source, details);
36 } 35 }
37 36
38 bool pong_; 37 bool pong_;
39 }; 38 };
40 39
41 // Main test class. 40 // Main test class.
42 class BrowserWindowCocoaTest : public testing::Test { 41 class BrowserWindowCocoaTest : public CocoaTest {
42 virtual void SetUp() {
43 CocoaTest::SetUp();
44 Browser* browser = browser_helper_.browser();
45 controller_ = [[BrowserWindowController alloc] initWithBrowser:browser
46 takeOwnership:NO];
47 }
43 48
44 virtual void SetUp() { 49 virtual void TearDown() {
45 controller_.reset([[BrowserWindowController alloc] 50 [controller_ close];
46 initWithBrowser:browser_helper_.browser() 51 CocoaTest::TearDown();
47 takeOwnership:NO]);
48 } 52 }
49 53
50 public: 54 public:
51 // Order is very important here. We want the controller deleted
52 // before the pool, and want the pool deleted before
53 // BrowserTestHelper.
54 CocoaTestHelper cocoa_helper_;
55 BrowserTestHelper browser_helper_; 55 BrowserTestHelper browser_helper_;
56 base::ScopedNSAutoreleasePool pool_; 56 BrowserWindowController* controller_;
57 scoped_nsobject<BrowserWindowController> controller_;
58 }; 57 };
59 58
60 59
61 TEST_F(BrowserWindowCocoaTest, TestNotification) { 60 TEST_F(BrowserWindowCocoaTest, TestNotification) {
62 BrowserWindowCocoaPong *bwc = new BrowserWindowCocoaPong( 61 BrowserWindowCocoaPong *bwc =
63 browser_helper_.browser(), 62 new BrowserWindowCocoaPong(browser_helper_.browser(), controller_);
64 controller_.get(),
65 cocoa_helper_.window());
66 63
67 EXPECT_FALSE(bwc->pong_); 64 EXPECT_FALSE(bwc->pong_);
68 bookmark_utils::ToggleWhenVisible(browser_helper_.profile()); 65 bookmark_utils::ToggleWhenVisible(browser_helper_.profile());
69 // Confirm we are listening 66 // Confirm we are listening
70 EXPECT_TRUE(bwc->pong_); 67 EXPECT_TRUE(bwc->pong_);
71
72 delete bwc; 68 delete bwc;
73 // If this does NOT crash it confirms we stopped listening in the destructor. 69 // If this does NOT crash it confirms we stopped listening in the destructor.
74 bookmark_utils::ToggleWhenVisible(browser_helper_.profile()); 70 bookmark_utils::ToggleWhenVisible(browser_helper_.profile());
75 } 71 }
76 72
77 73
78 TEST_F(BrowserWindowCocoaTest, TestBookmarkBarVisible) { 74 TEST_F(BrowserWindowCocoaTest, TestBookmarkBarVisible) {
79 BrowserWindowCocoaPong *bwc = new BrowserWindowCocoaPong( 75 BrowserWindowCocoaPong *bwc = new BrowserWindowCocoaPong(
80 browser_helper_.browser(), 76 browser_helper_.browser(),
81 controller_.get(), 77 controller_);
82 cocoa_helper_.window());
83 scoped_ptr<BrowserWindowCocoaPong> scoped_bwc(bwc); 78 scoped_ptr<BrowserWindowCocoaPong> scoped_bwc(bwc);
84 79
85 bool before = bwc->IsBookmarkBarVisible(); 80 bool before = bwc->IsBookmarkBarVisible();
86 bookmark_utils::ToggleWhenVisible(browser_helper_.profile()); 81 bookmark_utils::ToggleWhenVisible(browser_helper_.profile());
87 EXPECT_NE(before, bwc->IsBookmarkBarVisible()); 82 EXPECT_NE(before, bwc->IsBookmarkBarVisible());
88 83
89 bookmark_utils::ToggleWhenVisible(browser_helper_.profile()); 84 bookmark_utils::ToggleWhenVisible(browser_helper_.profile());
90 EXPECT_EQ(before, bwc->IsBookmarkBarVisible()); 85 EXPECT_EQ(before, bwc->IsBookmarkBarVisible());
91 } 86 }
92 87
93 @interface FakeController : NSWindowController { 88 @interface FakeController : NSWindowController {
94 BOOL fullscreen_; 89 BOOL fullscreen_;
95 } 90 }
96 @end 91 @end
97 92
98 @implementation FakeController 93 @implementation FakeController
99 - (void)setFullscreen:(BOOL)fullscreen { 94 - (void)setFullscreen:(BOOL)fullscreen {
100 fullscreen_ = fullscreen; 95 fullscreen_ = fullscreen;
101 } 96 }
102 - (BOOL)isFullscreen { 97 - (BOOL)isFullscreen {
103 return fullscreen_; 98 return fullscreen_;
104 } 99 }
105 @end 100 @end
106 101
107 TEST_F(BrowserWindowCocoaTest, TestFullscreen) { 102 TEST_F(BrowserWindowCocoaTest, TestFullscreen) {
108 scoped_nsobject<FakeController> fake_controller_([[FakeController alloc] 103 FakeController* fake_controller = [[FakeController alloc] init];
109 init]);
110 BrowserWindowCocoaPong *bwc = new BrowserWindowCocoaPong( 104 BrowserWindowCocoaPong *bwc = new BrowserWindowCocoaPong(
111 browser_helper_.browser(), 105 browser_helper_.browser(),
112 (BrowserWindowController*)fake_controller_.get(), 106 (BrowserWindowController*)fake_controller);
113 cocoa_helper_.window());
114 scoped_ptr<BrowserWindowCocoaPong> scoped_bwc(bwc); 107 scoped_ptr<BrowserWindowCocoaPong> scoped_bwc(bwc);
115 108
116 EXPECT_FALSE(bwc->IsFullscreen()); 109 EXPECT_FALSE(bwc->IsFullscreen());
117 bwc->SetFullscreen(true); 110 bwc->SetFullscreen(true);
118 EXPECT_TRUE(bwc->IsFullscreen()); 111 EXPECT_TRUE(bwc->IsFullscreen());
119 bwc->SetFullscreen(false); 112 bwc->SetFullscreen(false);
120 EXPECT_FALSE(bwc->IsFullscreen()); 113 EXPECT_FALSE(bwc->IsFullscreen());
114 [fake_controller close];
121 } 115 }
122 116
123 /* TODO(???): test other methods of BrowserWindowCocoa */ 117 // TODO(???): test other methods of BrowserWindowCocoa
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698