| 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_USER_ACTION: | 120 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS: |
| 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; | |
| 129 } | 126 } |
| 130 ASSERT_TRUE(button); | 127 ASSERT_TRUE(button); |
| 131 | 128 |
| 132 // Click the button. | 129 // Click the button. |
| 133 std::pair<NSEvent*, NSEvent*> events = | 130 std::pair<NSEvent*, NSEvent*> events = |
| 134 cocoa_test_event_utils::MouseClickInView(button, 1); | 131 cocoa_test_event_utils::MouseClickInView(button, 1); |
| 135 [NSApp postEvent:events.second atStart:YES]; | 132 [NSApp postEvent:events.second atStart:YES]; |
| 136 [NSApp sendEvent:events.first]; | 133 [NSApp sendEvent:events.first]; |
| 137 chrome::testing::NSRunLoopRunAllPending(); | 134 chrome::testing::NSRunLoopRunAllPending(); |
| 138 | 135 |
| 139 // The bubble should be closed, and the delegate should be told that the | 136 // The bubble should be closed, and the delegate should be told that the |
| 140 // button was clicked. | 137 // button was clicked. |
| 141 ASSERT_TRUE(delegate.close_action()); | 138 ASSERT_TRUE(delegate.close_action()); |
| 142 EXPECT_EQ(expected_action, *delegate.close_action()); | 139 EXPECT_EQ(expected_action, *delegate.close_action()); |
| 143 EXPECT_TRUE([windowObserver windowIsClosing]); | 140 EXPECT_TRUE([windowObserver windowIsClosing]); |
| 144 } | 141 } |
| 145 | 142 |
| 146 // Test clicking on the action button and dismissing the bubble. | 143 // Test clicking on the action button and dismissing the bubble. |
| 147 TEST_F(ToolbarActionsBarBubbleMacTest, CloseActionAndDismiss) { | 144 TEST_F(ToolbarActionsBarBubbleMacTest, CloseActionAndDismiss) { |
| 148 // Test all the possible actions. | 145 // Test all the possible actions. |
| 149 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); | 146 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); |
| 150 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); | 147 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS); |
| 151 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); | 148 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); |
| 152 | 149 |
| 153 { | 150 { |
| 154 // Test dismissing the bubble without clicking the button. | 151 // Test dismissing the bubble without clicking the button. |
| 155 TestToolbarActionsBarBubbleDelegate delegate( | 152 TestToolbarActionsBarBubbleDelegate delegate( |
| 156 HeadingString(), BodyString(), ActionString()); | 153 HeadingString(), BodyString(), ActionString()); |
| 157 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); | 154 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); |
| 158 base::scoped_nsobject<WindowObserver> windowObserver( | 155 base::scoped_nsobject<WindowObserver> windowObserver( |
| 159 [[WindowObserver alloc] initWithWindow:[bubble window]]); | 156 [[WindowObserver alloc] initWithWindow:[bubble window]]); |
| 160 EXPECT_FALSE([windowObserver windowIsClosing]); | 157 EXPECT_FALSE([windowObserver windowIsClosing]); |
| 161 | 158 |
| 162 // Close the bubble. The delegate should be told it was dismissed. | 159 // Close the bubble. The delegate should be told it was dismissed. |
| 163 [bubble close]; | 160 [bubble close]; |
| 164 chrome::testing::NSRunLoopRunAllPending(); | 161 chrome::testing::NSRunLoopRunAllPending(); |
| 165 ASSERT_TRUE(delegate.close_action()); | 162 ASSERT_TRUE(delegate.close_action()); |
| 166 EXPECT_EQ(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION, | 163 EXPECT_EQ(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS, |
| 167 *delegate.close_action()); | 164 *delegate.close_action()); |
| 168 EXPECT_TRUE([windowObserver windowIsClosing]); | 165 EXPECT_TRUE([windowObserver windowIsClosing]); |
| 169 } | 166 } |
| 170 } | 167 } |
| 171 | 168 |
| 172 // Test the basic layout of the bubble. | 169 // Test the basic layout of the bubble. |
| 173 TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { | 170 TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { |
| 174 // Test with no optional fields. | 171 // Test with no optional fields. |
| 175 { | 172 { |
| 176 TestToolbarActionsBarBubbleDelegate delegate( | 173 TestToolbarActionsBarBubbleDelegate delegate( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); | 238 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); |
| 242 EXPECT_TRUE([bubble actionButton]); | 239 EXPECT_TRUE([bubble actionButton]); |
| 243 EXPECT_TRUE([bubble learnMoreButton]); | 240 EXPECT_TRUE([bubble learnMoreButton]); |
| 244 EXPECT_TRUE([bubble dismissButton]); | 241 EXPECT_TRUE([bubble dismissButton]); |
| 245 EXPECT_TRUE([bubble itemList]); | 242 EXPECT_TRUE([bubble itemList]); |
| 246 | 243 |
| 247 [bubble close]; | 244 [bubble close]; |
| 248 chrome::testing::NSRunLoopRunAllPending(); | 245 chrome::testing::NSRunLoopRunAllPending(); |
| 249 } | 246 } |
| 250 } | 247 } |
| OLD | NEW |