| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/controls/menu/menu_runner_impl_cocoa.h" | 5 #import "ui/views/controls/menu/menu_runner_impl_cocoa.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 void MenuCancelCallback() { | 130 void MenuCancelCallback() { |
| 131 runner_->Cancel(); | 131 runner_->Cancel(); |
| 132 EXPECT_FALSE(runner_->IsRunning()); | 132 EXPECT_FALSE(runner_->IsRunning()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void MenuDeleteCallback() { | 135 void MenuDeleteCallback() { |
| 136 runner_->Release(); | 136 runner_->Release(); |
| 137 runner_ = nullptr; | 137 runner_ = nullptr; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void MenuCancelAndDeleteCallback() { |
| 141 runner_->Cancel(); |
| 142 runner_->Release(); |
| 143 runner_ = nullptr; |
| 144 } |
| 145 |
| 140 protected: | 146 protected: |
| 141 scoped_ptr<TestModel> menu_; | 147 scoped_ptr<TestModel> menu_; |
| 142 internal::MenuRunnerImplCocoa* runner_ = nullptr; | 148 internal::MenuRunnerImplCocoa* runner_ = nullptr; |
| 143 views::Widget* parent_ = nullptr; | 149 views::Widget* parent_ = nullptr; |
| 144 NSRect last_anchor_frame_ = NSZeroRect; | 150 NSRect last_anchor_frame_ = NSZeroRect; |
| 145 | 151 |
| 146 private: | 152 private: |
| 147 void RunMenuWrapperCallback(const base::Closure& callback) { | 153 void RunMenuWrapperCallback(const base::Closure& callback) { |
| 148 EXPECT_TRUE(runner_->IsRunning()); | 154 EXPECT_TRUE(runner_->IsRunning()); |
| 149 callback.Run(); | 155 callback.Run(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 175 runner_->Cancel(); | 181 runner_->Cancel(); |
| 176 EXPECT_FALSE(runner_->IsRunning()); | 182 EXPECT_FALSE(runner_->IsRunning()); |
| 177 } | 183 } |
| 178 | 184 |
| 179 TEST_F(MenuRunnerCocoaTest, RunMenuAndDelete) { | 185 TEST_F(MenuRunnerCocoaTest, RunMenuAndDelete) { |
| 180 MenuRunner::RunResult result = RunMenu(base::Bind( | 186 MenuRunner::RunResult result = RunMenu(base::Bind( |
| 181 &MenuRunnerCocoaTest::MenuDeleteCallback, base::Unretained(this))); | 187 &MenuRunnerCocoaTest::MenuDeleteCallback, base::Unretained(this))); |
| 182 EXPECT_EQ(MenuRunner::MENU_DELETED, result); | 188 EXPECT_EQ(MenuRunner::MENU_DELETED, result); |
| 183 } | 189 } |
| 184 | 190 |
| 191 // Ensure a menu can be safely released immediately after a call to Cancel() in |
| 192 // the same run loop iteration. |
| 193 TEST_F(MenuRunnerCocoaTest, DestroyAfterCanceling) { |
| 194 MenuRunner::RunResult result = |
| 195 RunMenu(base::Bind(&MenuRunnerCocoaTest::MenuCancelAndDeleteCallback, |
| 196 base::Unretained(this))); |
| 197 EXPECT_EQ(MenuRunner::MENU_DELETED, result); |
| 198 } |
| 199 |
| 185 TEST_F(MenuRunnerCocoaTest, RunMenuTwice) { | 200 TEST_F(MenuRunnerCocoaTest, RunMenuTwice) { |
| 186 for (int i = 0; i < 2; ++i) { | 201 for (int i = 0; i < 2; ++i) { |
| 187 MenuRunner::RunResult result = RunMenu(base::Bind( | 202 MenuRunner::RunResult result = RunMenu(base::Bind( |
| 188 &MenuRunnerCocoaTest::MenuCancelCallback, base::Unretained(this))); | 203 &MenuRunnerCocoaTest::MenuCancelCallback, base::Unretained(this))); |
| 189 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | 204 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); |
| 190 EXPECT_FALSE(runner_->IsRunning()); | 205 EXPECT_FALSE(runner_->IsRunning()); |
| 191 } | 206 } |
| 192 } | 207 } |
| 193 | 208 |
| 194 TEST_F(MenuRunnerCocoaTest, CancelWithoutRunning) { | 209 TEST_F(MenuRunnerCocoaTest, CancelWithoutRunning) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // In RTL, Cocoa messes up the positioning unless the anchor rectangle is | 254 // In RTL, Cocoa messes up the positioning unless the anchor rectangle is |
| 240 // offset to the right of the view. The offset for the checkmark is also | 255 // offset to the right of the view. The offset for the checkmark is also |
| 241 // skipped, to give a better match to native behavior. | 256 // skipped, to give a better match to native behavior. |
| 242 base::i18n::SetICUDefaultLocale("he"); | 257 base::i18n::SetICUDefaultLocale("he"); |
| 243 RunMenuAt(anchor_rect); | 258 RunMenuAt(anchor_rect); |
| 244 EXPECT_EQ(combobox_rect.right(), last_anchor_frame_.origin.x); | 259 EXPECT_EQ(combobox_rect.right(), last_anchor_frame_.origin.x); |
| 245 } | 260 } |
| 246 | 261 |
| 247 } // namespace test | 262 } // namespace test |
| 248 } // namespace views | 263 } // namespace views |
| OLD | NEW |