Chromium Code Reviews| Index: chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_browsertest.mm |
| diff --git a/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_browsertest.mm b/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_browsertest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1ee7cb651a0e85ce7f1b86c58628ab095b32d794 |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_browsertest.mm |
| @@ -0,0 +1,88 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/mac/foundation_util.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_window.h" |
| +#import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| +#import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| +#include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| +#include "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h" |
| +#include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h" |
| +#include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h" |
| +#include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view_controller.h" |
| +#include "chrome/browser/ui/passwords/manage_passwords_test.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "testing/gtest_mac.h" |
| +#include "ui/events/test/cocoa_test_event_utils.h" |
| + |
| +// A helper class to swizzle [NSWindow isKeyWindow] to always return true. |
| +@interface AlwaysKeyNSWindow : NSObject |
|
Scott Hess - ex-Googler
2014/08/05 17:41:01
The use of this is kind of ... terrifying, but I c
dconnelly
2014/08/06 12:46:12
Done.
|
| +- (BOOL)isKeyWindow; |
| +@end |
| + |
| +@implementation AlwaysKeyNSWindow |
| +- (BOOL)isKeyWindow { |
| + return YES; |
| +} |
| +@end |
| + |
| +// Integration tests for the Mac password bubble. |
| +class ManagePasswordsBubbleTest : public ManagePasswordsTest { |
| + public: |
| + virtual void SetUpOnMainThread() OVERRIDE { |
| + ManagePasswordsTest::SetUpOnMainThread(); |
| + browser()->window()->Show(); |
| + } |
| + |
| + virtual void TearDownOnMainThread() OVERRIDE { |
| + ManagePasswordsTest::TearDownOnMainThread(); |
| + } |
| + |
| + ManagePasswordsBubbleController* controller() { |
| + return ManagePasswordsBubbleCocoa::instance() |
| + ? ManagePasswordsBubbleCocoa::instance()->controller_ |
| + : nil; |
| + } |
| + |
| + void DoWithSwizzledNSWindow(void (^block)(void)) { |
| + // Swizzle [NSWindow isKeyWindow] so that BrowserWindow::IsActive will |
| + // return true and the bubble can be displayed. |
| + ScopedClassSwizzler swizzler( |
| + [NSWindow class], [AlwaysKeyNSWindow class], @selector(isKeyWindow)); |
| + block(); |
| + } |
| + |
| + virtual ManagePasswordsIcon* view() OVERRIDE { |
| + NSWindow* window = browser()->window()->GetNativeWindow(); |
| + BrowserWindowController* bwc = |
| + [BrowserWindowController browserWindowControllerForWindow:window]; |
| + return [bwc locationBarBridge]->manage_passwords_decoration()->icon(); |
| + } |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, |
| + PasswordEntryShowsPendingSaveView) { |
| + EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance()); |
| + DoWithSwizzledNSWindow(^{ SetupPendingPassword(); }); |
| + EXPECT_TRUE(ManagePasswordsBubbleCocoa::instance()); |
| + EXPECT_EQ([ManagePasswordsBubblePendingViewController class], |
| + [controller().currentController class]); |
| + EXPECT_TRUE(view()->active()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, |
| + IconInactiveStateDismissesBubble) { |
| + DoWithSwizzledNSWindow(^{ SetupPendingPassword(); }); |
| + EXPECT_TRUE(ManagePasswordsBubbleCocoa::instance()); |
| + |
| + // Disable animations so that the bubbles close immediately. |
| + InfoBubbleWindow* window = |
| + base::mac::ObjCCast<InfoBubbleWindow>([controller() window]); |
| + [window setAllowedAnimations:info_bubble::kAnimateNone]; |
| + |
| + view()->SetState(password_manager::ui::INACTIVE_STATE); |
| + EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance()); |
| +} |