OLD | NEW |
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 <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" |
| 10 #import "chrome/browser/cocoa/browser_test_helper.h" |
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 11 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
10 #include "chrome/browser/cocoa/status_bubble_mac.h" | 12 #import "chrome/browser/cocoa/status_bubble_mac.h" |
11 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
14 #import "third_party/GTM/AppKit/GTMTheme.h" | 16 #import "third_party/GTM/AppKit/GTMTheme.h" |
15 | 17 |
16 @interface StatusBubbleMacTestWindowDelegate : NSObject <GTMThemeDelegate>; | 18 @interface StatusBubbleMacTestWindowDelegate : NSObject <GTMThemeDelegate> |
17 @end | 19 @end |
18 @implementation StatusBubbleMacTestWindowDelegate | 20 @implementation StatusBubbleMacTestWindowDelegate |
19 - (GTMTheme*)gtm_themeForWindow:(NSWindow*)window { | 21 - (GTMTheme*)gtm_themeForWindow:(NSWindow*)window { |
20 return [[[GTMTheme alloc] init] autorelease]; | 22 return [[[GTMTheme alloc] init] autorelease]; |
21 } | 23 } |
22 | 24 |
23 - (NSPoint)gtm_themePatternPhaseForWindow:(NSWindow*)window { | 25 - (NSPoint)gtm_themePatternPhaseForWindow:(NSWindow*)window { |
24 return NSZeroPoint; | 26 return NSZeroPoint; |
25 } | 27 } |
26 @end | 28 @end |
27 | 29 |
| 30 // The test delegate records all of the status bubble object's state |
| 31 // transitions. |
| 32 @interface StatusBubbleMacTestDelegate : NSObject { |
| 33 @private |
| 34 std::vector<StatusBubbleMac::StatusBubbleState> states_; |
| 35 } |
| 36 - (void)statusBubbleWillEnterState:(StatusBubbleMac::StatusBubbleState)state; |
| 37 @end |
| 38 @implementation StatusBubbleMacTestDelegate |
| 39 - (void)statusBubbleWillEnterState:(StatusBubbleMac::StatusBubbleState)state { |
| 40 states_.push_back(state); |
| 41 } |
| 42 - (std::vector<StatusBubbleMac::StatusBubbleState>*)states { |
| 43 return &states_; |
| 44 } |
| 45 @end |
| 46 |
28 class StatusBubbleMacTest : public PlatformTest { | 47 class StatusBubbleMacTest : public PlatformTest { |
29 public: | 48 public: |
30 StatusBubbleMacTest() { | 49 StatusBubbleMacTest() { |
31 NSWindow* window = cocoa_helper_.window(); | 50 NSWindow* window = cocoa_helper_.window(); |
32 bubble_.reset(new StatusBubbleMac(window, nil)); | 51 EXPECT_TRUE(window); |
| 52 delegate_.reset([[StatusBubbleMacTestDelegate alloc] init]); |
| 53 EXPECT_TRUE(delegate_.get()); |
| 54 bubble_.reset(new StatusBubbleMac(window, delegate_)); |
33 EXPECT_TRUE(bubble_.get()); | 55 EXPECT_TRUE(bubble_.get()); |
| 56 |
| 57 // Turn off delays and transitions for test mode. This doesn't just speed |
| 58 // things along, it's actually required to get StatusBubbleMac to behave |
| 59 // synchronously, because the tests here don't know how to wait for |
| 60 // results. This allows these tests to be much more complete with a |
| 61 // minimal loss of coverage and without any heinous rearchitecting. |
| 62 bubble_->immediate_ = true; |
| 63 |
34 EXPECT_FALSE(bubble_->window_); // lazily creates window | 64 EXPECT_FALSE(bubble_->window_); // lazily creates window |
35 } | 65 } |
36 | 66 |
37 bool IsVisible() { | 67 bool IsVisible() { |
38 return [bubble_->window_ isVisible] ? true: false; | 68 if (![bubble_->window_ isVisible]) |
| 69 return false; |
| 70 return [bubble_->window_ alphaValue] > 0.0; |
39 } | 71 } |
40 NSString* GetText() { | 72 NSString* GetText() { |
41 return bubble_->status_text_; | 73 return bubble_->status_text_; |
42 } | 74 } |
43 NSString* GetURLText() { | 75 NSString* GetURLText() { |
44 return bubble_->url_text_; | 76 return bubble_->url_text_; |
45 } | 77 } |
| 78 NSString* GetBubbleViewText() { |
| 79 BubbleView* bubbleView = [bubble_->window_ contentView]; |
| 80 return [bubbleView content]; |
| 81 } |
46 NSWindow* GetWindow() { | 82 NSWindow* GetWindow() { |
47 return bubble_->window_; | 83 return bubble_->window_; |
48 } | 84 } |
49 NSWindow* GetParent() { | 85 NSWindow* GetParent() { |
50 return bubble_->parent_; | 86 return bubble_->parent_; |
51 } | 87 } |
| 88 StatusBubbleMac::StatusBubbleState GetState() { |
| 89 return bubble_->state_; |
| 90 } |
| 91 void SetState(StatusBubbleMac::StatusBubbleState state) { |
| 92 bubble_->SetState(state); |
| 93 } |
| 94 std::vector<StatusBubbleMac::StatusBubbleState>* States() { |
| 95 return [delegate_ states]; |
| 96 } |
| 97 StatusBubbleMac::StatusBubbleState StateAt(int index) { |
| 98 return (*States())[index]; |
| 99 } |
52 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... | 100 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc... |
| 101 BrowserTestHelper browser_helper_; |
| 102 scoped_nsobject<StatusBubbleMacTestDelegate> delegate_; |
53 scoped_ptr<StatusBubbleMac> bubble_; | 103 scoped_ptr<StatusBubbleMac> bubble_; |
54 }; | 104 }; |
55 | 105 |
56 TEST_F(StatusBubbleMacTest, Theme) { | 106 TEST_F(StatusBubbleMacTest, Theme) { |
57 bubble_->SetStatus(L"Theme test"); // Creates the window | 107 bubble_->SetStatus(L"Theme test"); // Creates the window |
58 [GetParent() setDelegate: | 108 [GetParent() setDelegate: |
59 [[[StatusBubbleMacTestWindowDelegate alloc] init] autorelease]]; | 109 [[[StatusBubbleMacTestWindowDelegate alloc] init] autorelease]]; |
60 EXPECT_TRUE([GetParent() gtm_theme] != nil); | 110 EXPECT_TRUE([GetParent() gtm_theme] != nil); |
61 EXPECT_TRUE([[GetWindow() contentView] gtm_theme] != nil); | 111 EXPECT_TRUE([[GetWindow() contentView] gtm_theme] != nil); |
62 } | 112 } |
63 | 113 |
64 TEST_F(StatusBubbleMacTest, SetStatus) { | 114 TEST_F(StatusBubbleMacTest, SetStatus) { |
65 bubble_->SetStatus(L""); | 115 bubble_->SetStatus(L""); |
66 bubble_->SetStatus(L"This is a test"); | 116 bubble_->SetStatus(L"This is a test"); |
67 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); | 117 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); |
68 EXPECT_TRUE(IsVisible()); | 118 EXPECT_TRUE(IsVisible()); |
69 | 119 |
70 // Set the status to the exact same thing again | 120 // Set the status to the exact same thing again |
71 bubble_->SetStatus(L"This is a test"); | 121 bubble_->SetStatus(L"This is a test"); |
72 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); | 122 EXPECT_TRUE([GetText() isEqualToString:@"This is a test"]); |
73 | 123 |
74 // Hide it | 124 // Hide it |
75 bubble_->SetStatus(L""); | 125 bubble_->SetStatus(L""); |
76 EXPECT_FALSE(IsVisible()); | 126 EXPECT_FALSE(IsVisible()); |
77 EXPECT_FALSE(GetText()); | |
78 } | 127 } |
79 | 128 |
80 TEST_F(StatusBubbleMacTest, SetURL) { | 129 TEST_F(StatusBubbleMacTest, SetURL) { |
81 bubble_->SetURL(GURL(), L""); | 130 bubble_->SetURL(GURL(), L""); |
82 EXPECT_FALSE(IsVisible()); | 131 EXPECT_FALSE(IsVisible()); |
83 bubble_->SetURL(GURL("bad url"), L""); | 132 bubble_->SetURL(GURL("bad url"), L""); |
84 EXPECT_FALSE(IsVisible()); | 133 EXPECT_FALSE(IsVisible()); |
85 bubble_->SetURL(GURL("http://"), L""); | 134 bubble_->SetURL(GURL("http://"), L""); |
86 EXPECT_TRUE(IsVisible()); | 135 EXPECT_TRUE(IsVisible()); |
87 EXPECT_TRUE([GetURLText() isEqualToString:@"http:"]); | 136 EXPECT_TRUE([GetURLText() isEqualToString:@"http:"]); |
(...skipping 11 matching lines...) Expand all Loading... |
99 // Test hiding bubble that's already hidden. | 148 // Test hiding bubble that's already hidden. |
100 TEST_F(StatusBubbleMacTest, Hides) { | 149 TEST_F(StatusBubbleMacTest, Hides) { |
101 bubble_->SetStatus(L"Showing"); | 150 bubble_->SetStatus(L"Showing"); |
102 EXPECT_TRUE(IsVisible()); | 151 EXPECT_TRUE(IsVisible()); |
103 bubble_->Hide(); | 152 bubble_->Hide(); |
104 EXPECT_FALSE(IsVisible()); | 153 EXPECT_FALSE(IsVisible()); |
105 bubble_->Hide(); | 154 bubble_->Hide(); |
106 EXPECT_FALSE(IsVisible()); | 155 EXPECT_FALSE(IsVisible()); |
107 } | 156 } |
108 | 157 |
| 158 // Test the "main"/"backup" behavior in StatusBubbleMac::SetText(). |
| 159 TEST_F(StatusBubbleMacTest, SetStatusAndURL) { |
| 160 EXPECT_FALSE(IsVisible()); |
| 161 bubble_->SetStatus(L"Status"); |
| 162 EXPECT_TRUE(IsVisible()); |
| 163 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]); |
| 164 bubble_->SetURL(GURL("http://www.nytimes.com/"), L""); |
| 165 EXPECT_TRUE(IsVisible()); |
| 166 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"http://www.nytimes.com/"]); |
| 167 bubble_->SetURL(GURL(), L""); |
| 168 EXPECT_TRUE(IsVisible()); |
| 169 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]); |
| 170 bubble_->SetStatus(L""); |
| 171 EXPECT_FALSE(IsVisible()); |
| 172 bubble_->SetURL(GURL("http://www.nytimes.com/"), L""); |
| 173 EXPECT_TRUE(IsVisible()); |
| 174 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"http://www.nytimes.com/"]); |
| 175 bubble_->SetStatus(L"Status"); |
| 176 EXPECT_TRUE(IsVisible()); |
| 177 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"Status"]); |
| 178 bubble_->SetStatus(L""); |
| 179 EXPECT_TRUE(IsVisible()); |
| 180 EXPECT_TRUE([GetBubbleViewText() isEqualToString:@"http://www.nytimes.com/"]); |
| 181 bubble_->SetURL(GURL(), L""); |
| 182 EXPECT_FALSE(IsVisible()); |
| 183 } |
| 184 |
| 185 // Test that the status bubble goes through the correct delay and fade states. |
| 186 // The delay and fade duration are simulated and not actually experienced |
| 187 // during the test because StatusBubbleMacTest sets immediate_ mode. |
| 188 TEST_F(StatusBubbleMacTest, StateTransitions) { |
| 189 // First, some sanity |
| 190 |
| 191 EXPECT_FALSE(IsVisible()); |
| 192 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 193 |
| 194 States()->clear(); |
| 195 EXPECT_TRUE(States()->empty()); |
| 196 |
| 197 bubble_->SetStatus(L""); |
| 198 EXPECT_FALSE(IsVisible()); |
| 199 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 200 EXPECT_TRUE(States()->empty()); // no change from initial kBubbleHidden state |
| 201 |
| 202 // Next, a few ordinary cases |
| 203 |
| 204 // Test StartShowing from kBubbleHidden |
| 205 bubble_->SetStatus(L"Status"); |
| 206 EXPECT_TRUE(IsVisible()); |
| 207 // Check GetState before checking States to make sure that all state |
| 208 // transitions have been flushed to States. |
| 209 EXPECT_EQ(StatusBubbleMac::kBubbleShown, GetState()); |
| 210 EXPECT_EQ(3u, States()->size()); |
| 211 EXPECT_EQ(StatusBubbleMac::kBubbleShowingTimer, StateAt(0)); |
| 212 EXPECT_EQ(StatusBubbleMac::kBubbleShowingFadeIn, StateAt(1)); |
| 213 EXPECT_EQ(StatusBubbleMac::kBubbleShown, StateAt(2)); |
| 214 |
| 215 // Test StartShowing from kBubbleShown with the same message |
| 216 States()->clear(); |
| 217 bubble_->SetStatus(L"Status"); |
| 218 EXPECT_TRUE(IsVisible()); |
| 219 EXPECT_EQ(StatusBubbleMac::kBubbleShown, GetState()); |
| 220 EXPECT_TRUE(States()->empty()); |
| 221 |
| 222 // Test StartShowing from kBubbleShown with a different message |
| 223 bubble_->SetStatus(L"New Status"); |
| 224 EXPECT_TRUE(IsVisible()); |
| 225 EXPECT_EQ(StatusBubbleMac::kBubbleShown, GetState()); |
| 226 EXPECT_TRUE(States()->empty()); |
| 227 |
| 228 // Test StartHiding from kBubbleShown |
| 229 bubble_->SetStatus(L""); |
| 230 EXPECT_FALSE(IsVisible()); |
| 231 // Check GetState before checking States to make sure that all state |
| 232 // transitions have been flushed to States. |
| 233 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 234 EXPECT_EQ(3u, States()->size()); |
| 235 EXPECT_EQ(StatusBubbleMac::kBubbleHidingTimer, StateAt(0)); |
| 236 EXPECT_EQ(StatusBubbleMac::kBubbleHidingFadeOut, StateAt(1)); |
| 237 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, StateAt(2)); |
| 238 |
| 239 // Test StartHiding from kBubbleHidden |
| 240 States()->clear(); |
| 241 bubble_->SetStatus(L""); |
| 242 EXPECT_FALSE(IsVisible()); |
| 243 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 244 EXPECT_TRUE(States()->empty()); |
| 245 |
| 246 // Now, the edge cases |
| 247 |
| 248 // Test StartShowing from kBubbleShowingTimer |
| 249 bubble_->SetStatus(L"Status"); |
| 250 SetState(StatusBubbleMac::kBubbleShowingTimer); |
| 251 [GetWindow() setAlphaValue:0.0]; |
| 252 States()->clear(); |
| 253 EXPECT_TRUE(States()->empty()); |
| 254 bubble_->SetStatus(L"Status"); |
| 255 EXPECT_EQ(StatusBubbleMac::kBubbleShown, GetState()); |
| 256 EXPECT_EQ(2u, States()->size()); |
| 257 EXPECT_EQ(StatusBubbleMac::kBubbleShowingFadeIn, StateAt(0)); |
| 258 EXPECT_EQ(StatusBubbleMac::kBubbleShown, StateAt(1)); |
| 259 |
| 260 // Test StartShowing from kBubbleShowingFadeIn |
| 261 bubble_->SetStatus(L"Status"); |
| 262 SetState(StatusBubbleMac::kBubbleShowingFadeIn); |
| 263 [GetWindow() setAlphaValue:0.5]; |
| 264 States()->clear(); |
| 265 EXPECT_TRUE(States()->empty()); |
| 266 bubble_->SetStatus(L"Status"); |
| 267 // The actual state values can't be tested in immediate_ mode because |
| 268 // the window wasn't actually fading in. Without immediate_ mode, |
| 269 // expect kBubbleShown. |
| 270 bubble_->SetStatus(L""); // Go back to a deterministic state. |
| 271 |
| 272 // Test StartShowing from kBubbleHidingTimer |
| 273 bubble_->SetStatus(L""); |
| 274 SetState(StatusBubbleMac::kBubbleHidingTimer); |
| 275 [GetWindow() setAlphaValue:1.0]; |
| 276 States()->clear(); |
| 277 EXPECT_TRUE(States()->empty()); |
| 278 bubble_->SetStatus(L"Status"); |
| 279 EXPECT_EQ(StatusBubbleMac::kBubbleShown, GetState()); |
| 280 EXPECT_EQ(1u, States()->size()); |
| 281 EXPECT_EQ(StatusBubbleMac::kBubbleShown, StateAt(0)); |
| 282 |
| 283 // Test StartShowing from kBubbleHidingFadeOut |
| 284 bubble_->SetStatus(L""); |
| 285 SetState(StatusBubbleMac::kBubbleHidingFadeOut); |
| 286 [GetWindow() setAlphaValue:0.5]; |
| 287 States()->clear(); |
| 288 EXPECT_TRUE(States()->empty()); |
| 289 bubble_->SetStatus(L"Status"); |
| 290 EXPECT_EQ(StatusBubbleMac::kBubbleShown, GetState()); |
| 291 EXPECT_EQ(2u, States()->size()); |
| 292 EXPECT_EQ(StatusBubbleMac::kBubbleShowingFadeIn, StateAt(0)); |
| 293 EXPECT_EQ(StatusBubbleMac::kBubbleShown, StateAt(1)); |
| 294 |
| 295 // Test StartHiding from kBubbleShowingTimer |
| 296 bubble_->SetStatus(L"Status"); |
| 297 SetState(StatusBubbleMac::kBubbleShowingTimer); |
| 298 [GetWindow() setAlphaValue:0.0]; |
| 299 States()->clear(); |
| 300 EXPECT_TRUE(States()->empty()); |
| 301 bubble_->SetStatus(L""); |
| 302 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 303 EXPECT_EQ(1u, States()->size()); |
| 304 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, StateAt(0)); |
| 305 |
| 306 // Test StartHiding from kBubbleShowingFadeIn |
| 307 bubble_->SetStatus(L"Status"); |
| 308 SetState(StatusBubbleMac::kBubbleShowingFadeIn); |
| 309 [GetWindow() setAlphaValue:0.5]; |
| 310 States()->clear(); |
| 311 EXPECT_TRUE(States()->empty()); |
| 312 bubble_->SetStatus(L""); |
| 313 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 314 EXPECT_EQ(2u, States()->size()); |
| 315 EXPECT_EQ(StatusBubbleMac::kBubbleHidingFadeOut, StateAt(0)); |
| 316 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, StateAt(1)); |
| 317 |
| 318 // Test StartHiding from kBubbleHidingTimer |
| 319 bubble_->SetStatus(L""); |
| 320 SetState(StatusBubbleMac::kBubbleHidingTimer); |
| 321 [GetWindow() setAlphaValue:1.0]; |
| 322 States()->clear(); |
| 323 EXPECT_TRUE(States()->empty()); |
| 324 bubble_->SetStatus(L""); |
| 325 // The actual state values can't be tested in immediate_ mode because |
| 326 // the timer wasn't actually running. Without immediate_ mode, expect |
| 327 // kBubbleHidingFadeOut and kBubbleHidden. |
| 328 bubble_->SetStatus(L"Status"); // Go back to a deterministic state. |
| 329 |
| 330 // Test StartHiding from kBubbleHidingFadeOut |
| 331 bubble_->SetStatus(L""); |
| 332 SetState(StatusBubbleMac::kBubbleHidingFadeOut); |
| 333 [GetWindow() setAlphaValue:0.5]; |
| 334 States()->clear(); |
| 335 EXPECT_TRUE(States()->empty()); |
| 336 bubble_->SetStatus(L""); |
| 337 // The actual state values can't be tested in immediate_ mode because |
| 338 // the window wasn't actually fading out. Without immediate_ mode, expect |
| 339 // kBubbleHidden. |
| 340 bubble_->SetStatus(L"Status"); // Go back to a deterministic state. |
| 341 |
| 342 // Test Hide from kBubbleHidden |
| 343 bubble_->SetStatus(L""); |
| 344 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 345 States()->clear(); |
| 346 EXPECT_TRUE(States()->empty()); |
| 347 bubble_->Hide(); |
| 348 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 349 EXPECT_TRUE(States()->empty()); |
| 350 |
| 351 // Test Hide from kBubbleShowingTimer |
| 352 bubble_->SetStatus(L"Status"); |
| 353 SetState(StatusBubbleMac::kBubbleShowingTimer); |
| 354 [GetWindow() setAlphaValue:0.0]; |
| 355 States()->clear(); |
| 356 EXPECT_TRUE(States()->empty()); |
| 357 bubble_->Hide(); |
| 358 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 359 EXPECT_EQ(1u, States()->size()); |
| 360 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, StateAt(0)); |
| 361 |
| 362 // Test Hide from kBubbleShowingFadeIn |
| 363 bubble_->SetStatus(L"Status"); |
| 364 SetState(StatusBubbleMac::kBubbleShowingFadeIn); |
| 365 [GetWindow() setAlphaValue:0.5]; |
| 366 States()->clear(); |
| 367 EXPECT_TRUE(States()->empty()); |
| 368 bubble_->Hide(); |
| 369 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 370 EXPECT_EQ(2u, States()->size()); |
| 371 EXPECT_EQ(StatusBubbleMac::kBubbleHidingFadeOut, StateAt(0)); |
| 372 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, StateAt(1)); |
| 373 |
| 374 // Test Hide from kBubbleShown |
| 375 bubble_->SetStatus(L"Status"); |
| 376 States()->clear(); |
| 377 EXPECT_TRUE(States()->empty()); |
| 378 bubble_->Hide(); |
| 379 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 380 EXPECT_EQ(1u, States()->size()); |
| 381 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, StateAt(0)); |
| 382 |
| 383 // Test Hide from kBubbleHidingTimer |
| 384 bubble_->SetStatus(L"Status"); |
| 385 SetState(StatusBubbleMac::kBubbleHidingTimer); |
| 386 States()->clear(); |
| 387 EXPECT_TRUE(States()->empty()); |
| 388 bubble_->Hide(); |
| 389 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 390 EXPECT_EQ(1u, States()->size()); |
| 391 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, StateAt(0)); |
| 392 |
| 393 // Test Hide from kBubbleHidingFadeOut |
| 394 bubble_->SetStatus(L"Status"); |
| 395 SetState(StatusBubbleMac::kBubbleHidingFadeOut); |
| 396 [GetWindow() setAlphaValue:0.5]; |
| 397 States()->clear(); |
| 398 EXPECT_TRUE(States()->empty()); |
| 399 bubble_->Hide(); |
| 400 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, GetState()); |
| 401 EXPECT_EQ(1u, States()->size()); |
| 402 EXPECT_EQ(StatusBubbleMac::kBubbleHidden, StateAt(0)); |
| 403 } |
| 404 |
109 TEST_F(StatusBubbleMacTest, MouseMove) { | 405 TEST_F(StatusBubbleMacTest, MouseMove) { |
110 // TODO(pinkerton): Not sure what to do here since it relies on | 406 // TODO(pinkerton): Not sure what to do here since it relies on |
111 // [NSEvent currentEvent] and the current mouse location. | 407 // [NSEvent currentEvent] and the current mouse location. |
112 } | 408 } |
113 | 409 |
114 TEST_F(StatusBubbleMacTest, Delete) { | 410 TEST_F(StatusBubbleMacTest, Delete) { |
115 NSWindow* window = cocoa_helper_.window(); | 411 NSWindow* window = cocoa_helper_.window(); |
116 // Create and delete immediately. | 412 // Create and delete immediately. |
117 StatusBubbleMac* bubble = new StatusBubbleMac(window, nil); | 413 StatusBubbleMac* bubble = new StatusBubbleMac(window, nil); |
118 delete bubble; | 414 delete bubble; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 frame.size.width += 50.0; // (fairly arbitrary nonzero value) | 457 frame.size.width += 50.0; // (fairly arbitrary nonzero value) |
162 frame.size.height += 50.0; // (fairly arbitrary nonzero value) | 458 frame.size.height += 50.0; // (fairly arbitrary nonzero value) |
163 [window setFrame:frame display:YES]; | 459 [window setFrame:frame display:YES]; |
164 bubble_->UpdateSizeAndPosition(); | 460 bubble_->UpdateSizeAndPosition(); |
165 rect_after = [GetWindow() frame]; | 461 rect_after = [GetWindow() frame]; |
166 EXPECT_EQ(rect_before.origin.x, rect_after.origin.x); | 462 EXPECT_EQ(rect_before.origin.x, rect_after.origin.x); |
167 EXPECT_EQ(rect_before.origin.y, rect_after.origin.y); | 463 EXPECT_EQ(rect_before.origin.y, rect_after.origin.y); |
168 EXPECT_NE(rect_before.size.width, rect_after.size.width); | 464 EXPECT_NE(rect_before.size.width, rect_after.size.width); |
169 EXPECT_EQ(rect_before.size.height, rect_after.size.height); | 465 EXPECT_EQ(rect_before.size.height, rect_after.size.height); |
170 } | 466 } |
OLD | NEW |