Skip to content

Commit

Permalink
mac: Make ui_base_unittests build with the 10.11 SDK.
Browse files Browse the repository at this point in the history
BUG=517914
R=rsesek@chromium.org

Review URL: https://codereview.chromium.org/1402513002 .

Cr-Commit-Position: refs/heads/master@{#353381}
  • Loading branch information
nico committed Oct 9, 2015
1 parent a951891 commit cc70f74
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
8 changes: 4 additions & 4 deletions ui/app_list/cocoa/test/apps_grid_controller_test_helper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
}

void AppsGridControllerTestHelper::SimulateMouseEnterItemAt(size_t index) {
[[apps_grid_controller_ itemAtIndex:index] mouseEntered:
cocoa_test_event_utils::EnterExitEventWithType(NSMouseEntered)];
[[apps_grid_controller_ itemAtIndex:index]
mouseEntered:cocoa_test_event_utils::EnterEvent()];
}

void AppsGridControllerTestHelper::SimulateMouseExitItemAt(size_t index) {
[[apps_grid_controller_ itemAtIndex:index] mouseExited:
cocoa_test_event_utils::EnterExitEventWithType(NSMouseExited)];
[[apps_grid_controller_ itemAtIndex:index]
mouseExited:cocoa_test_event_utils::ExitEvent()];
}

std::string AppsGridControllerTestHelper::GetViewContent() const {
Expand Down
5 changes: 3 additions & 2 deletions ui/base/cocoa/controls/hover_image_menu_button_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/mac/foundation_util.h"
#import "testing/gtest_mac.h"
#import "ui/base/cocoa/controls/hover_image_menu_button_cell.h"
#include "ui/events/test/cocoa_test_event_utils.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"

namespace ui {
Expand Down Expand Up @@ -157,13 +158,13 @@
EXPECT_FALSE([menu_button_ needsDisplay]);
EXPECT_NSEQ(normal_, [[menu_button_ cell] imageToDraw]);

[menu_button_ mouseEntered:nil];
[menu_button_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
EXPECT_TRUE([menu_button_ needsDisplay]);
EXPECT_NSEQ(hovered_, [[menu_button_ cell] imageToDraw]);
[menu_button_ display];
EXPECT_FALSE([menu_button_ needsDisplay]);

[menu_button_ mouseExited:nil];
[menu_button_ mouseExited:cocoa_test_event_utils::ExitEvent()];
EXPECT_TRUE([menu_button_ needsDisplay]);
EXPECT_NSEQ(normal_, [[menu_button_ cell] imageToDraw]);
[menu_button_ display];
Expand Down
19 changes: 9 additions & 10 deletions ui/base/cocoa/controls/hyperlink_button_cell_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#import "testing/gtest_mac.h"
#include "testing/platform_test.h"
#include "ui/events/test/cocoa_test_event_utils.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"

namespace ui {
Expand Down Expand Up @@ -75,13 +76,11 @@ bool HasUnderlineAttribute(NSDictionary* attributes) {
}

// Test mouse events.
// TODO(rsesek): See if we can synthesize mouse events to more accurately
// test this.
TEST_F(HyperlinkButtonCellTest, MouseHover) {
[[NSCursor disappearingItemCursor] push]; // Set a known state.
[cell_ mouseEntered:nil];
[cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
EXPECT_EQ([NSCursor pointingHandCursor], [NSCursor currentCursor]);
[cell_ mouseExited:nil];
[cell_ mouseExited:cocoa_test_event_utils::ExitEvent()];
EXPECT_EQ([NSCursor disappearingItemCursor], [NSCursor currentCursor]);
[NSCursor pop];
}
Expand All @@ -91,10 +90,10 @@ bool HasUnderlineAttribute(NSDictionary* attributes) {
[cell_ setEnabled:NO];

[[NSCursor disappearingItemCursor] push]; // Set a known state.
[cell_ mouseEntered:nil];
[cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
EXPECT_EQ([NSCursor disappearingItemCursor], [NSCursor currentCursor]);

[cell_ mouseExited:nil];
[cell_ mouseExited:cocoa_test_event_utils::ExitEvent()];
EXPECT_EQ([NSCursor disappearingItemCursor], [NSCursor currentCursor]);
[NSCursor pop];
[NSCursor pop];
Expand All @@ -103,16 +102,16 @@ bool HasUnderlineAttribute(NSDictionary* attributes) {
// Test underline on hover.
TEST_F(HyperlinkButtonCellTest, UnderlineOnHover) {
EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes]));
[cell_ mouseEntered:nil];
[cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes]));
[cell_ mouseExited:nil];
[cell_ mouseExited:cocoa_test_event_utils::ExitEvent()];
EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes]));

[cell_ setUnderlineOnHover:YES];
EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes]));
[cell_ mouseEntered:nil];
[cell_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
EXPECT_TRUE(HasUnderlineAttribute([cell_ linkAttributes]));
[cell_ mouseExited:nil];
[cell_ mouseExited:cocoa_test_event_utils::ExitEvent()];
EXPECT_FALSE(HasUnderlineAttribute([cell_ linkAttributes]));
}

Expand Down
5 changes: 3 additions & 2 deletions ui/base/cocoa/hover_image_button_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "ui/base/cocoa/hover_image_button.h"

#import "base/mac/scoped_nsobject.h"
#include "ui/events/test/cocoa_test_event_utils.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"

namespace {
Expand Down Expand Up @@ -35,10 +36,10 @@ void DrawRect() {
[button_ setDefaultImage:image];
[button_ setHoverImage:hover];

[button_ mouseEntered:nil];
[button_ mouseEntered:cocoa_test_event_utils::EnterEvent()];
DrawRect();
EXPECT_EQ([button_ image], hover);
[button_ mouseExited:nil];
[button_ mouseExited:cocoa_test_event_utils::ExitEvent()];
DrawRect();
EXPECT_NE([button_ image], hover);
EXPECT_EQ([button_ image], image);
Expand Down
4 changes: 3 additions & 1 deletion ui/base/cocoa/menu_controller_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "ui/base/cocoa/menu_controller.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/test/cocoa_test_event_utils.h"
#include "ui/gfx/image/image.h"
#import "ui/gfx/test/ui_cocoa_test_helper.h"
#include "ui/resources/grit/ui_resources.h"
Expand Down Expand Up @@ -372,7 +373,8 @@ void Validate(MenuController* controller, NSMenu* menu) {

// Pop open the menu, which will spin an event-tracking run loop.
[NSMenu popUpContextMenu:[menu menu]
withEvent:nil
withEvent:cocoa_test_event_utils::RightMouseDownAtPoint(
NSZeroPoint)
forView:[test_window() contentView]];

EXPECT_FALSE([menu isMenuOpen]);
Expand Down
4 changes: 2 additions & 2 deletions ui/events/cocoa/events_mac_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ void ClearSwizzle() {
event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0);
EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(event));

event = cocoa_test_event_utils::EnterExitEventWithType(NSMouseEntered);
event = cocoa_test_event_utils::EnterEvent();
EXPECT_EQ(ui::ET_MOUSE_ENTERED, ui::EventTypeFromNative(event));
event = cocoa_test_event_utils::EnterExitEventWithType(NSMouseExited);
event = cocoa_test_event_utils::ExitEvent();
EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(event));
}

Expand Down
7 changes: 5 additions & 2 deletions ui/events/test/cocoa_test_event_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ NSEvent* KeyEventWithKeyCode(unsigned short key_code,
NSEventType event_type,
NSUInteger modifiers);

// Returns a mouse enter/exit event with the given type.
NSEvent* EnterExitEventWithType(NSEventType event_type);
// Returns a mouse enter event.
NSEvent* EnterEvent();

// Returns a mouse exit event.
NSEvent* ExitEvent();

// Return an "other" event with the given type.
NSEvent* OtherEventWithType(NSEventType event_type);
Expand Down
10 changes: 9 additions & 1 deletion ui/events/test/cocoa_test_event_utils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ uint64_t UpTimeInNanoseconds(void) {
keyCode:key_code];
}

NSEvent* EnterExitEventWithType(NSEventType event_type) {
static NSEvent* EnterExitEventWithType(NSEventType event_type) {
return [NSEvent enterExitEventWithType:event_type
location:NSZeroPoint
modifierFlags:0
Expand All @@ -162,6 +162,14 @@ uint64_t UpTimeInNanoseconds(void) {
userData:NULL];
}

NSEvent* EnterEvent() {
return EnterExitEventWithType(NSMouseEntered);
}

NSEvent* ExitEvent() {
return EnterExitEventWithType(NSMouseExited);
}

NSEvent* OtherEventWithType(NSEventType event_type) {
return [NSEvent otherEventWithType:event_type
location:NSZeroPoint
Expand Down

0 comments on commit cc70f74

Please sign in to comment.