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

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

Issue 3095004: [Mac] Use the new {EXPECT,ASSERT}_NS{EQ,NE} macros where possible. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Fix compile Created 10 years, 4 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
OLDNEW
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 <Cocoa/Cocoa.h> 5 #include <Cocoa/Cocoa.h>
6 6
7 #include "base/scoped_nsobject.h" 7 #include "base/scoped_nsobject.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #import "chrome/browser/cocoa/bubble_view.h" 9 #import "chrome/browser/cocoa/bubble_view.h"
10 #import "chrome/browser/cocoa/browser_test_helper.h" 10 #import "chrome/browser/cocoa/browser_test_helper.h"
11 #import "chrome/browser/cocoa/cocoa_test_helper.h" 11 #import "chrome/browser/cocoa/cocoa_test_helper.h"
12 #import "chrome/browser/cocoa/status_bubble_mac.h" 12 #import "chrome/browser/cocoa/status_bubble_mac.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #import "testing/gtest_mac.h"
15 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
16 17
17 // The test delegate records all of the status bubble object's state 18 // The test delegate records all of the status bubble object's state
18 // transitions. 19 // transitions.
19 @interface StatusBubbleMacTestDelegate : NSObject { 20 @interface StatusBubbleMacTestDelegate : NSObject {
20 @private 21 @private
21 std::vector<StatusBubbleMac::StatusBubbleState> states_; 22 std::vector<StatusBubbleMac::StatusBubbleState> states_;
22 } 23 }
23 - (void)statusBubbleWillEnterState:(StatusBubbleMac::StatusBubbleState)state; 24 - (void)statusBubbleWillEnterState:(StatusBubbleMac::StatusBubbleState)state;
24 @end 25 @end
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 return (*States())[index]; 107 return (*States())[index];
107 } 108 }
108 BrowserTestHelper browser_helper_; 109 BrowserTestHelper browser_helper_;
109 scoped_nsobject<StatusBubbleMacTestDelegate> delegate_; 110 scoped_nsobject<StatusBubbleMacTestDelegate> delegate_;
110 StatusBubbleMac* bubble_; // Strong. 111 StatusBubbleMac* bubble_; // Strong.
111 }; 112 };
112 113
113 TEST_F(StatusBubbleMacTest, SetStatus) { 114 TEST_F(StatusBubbleMacTest, SetStatus) {
114 bubble_->SetStatus(L""); 115 bubble_->SetStatus(L"");
115 bubble_->SetStatus(L"This is a test"); 116 bubble_->SetStatus(L"This is a test");
116 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); 117 EXPECT_NSEQ(@"This is a test", GetText());
117 EXPECT_TRUE(IsVisible()); 118 EXPECT_TRUE(IsVisible());
118 119
119 // Set the status to the exact same thing again 120 // Set the status to the exact same thing again
120 bubble_->SetStatus(L"This is a test"); 121 bubble_->SetStatus(L"This is a test");
121 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); 122 EXPECT_NSEQ(@"This is a test", GetText());
122 123
123 // Hide it 124 // Hide it
124 bubble_->SetStatus(L""); 125 bubble_->SetStatus(L"");
125 EXPECT_FALSE(IsVisible()); 126 EXPECT_FALSE(IsVisible());
126 } 127 }
127 128
128 TEST_F(StatusBubbleMacTest, SetURL) { 129 TEST_F(StatusBubbleMacTest, SetURL) {
129 bubble_->SetURL(GURL(), L""); 130 bubble_->SetURL(GURL(), L"");
130 EXPECT_FALSE(IsVisible()); 131 EXPECT_FALSE(IsVisible());
131 bubble_->SetURL(GURL("bad url"), L""); 132 bubble_->SetURL(GURL("bad url"), L"");
132 EXPECT_FALSE(IsVisible()); 133 EXPECT_FALSE(IsVisible());
133 bubble_->SetURL(GURL("http://"), L""); 134 bubble_->SetURL(GURL("http://"), L"");
134 EXPECT_TRUE(IsVisible()); 135 EXPECT_TRUE(IsVisible());
135 EXPECT_TRUE([GetURLText() isEqualToString:@"http:"]); 136 EXPECT_NSEQ(@"http:", GetURLText());
136 bubble_->SetURL(GURL("about:blank"), L""); 137 bubble_->SetURL(GURL("about:blank"), L"");
137 EXPECT_TRUE(IsVisible()); 138 EXPECT_TRUE(IsVisible());
138 EXPECT_TRUE([GetURLText() isEqualToString:@"about:blank"]); 139 EXPECT_NSEQ(@"about:blank", GetURLText());
139 bubble_->SetURL(GURL("foopy://"), L""); 140 bubble_->SetURL(GURL("foopy://"), L"");
140 EXPECT_TRUE(IsVisible()); 141 EXPECT_TRUE(IsVisible());
141 EXPECT_TRUE([GetURLText() isEqualToString:@"foopy://"]); 142 EXPECT_NSEQ(@"foopy://", GetURLText());
142 bubble_->SetURL(GURL("http://www.cnn.com"), L""); 143 bubble_->SetURL(GURL("http://www.cnn.com"), L"");
143 EXPECT_TRUE(IsVisible()); 144 EXPECT_TRUE(IsVisible());
144 EXPECT_TRUE([GetURLText() isEqualToString:@"www.cnn.com"]); 145 EXPECT_NSEQ(@"www.cnn.com", GetURLText());
145 } 146 }
146 147
147 // Test hiding bubble that's already hidden. 148 // Test hiding bubble that's already hidden.
148 TEST_F(StatusBubbleMacTest, Hides) { 149 TEST_F(StatusBubbleMacTest, Hides) {
149 bubble_->SetStatus(L"Showing"); 150 bubble_->SetStatus(L"Showing");
150 EXPECT_TRUE(IsVisible()); 151 EXPECT_TRUE(IsVisible());
151 bubble_->Hide(); 152 bubble_->Hide();
152 EXPECT_FALSE(IsVisible()); 153 EXPECT_FALSE(IsVisible());
153 bubble_->Hide(); 154 bubble_->Hide();
154 EXPECT_FALSE(IsVisible()); 155 EXPECT_FALSE(IsVisible());
155 } 156 }
156 157
157 // Test the "main"/"backup" behavior in StatusBubbleMac::SetText(). 158 // Test the "main"/"backup" behavior in StatusBubbleMac::SetText().
158 TEST_F(StatusBubbleMacTest, SetStatusAndURL) { 159 TEST_F(StatusBubbleMacTest, SetStatusAndURL) {
159 EXPECT_FALSE(IsVisible()); 160 EXPECT_FALSE(IsVisible());
160 bubble_->SetStatus(L"Status"); 161 bubble_->SetStatus(L"Status");
161 EXPECT_TRUE(IsVisible()); 162 EXPECT_TRUE(IsVisible());
162 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]); 163 EXPECT_NSEQ(@"Status", GetBubbleViewText());
163 bubble_->SetURL(GURL("http://www.nytimes.com"), L""); 164 bubble_->SetURL(GURL("http://www.nytimes.com"), L"");
164 EXPECT_TRUE(IsVisible()); 165 EXPECT_TRUE(IsVisible());
165 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"www.nytimes.com"]); 166 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText());
166 bubble_->SetURL(GURL(), L""); 167 bubble_->SetURL(GURL(), L"");
167 EXPECT_TRUE(IsVisible()); 168 EXPECT_TRUE(IsVisible());
168 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]); 169 EXPECT_NSEQ(@"Status", GetBubbleViewText());
169 bubble_->SetStatus(L""); 170 bubble_->SetStatus(L"");
170 EXPECT_FALSE(IsVisible()); 171 EXPECT_FALSE(IsVisible());
171 bubble_->SetURL(GURL("http://www.nytimes.com"), L""); 172 bubble_->SetURL(GURL("http://www.nytimes.com"), L"");
172 EXPECT_TRUE(IsVisible()); 173 EXPECT_TRUE(IsVisible());
173 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"www.nytimes.com"]); 174 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText());
174 bubble_->SetStatus(L"Status"); 175 bubble_->SetStatus(L"Status");
175 EXPECT_TRUE(IsVisible()); 176 EXPECT_TRUE(IsVisible());
176 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]); 177 EXPECT_NSEQ(@"Status", GetBubbleViewText());
177 bubble_->SetStatus(L""); 178 bubble_->SetStatus(L"");
178 EXPECT_TRUE(IsVisible()); 179 EXPECT_TRUE(IsVisible());
179 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"www.nytimes.com"]); 180 EXPECT_NSEQ(@"www.nytimes.com", GetBubbleViewText());
180 bubble_->SetURL(GURL(), L""); 181 bubble_->SetURL(GURL(), L"");
181 EXPECT_FALSE(IsVisible()); 182 EXPECT_FALSE(IsVisible());
182 } 183 }
183 184
184 // Test that the status bubble goes through the correct delay and fade states. 185 // Test that the status bubble goes through the correct delay and fade states.
185 // The delay and fade duration are simulated and not actually experienced 186 // The delay and fade duration are simulated and not actually experienced
186 // during the test because StatusBubbleMacTest sets immediate_ mode. 187 // during the test because StatusBubbleMacTest sets immediate_ mode.
187 TEST_F(StatusBubbleMacTest, StateTransitions) { 188 TEST_F(StatusBubbleMacTest, StateTransitions) {
188 // First, some sanity 189 // First, some sanity
189 190
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 bubble_->Hide(); 472 bubble_->Hide();
472 NSRect frame = [window frame]; 473 NSRect frame = [window frame];
473 frame.origin.x += 50; 474 frame.origin.x += 50;
474 [window setFrame:frame display:YES]; 475 [window setFrame:frame display:YES];
475 bubble_->SetStatus(L"Reshowing"); 476 bubble_->SetStatus(L"Reshowing");
476 477
477 // The bubble should reattach in the correct location. 478 // The bubble should reattach in the correct location.
478 child = GetWindow(); 479 child = GetWindow();
479 EXPECT_TRUE(NSEqualPoints([window frame].origin, [child frame].origin)); 480 EXPECT_TRUE(NSEqualPoints([window frame].origin, [child frame].origin));
480 } 481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698