| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #import "base/mac/foundation_util.h" | 6 #import "base/mac/foundation_util.h" |
| 7 #import "base/mac/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 10 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" | 10 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 base::scoped_nsobject<WindowObserver> windowObserver( | 110 base::scoped_nsobject<WindowObserver> windowObserver( |
| 111 [[WindowObserver alloc] initWithWindow:[bubble window]]); | 111 [[WindowObserver alloc] initWithWindow:[bubble window]]); |
| 112 EXPECT_FALSE([windowObserver windowIsClosing]); | 112 EXPECT_FALSE([windowObserver windowIsClosing]); |
| 113 | 113 |
| 114 // Find the appropriate button to click. | 114 // Find the appropriate button to click. |
| 115 NSButton* button = nil; | 115 NSButton* button = nil; |
| 116 switch (expected_action) { | 116 switch (expected_action) { |
| 117 case ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE: | 117 case ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE: |
| 118 button = [bubble actionButton]; | 118 button = [bubble actionButton]; |
| 119 break; | 119 break; |
| 120 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS: | 120 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION: |
| 121 button = [bubble dismissButton]; | 121 button = [bubble dismissButton]; |
| 122 break; | 122 break; |
| 123 case ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE: | 123 case ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE: |
| 124 button = [bubble learnMoreButton]; | 124 button = [bubble learnMoreButton]; |
| 125 break; | 125 break; |
| 126 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION: |
| 127 NOTREACHED(); // Deactivation is tested below. |
| 128 break; |
| 126 } | 129 } |
| 127 ASSERT_TRUE(button); | 130 ASSERT_TRUE(button); |
| 128 | 131 |
| 129 // Click the button. | 132 // Click the button. |
| 130 std::pair<NSEvent*, NSEvent*> events = | 133 std::pair<NSEvent*, NSEvent*> events = |
| 131 cocoa_test_event_utils::MouseClickInView(button, 1); | 134 cocoa_test_event_utils::MouseClickInView(button, 1); |
| 132 [NSApp postEvent:events.second atStart:YES]; | 135 [NSApp postEvent:events.second atStart:YES]; |
| 133 [NSApp sendEvent:events.first]; | 136 [NSApp sendEvent:events.first]; |
| 134 chrome::testing::NSRunLoopRunAllPending(); | 137 chrome::testing::NSRunLoopRunAllPending(); |
| 135 | 138 |
| 136 // The bubble should be closed, and the delegate should be told that the | 139 // The bubble should be closed, and the delegate should be told that the |
| 137 // button was clicked. | 140 // button was clicked. |
| 138 ASSERT_TRUE(delegate.close_action()); | 141 ASSERT_TRUE(delegate.close_action()); |
| 139 EXPECT_EQ(expected_action, *delegate.close_action()); | 142 EXPECT_EQ(expected_action, *delegate.close_action()); |
| 140 EXPECT_TRUE([windowObserver windowIsClosing]); | 143 EXPECT_TRUE([windowObserver windowIsClosing]); |
| 141 } | 144 } |
| 142 | 145 |
| 143 // Test clicking on the action button and dismissing the bubble. | 146 // Test clicking on the action button and dismissing the bubble. |
| 144 TEST_F(ToolbarActionsBarBubbleMacTest, CloseActionAndDismiss) { | 147 TEST_F(ToolbarActionsBarBubbleMacTest, CloseActionAndDismiss) { |
| 145 // Test all the possible actions. | 148 // Test all the possible actions. |
| 146 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); | 149 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); |
| 147 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS); | 150 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); |
| 148 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); | 151 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); |
| 149 | 152 |
| 150 { | 153 { |
| 151 // Test dismissing the bubble without clicking the button. | 154 // Test dismissing the bubble without clicking the button. |
| 152 TestToolbarActionsBarBubbleDelegate delegate( | 155 TestToolbarActionsBarBubbleDelegate delegate( |
| 153 HeadingString(), BodyString(), ActionString()); | 156 HeadingString(), BodyString(), ActionString()); |
| 154 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); | 157 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); |
| 155 base::scoped_nsobject<WindowObserver> windowObserver( | 158 base::scoped_nsobject<WindowObserver> windowObserver( |
| 156 [[WindowObserver alloc] initWithWindow:[bubble window]]); | 159 [[WindowObserver alloc] initWithWindow:[bubble window]]); |
| 157 EXPECT_FALSE([windowObserver windowIsClosing]); | 160 EXPECT_FALSE([windowObserver windowIsClosing]); |
| 158 | 161 |
| 159 // Close the bubble. The delegate should be told it was dismissed. | 162 // Close the bubble. The delegate should be told it was dismissed. |
| 160 [bubble close]; | 163 [bubble close]; |
| 161 chrome::testing::NSRunLoopRunAllPending(); | 164 chrome::testing::NSRunLoopRunAllPending(); |
| 162 ASSERT_TRUE(delegate.close_action()); | 165 ASSERT_TRUE(delegate.close_action()); |
| 163 EXPECT_EQ(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS, | 166 EXPECT_EQ(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION, |
| 164 *delegate.close_action()); | 167 *delegate.close_action()); |
| 165 EXPECT_TRUE([windowObserver windowIsClosing]); | 168 EXPECT_TRUE([windowObserver windowIsClosing]); |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 | 171 |
| 169 // Test the basic layout of the bubble. | 172 // Test the basic layout of the bubble. |
| 170 TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { | 173 TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { |
| 171 // Test with no optional fields. | 174 // Test with no optional fields. |
| 172 { | 175 { |
| 173 TestToolbarActionsBarBubbleDelegate delegate( | 176 TestToolbarActionsBarBubbleDelegate delegate( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); | 241 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); |
| 239 EXPECT_TRUE([bubble actionButton]); | 242 EXPECT_TRUE([bubble actionButton]); |
| 240 EXPECT_TRUE([bubble learnMoreButton]); | 243 EXPECT_TRUE([bubble learnMoreButton]); |
| 241 EXPECT_TRUE([bubble dismissButton]); | 244 EXPECT_TRUE([bubble dismissButton]); |
| 242 EXPECT_TRUE([bubble itemList]); | 245 EXPECT_TRUE([bubble itemList]); |
| 243 | 246 |
| 244 [bubble close]; | 247 [bubble close]; |
| 245 chrome::testing::NSRunLoopRunAllPending(); | 248 chrome::testing::NSRunLoopRunAllPending(); |
| 246 } | 249 } |
| 247 } | 250 } |
| OLD | NEW |