| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_pump_mac.h" | 9 #include "base/message_loop/message_pump_mac.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/prefs/pref_service_syncable.h" | 11 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 11 #include "chrome/browser/profiles/avatar_menu_model.h" | 12 #include "chrome/browser/profiles/avatar_menu_model.h" |
| 12 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 13 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
| 13 #include "chrome/browser/profiles/profile_info_cache.h" | 14 #include "chrome/browser/profiles/profile_info_cache.h" |
| 14 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 15 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
| 17 #include "testing/gtest_mac.h" | 18 #include "testing/gtest_mac.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 136 } |
| 136 | 137 |
| 137 [controller() close]; | 138 [controller() close]; |
| 138 } | 139 } |
| 139 | 140 |
| 140 // This subclass is used to inject a delegate into the hide/show edit link | 141 // This subclass is used to inject a delegate into the hide/show edit link |
| 141 // animation. | 142 // animation. |
| 142 @interface TestingAvatarMenuItemController : AvatarMenuItemController | 143 @interface TestingAvatarMenuItemController : AvatarMenuItemController |
| 143 <NSAnimationDelegate> { | 144 <NSAnimationDelegate> { |
| 144 @private | 145 @private |
| 145 scoped_refptr<base::MessagePumpNSRunLoop> pump_; | 146 scoped_ptr<base::MessagePumpNSRunLoop> pump_; |
| 146 } | 147 } |
| 147 // After calling |-highlightForEventType:| an animation will possibly be | 148 // After calling |-highlightForEventType:| an animation will possibly be |
| 148 // started. Since the animation is non-blocking, the run loop will need to be | 149 // started. Since the animation is non-blocking, the run loop will need to be |
| 149 // spun (via the MessagePump) until the animation has finished. | 150 // spun (via the MessagePump) until the animation has finished. |
| 150 - (void)runMessagePump; | 151 - (void)runMessagePump; |
| 151 @end | 152 @end |
| 152 | 153 |
| 153 @implementation TestingAvatarMenuItemController | 154 @implementation TestingAvatarMenuItemController |
| 154 - (void)runMessagePump { | 155 - (void)runMessagePump { |
| 155 if (!pump_.get()) | 156 if (!pump_) |
| 156 pump_ = new base::MessagePumpNSRunLoop; | 157 pump_.reset(new base::MessagePumpNSRunLoop); |
| 157 pump_->Run(NULL); | 158 pump_->Run(NULL); |
| 158 } | 159 } |
| 159 | 160 |
| 160 - (void)willStartAnimation:(NSAnimation*)anim { | 161 - (void)willStartAnimation:(NSAnimation*)anim { |
| 161 [anim setDelegate:self]; | 162 [anim setDelegate:self]; |
| 162 } | 163 } |
| 163 | 164 |
| 164 - (void)animationDidEnd:(NSAnimation*)anim { | 165 - (void)animationDidEnd:(NSAnimation*)anim { |
| 165 [super animationDidEnd:anim]; | 166 [super animationDidEnd:anim]; |
| 166 pump_->Quit(); | 167 pump_->Quit(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 [controller() keyDown:event]; | 254 [controller() keyDown:event]; |
| 254 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); | 255 EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem()); |
| 255 | 256 |
| 256 [controller() keyDown:event]; | 257 [controller() keyDown:event]; |
| 257 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 258 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
| 258 | 259 |
| 259 // There are no more items now so going up should stay at the first item. | 260 // There are no more items now so going up should stay at the first item. |
| 260 [controller() keyDown:event]; | 261 [controller() keyDown:event]; |
| 261 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); | 262 EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem()); |
| 262 } | 263 } |
| OLD | NEW |