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

Side by Side Diff: chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa_browsertest.mm

Issue 2624273003: Add a test for our workaround of an AppKit crash in SFChooseIdentityPanel. (Closed)
Patch Set: Created 3 years, 11 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.h" 5 #import "chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.h"
6 6
7 #import <SecurityInterface/SFChooseIdentityPanel.h> 7 #import <SecurityInterface/SFChooseIdentityPanel.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #import "base/mac/mac_util.h" 10 #import "base/mac/mac_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" 13 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
14 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h" 14 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "components/web_modal/web_contents_modal_dialog_manager.h" 18 #include "components/web_modal/web_contents_modal_dialog_manager.h"
19 #include "content/public/browser/client_certificate_delegate.h" 19 #include "content/public/browser/client_certificate_delegate.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/test_utils.h" 21 #include "content/public/test/test_utils.h"
22 #import "testing/gtest_mac.h" 22 #import "testing/gtest_mac.h"
23 #include "ui/base/cocoa/window_size_constants.h" 23 #include "ui/base/cocoa/window_size_constants.h"
24 24
25 #import <objc/runtime.h>
26
25 using web_modal::WebContentsModalDialogManager; 27 using web_modal::WebContentsModalDialogManager;
26 28
27 namespace { 29 namespace {
28 30
29 class TestClientCertificateDelegate 31 class TestClientCertificateDelegate
30 : public content::ClientCertificateDelegate { 32 : public content::ClientCertificateDelegate {
31 public: 33 public:
32 // Creates a ClientCertificateDelegate that sets |*destroyed| to true on 34 // Creates a ClientCertificateDelegate that sets |*destroyed| to true on
33 // destruction. 35 // destruction.
34 explicit TestClientCertificateDelegate(bool* destroyed) 36 explicit TestClientCertificateDelegate(bool* destroyed)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 AddBlankTabAndShow(browser()); 114 AddBlankTabAndShow(browser());
113 EXPECT_EQ(0.0, [sheetWindow alphaValue]); 115 EXPECT_EQ(0.0, [sheetWindow alphaValue]);
114 EXPECT_TRUE([[selector overlayWindow] ignoresMouseEvents]); 116 EXPECT_TRUE([[selector overlayWindow] ignoresMouseEvents]);
115 117
116 // Switch back and verify that the sheet is shown. Interaction with the tab 118 // Switch back and verify that the sheet is shown. Interaction with the tab
117 // underneath should be blocked while the sheet is showing. 119 // underneath should be blocked while the sheet is showing.
118 chrome::SelectNumberedTab(browser(), 0); 120 chrome::SelectNumberedTab(browser(), 0);
119 EXPECT_EQ(1.0, [sheetWindow alphaValue]); 121 EXPECT_EQ(1.0, [sheetWindow alphaValue]);
120 EXPECT_FALSE([[selector overlayWindow] ignoresMouseEvents]); 122 EXPECT_FALSE([[selector overlayWindow] ignoresMouseEvents]);
121 } 123 }
124
125 @interface TestDeallocWatcher : NSObject
126 @end
127
128 @implementation TestDeallocWatcher {
129 BOOL* wasDeallocated_;
130 }
131
132 + (void)watchTarget:(NSObject*)target andSetFlag:(BOOL*)wasDeallocated {
133 TestDeallocWatcher* watcher = [[TestDeallocWatcher alloc] init];
134 watcher->wasDeallocated_ = wasDeallocated;
135 objc_setAssociatedObject(target, _cmd, watcher,
136 OBJC_ASSOCIATION_RETAIN_NONATOMIC);
137 [watcher release];
138 }
139
140 - (void)dealloc {
141 *wasDeallocated_ = true;
142 [super dealloc];
143 }
144
145 @end
Sidney San Martín 2017/01/11 21:27:03 rsesek@: Maybe there's a simpler way to do this? (
Robert Sesek 2017/01/11 22:03:31 Just a variant of what you're doing here, which is
Sidney San Martín 2017/01/11 22:15:33 That is better. Done.
146
147 // Test that we can't trigger the crash from https://crbug.com/653093
148 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest,
149 WorkaroundCrashySierra) {
150 BOOL selectorWasDeallocated = false;
Sidney San Martín 2017/01/11 21:29:41 I just caught myself not using underscores here :)
151
152 @autoreleasepool {
153 content::WebContents* web_contents =
154 browser()->tab_strip_model()->GetActiveWebContents();
155 SSLClientCertificateSelectorCocoa* selector =
156 [[SSLClientCertificateSelectorCocoa alloc]
157 initWithBrowserContext:web_contents->GetBrowserContext()
158 certRequestInfo:auth_requestor_->cert_request_info_.get()
159 delegate:nil];
160 [selector displayForWebContents:web_contents];
161 content::RunAllPendingInMessageLoop();
162
163 [TestDeallocWatcher watchTarget:selector
164 andSetFlag:&selectorWasDeallocated];
165
166 [selector.overlayWindow endSheet:selector.overlayWindow.attachedSheet];
167 content::RunAllPendingInMessageLoop();
168 }
169
170 EXPECT_TRUE(selectorWasDeallocated);
171
172 // Without the workaround, this will crash on Sierra.
173 [[NSNotificationCenter defaultCenter]
174 postNotificationName:NSPreferredScrollerStyleDidChangeNotification
175 object:nil
176 userInfo:@{
177 @"NSScrollerStyle" : @(NSScrollerStyleLegacy)
178 }];
179 [[NSNotificationCenter defaultCenter]
180 postNotificationName:NSPreferredScrollerStyleDidChangeNotification
181 object:nil
182 userInfo:@{
183 @"NSScrollerStyle" : @(NSScrollerStyleOverlay)
184 }];
185 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698