Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: ui/views/controls/menu/menu_runner_cocoa_unittest.mm

Issue 1876013002: Fixed potential crash on destroying MenuRunnerImplCocoa. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/controls/menu/menu_runner_impl_cocoa.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/menu/menu_runner_impl_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698