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

Unified Diff: chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller_unittest.mm

Issue 8332008: Cocoa: Support keyboard navigation in avatar menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller_unittest.mm
index 5f5e2a0c79d2eb0ffd7c3c20cb74b97b4b41983f..909e0024a33776119a917eb935129263d3093be3 100644
--- a/chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller_unittest.mm
@@ -15,6 +15,7 @@
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "testing/gtest_mac.h"
+#include "ui/base/test/cocoa_test_event_utils.h"
class FakeBridge : public AvatarMenuModelObserver {
public:
@@ -51,6 +52,14 @@ class AvatarMenuBubbleControllerTest : public CocoaTest {
AvatarMenuModel* model() { return model_; }
FakeBridge* bridge() { return bridge_; }
+ AvatarMenuItemController* GetHighlightedItem() {
+ for (AvatarMenuItemController* item in [controller() items]) {
+ if ([item isHighlighted])
+ return item;
+ }
+ return nil;
+ }
+
private:
TestingProfileManager manager_;
@@ -178,26 +187,62 @@ TEST_F(AvatarMenuBubbleControllerTest, HighlightForEventType) {
NSView* emailField = [item emailField];
// The edit link remains hidden.
- [item highlightForEventType:NSMouseEntered];
+ [item setIsHighlighted:YES];
EXPECT_TRUE(editButton.isHidden);
EXPECT_FALSE(emailField.isHidden);
- [item highlightForEventType:NSMouseExited];
+ [item setIsHighlighted:NO];
EXPECT_TRUE(editButton.isHidden);
EXPECT_FALSE(emailField.isHidden);
// Make the item "active" and re-test.
[[item activeView] setHidden:NO];
- [item highlightForEventType:NSMouseEntered];
+ [item setIsHighlighted:YES];
[item runMessagePump];
EXPECT_FALSE(editButton.isHidden);
EXPECT_TRUE(emailField.isHidden);
- [item highlightForEventType:NSMouseExited];
+ [item setIsHighlighted:NO];
[item runMessagePump];
EXPECT_TRUE(editButton.isHidden);
EXPECT_FALSE(emailField.isHidden);
}
+
+TEST_F(AvatarMenuBubbleControllerTest, DownArrow) {
+ EXPECT_NSEQ(nil, GetHighlightedItem());
+
+ NSEvent* event =
+ cocoa_test_event_utils::KeyEventWithCharacter(NSDownArrowFunctionKey);
+ // Going down with no item selected should start the selection at the first
+ // item.
+ [controller() keyDown:event];
+ EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem());
+
+ [controller() keyDown:event];
+ EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem());
+
+ // There are no more items now so going down should stay at the last item.
+ [controller() keyDown:event];
+ EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem());
+}
+
+TEST_F(AvatarMenuBubbleControllerTest, UpArrow) {
+ EXPECT_NSEQ(nil, GetHighlightedItem());
+
+ NSEvent* event =
+ cocoa_test_event_utils::KeyEventWithCharacter(NSUpArrowFunctionKey);
+ // Going up with no item selected should start the selection at the last
+ // item.
+ [controller() keyDown:event];
+ EXPECT_EQ([[controller() items] objectAtIndex:0], GetHighlightedItem());
+
+ [controller() keyDown:event];
+ EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem());
+
+ // There are no more items now so going up should stay at the first item.
+ [controller() keyDown:event];
+ EXPECT_EQ([[controller() items] objectAtIndex:1], GetHighlightedItem());
+}
« no previous file with comments | « chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.mm ('k') | ui/base/test/cocoa_test_event_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698