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

Unified 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: Remove unneeded scoped ptrs. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/download/download_item_controller_unittest.mm
diff --git a/chrome/browser/ui/cocoa/download/download_item_controller_unittest.mm b/chrome/browser/ui/cocoa/download/download_item_controller_unittest.mm
index cf7a98cc8bee7d407c4c62523202b709783aff70..509522564f49fb2988161c4107f375b820a4781b 100644
--- a/chrome/browser/ui/cocoa/download/download_item_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/download/download_item_controller_unittest.mm
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
+#import "chrome/browser/ui/cocoa/download/download_item_button.h"
#import "chrome/browser/ui/cocoa/download/download_item_controller.h"
#import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
#include "content/public/test/mock_download_item.h"
@@ -44,6 +45,13 @@ using ::testing::ReturnRefOfCopy;
- (void)awakeFromNib;
@end
+@interface DownloadItemButton(DownloadItemButtonTest)
+
+- (BOOL)showingContextMenu;
+
+@end
+
+
@implementation DownloadItemControllerWithInitCallback
- (id)initWithDownload:(content::DownloadItem*)downloadItem
@@ -179,4 +187,31 @@ TEST_F(DownloadItemControllerTest, NormalDownloadBecomesDangerous) {
[(id)shelf_ verify];
}
+TEST_F(DownloadItemControllerTest, DismissesContextMenuWhenRemovedFromWindow) {
+ base::scoped_nsobject<DownloadItemController> item(CreateItemController());
+ DownloadItemButton* downloadItemButton = nil;
+ for (NSView *nextSubview in [[item view] subviews]) {
+ if ([nextSubview isKindOfClass:[DownloadItemButton class]]) {
+ downloadItemButton = static_cast<DownloadItemButton *>(nextSubview);
+ break;
+ }
+ }
+ // showContextMenu: calls [NSMenu popUpContextMenu:...], which blocks until
+ // the menu is dismissed. Use a block to cancel the menu while waiting for
+ // [NSMenu popUpContextMenu:...] to return.
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ // Wait a bit to make sure [item showContextMenu:nil] is executing before
+ // proceeding.
+ [NSThread sleepForTimeInterval:0.25];
+ EXPECT_TRUE([downloadItemButton showingContextMenu]);
+ [downloadItemButton
+ performSelectorOnMainThread:@selector(removeFromSuperview)
+ withObject:nil
+ waitUntilDone:NO];
+ }];
+ [item showContextMenu:nil];
+ EXPECT_FALSE([downloadItemButton showingContextMenu]);
+}
+
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698