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

Side by Side Diff: chrome/browser/ui/cocoa/download/download_item_controller_unittest.mm

Issue 1125423002: Dismiss context menu when download bar is closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dismiss context menu using NSMenu API. Created 5 years, 7 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 | « chrome/browser/ui/cocoa/download/download_item_controller.mm ('k') | 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 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
11 #import "chrome/browser/ui/cocoa/download/download_item_button.h"
11 #import "chrome/browser/ui/cocoa/download/download_item_controller.h" 12 #import "chrome/browser/ui/cocoa/download/download_item_controller.h"
12 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" 13 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
13 #include "content/public/test/mock_download_item.h" 14 #include "content/public/test/mock_download_item.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h" 16 #include "testing/platform_test.h"
16 #import "third_party/ocmock/OCMock/OCMock.h" 17 #import "third_party/ocmock/OCMock/OCMock.h"
17 #import "third_party/ocmock/gtest_support.h" 18 #import "third_party/ocmock/gtest_support.h"
18 19
19 using ::testing::Return; 20 using ::testing::Return;
20 using ::testing::ReturnRefOfCopy; 21 using ::testing::ReturnRefOfCopy;
(...skipping 16 matching lines...) Expand all
37 @interface DownloadItemControllerWithInitCallback : DownloadItemController { 38 @interface DownloadItemControllerWithInitCallback : DownloadItemController {
38 @private 39 @private
39 base::Closure initCallback_; 40 base::Closure initCallback_;
40 } 41 }
41 - (id)initWithDownload:(content::DownloadItem*)downloadItem 42 - (id)initWithDownload:(content::DownloadItem*)downloadItem
42 shelf:(DownloadShelfController*)shelf 43 shelf:(DownloadShelfController*)shelf
43 initCallback:(const base::Closure&)callback; 44 initCallback:(const base::Closure&)callback;
44 - (void)awakeFromNib; 45 - (void)awakeFromNib;
45 @end 46 @end
46 47
48 @interface DownloadItemButton(DownloadItemButtonTest)
49
50 - (BOOL)showingContextMenu;
51
52 @end
53
54
47 @implementation DownloadItemControllerWithInitCallback 55 @implementation DownloadItemControllerWithInitCallback
48 56
49 - (id)initWithDownload:(content::DownloadItem*)downloadItem 57 - (id)initWithDownload:(content::DownloadItem*)downloadItem
50 shelf:(DownloadShelfController*)shelf 58 shelf:(DownloadShelfController*)shelf
51 initCallback:(const base::Closure&)callback { 59 initCallback:(const base::Closure&)callback {
52 if ((self = [super initWithDownload:downloadItem shelf:shelf navigator:NULL])) 60 if ((self = [super initWithDownload:downloadItem shelf:shelf navigator:NULL]))
53 initCallback_ = callback; 61 initCallback_ = callback;
54 return self; 62 return self;
55 } 63 }
56 64
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 ON_CALL(*download_item_, GetDangerType()) 180 ON_CALL(*download_item_, GetDangerType())
173 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)); 181 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS));
174 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false)); 182 ON_CALL(*download_item_, IsDangerous()).WillByDefault(Return(false));
175 download_item_->NotifyObserversDownloadUpdated(); 183 download_item_->NotifyObserversDownloadUpdated();
176 184
177 [item verifyProgressViewIsVisible:true]; 185 [item verifyProgressViewIsVisible:true];
178 [item verifyDangerousDownloadPromptIsVisible:false]; 186 [item verifyDangerousDownloadPromptIsVisible:false];
179 [(id)shelf_ verify]; 187 [(id)shelf_ verify];
180 } 188 }
181 189
190 TEST_F(DownloadItemControllerTest, DismissesContextMenuWhenRemovedFromWindow) {
191 base::scoped_nsobject<DownloadItemController> item(CreateItemController());
192 DownloadItemButton* downloadItemButton = nil;
193 for (NSView *nextSubview in [[item view] subviews]) {
194 if ([nextSubview isKindOfClass:[DownloadItemButton class]]) {
195 downloadItemButton = static_cast<DownloadItemButton *>(nextSubview);
196 break;
197 }
198 }
199 // showContextMenu: calls [NSMenu popUpContextMenu:...], which blocks until
200 // the menu is dismissed. Use a block to cancel the menu while waiting for
201 // [NSMenu popUpContextMenu:...] to return.
202 [[NSOperationQueue mainQueue] addOperationWithBlock:^{
203 // Wait a bit to make sure [item showContextMenu:nil] is executing before
204 // proceeding.
205 [NSThread sleepForTimeInterval:0.25];
asanka 2015/05/13 16:58:55 Let's avoid sleeping in tests. Can we schedule a
shrike 2015/05/13 23:25:51 I'm using an NSOperationQueue to execute the code
asanka 2015/05/14 03:31:45 Hm. Tasks posted via PostTask() for the UI message
shrike 2015/05/15 01:07:03 Originally you didn't like the [NSTask sleep] call
asanka 2015/05/15 14:56:11 Is there a new patchset? I'd prefer a PostTask an
shrike 2015/05/15 15:55:51 I think I was waiting on further direction before
shrike 2015/05/15 18:51:49 It looks like the message loop isn't running in th
206 EXPECT_TRUE([downloadItemButton showingContextMenu]);
207 [downloadItemButton
208 performSelectorOnMainThread:@selector(removeFromSuperview)
209 withObject:nil
210 waitUntilDone:NO];
asanka 2015/05/13 16:58:55 The real trigger for the removal of the context me
shrike 2015/05/13 23:25:52 I agree that makes sense. However, it appears that
211 }];
212 [item showContextMenu:nil];
213 EXPECT_FALSE([downloadItemButton showingContextMenu]);
asanka 2015/05/13 16:58:55 Given that this line won't be reached until the co
shrike 2015/05/13 23:25:52 Acknowledged.
214 }
215
216
182 } // namespace 217 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/download/download_item_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698