Chromium Code Reviews| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 | 152 |
| 153 TEST_F(MenuRunnerCocoaTest, RunMenuAndDelete) { | 153 TEST_F(MenuRunnerCocoaTest, RunMenuAndDelete) { |
| 154 MenuRunner::RunResult result = RunMenu(^{ | 154 MenuRunner::RunResult result = RunMenu(^{ |
| 155 runner_->Release(); | 155 runner_->Release(); |
| 156 runner_ = NULL; | 156 runner_ = NULL; |
| 157 }); | 157 }); |
| 158 | 158 |
| 159 EXPECT_EQ(MenuRunner::MENU_DELETED, result); | 159 EXPECT_EQ(MenuRunner::MENU_DELETED, result); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Tests that there is no "use after free" when we canceling menu | |
| 163 // (that causes deferred destructor in MenuRunnerImplCocoa::RunMenuAt()) and | |
| 164 // release it just after canceling (that was cause destructor | |
| 165 // in MenuRunnerImplCocoa::Release()). | |
|
tapted
2016/04/12 06:22:58
this comment is a bit hard to read perhaps
// Ens
| |
| 166 TEST_F(MenuRunnerCocoaTest, DestroyAfterCanceling) { | |
| 167 MenuRunner::RunResult result = RunMenu(^{ | |
|
tapted
2016/04/12 06:22:58
We got rid of all the Objective C blocks in this f
| |
| 168 runner_->Cancel(); | |
| 169 runner_->Release(); | |
|
tapted
2016/04/12 06:22:58
Is there code in Chrome that already follows this
| |
| 170 runner_ = nullptr; | |
| 171 }); | |
| 172 EXPECT_EQ(MenuRunner::MENU_DELETED, result); | |
| 173 } | |
| 174 | |
| 162 TEST_F(MenuRunnerCocoaTest, RunMenuTwice) { | 175 TEST_F(MenuRunnerCocoaTest, RunMenuTwice) { |
| 163 for (int i = 0; i < 2; ++i) { | 176 for (int i = 0; i < 2; ++i) { |
| 164 MenuRunner::RunResult result = RunMenu(^{ | 177 MenuRunner::RunResult result = RunMenu(^{ |
| 165 runner_->Cancel(); | 178 runner_->Cancel(); |
| 166 }); | 179 }); |
| 167 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); | 180 EXPECT_EQ(MenuRunner::NORMAL_EXIT, result); |
| 168 EXPECT_FALSE(runner_->IsRunning()); | 181 EXPECT_FALSE(runner_->IsRunning()); |
| 169 } | 182 } |
| 170 } | 183 } |
| 171 | 184 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 // In RTL, Cocoa messes up the positioning unless the anchor rectangle is | 230 // In RTL, Cocoa messes up the positioning unless the anchor rectangle is |
| 218 // offset to the right of the view. The offset for the checkmark is also | 231 // offset to the right of the view. The offset for the checkmark is also |
| 219 // skipped, to give a better match to native behavior. | 232 // skipped, to give a better match to native behavior. |
| 220 base::i18n::SetICUDefaultLocale("he"); | 233 base::i18n::SetICUDefaultLocale("he"); |
| 221 RunMenuAt(anchor_rect); | 234 RunMenuAt(anchor_rect); |
| 222 EXPECT_EQ(combobox_rect.right(), last_anchor_frame_.origin.x); | 235 EXPECT_EQ(combobox_rect.right(), last_anchor_frame_.origin.x); |
| 223 } | 236 } |
| 224 | 237 |
| 225 } // namespace test | 238 } // namespace test |
| 226 } // namespace views | 239 } // namespace views |
| OLD | NEW |