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

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: Refine unit test. 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
« no previous file with comments | « chrome/browser/ui/cocoa/download/download_item_controller.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b800b9946ab99360a258ce8eca38b07d34ea50e4 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 (this block will execute on the
+ // main thread, on the next pass through the run loop).
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ EXPECT_TRUE([downloadItemButton showingContextMenu]);
+ // Simulate the item's removal from the shelf. Ideally we would call an
+ // actual shelf removal method like [item remove] but the shelf and
+ // download item are mock objects.
+ [downloadItemButton removeFromSuperview];
+ }];
+ // The unit test will stop here until the block causes the DownloadItemButton
+ // to dismiss the menu.
+ [item showContextMenu:nil];
+}
+
+
} // namespace
« 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