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

Side by Side Diff: chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_browsertest.mm

Issue 444603003: Hook up the Mac password bubble to the browser and add browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort gypi Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/mac/foundation_util.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/browser_window.h"
8 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
10 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
11 #include "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
12 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h"
13 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h "
14 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view _controller.h"
15 #include "chrome/browser/ui/passwords/manage_passwords_test.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "content/public/test/test_utils.h"
18 #include "testing/gtest_mac.h"
19 #include "ui/events/test/cocoa_test_event_utils.h"
20
21 // A helper class to swizzle [NSWindow isKeyWindow] to always return true.
22 @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.
23 - (BOOL)isKeyWindow;
24 @end
25
26 @implementation AlwaysKeyNSWindow
27 - (BOOL)isKeyWindow {
28 return YES;
29 }
30 @end
31
32 // Integration tests for the Mac password bubble.
33 class ManagePasswordsBubbleTest : public ManagePasswordsTest {
34 public:
35 virtual void SetUpOnMainThread() OVERRIDE {
36 ManagePasswordsTest::SetUpOnMainThread();
37 browser()->window()->Show();
38 }
39
40 virtual void TearDownOnMainThread() OVERRIDE {
41 ManagePasswordsTest::TearDownOnMainThread();
42 }
43
44 ManagePasswordsBubbleController* controller() {
45 return ManagePasswordsBubbleCocoa::instance()
46 ? ManagePasswordsBubbleCocoa::instance()->controller_
47 : nil;
48 }
49
50 void DoWithSwizzledNSWindow(void (^block)(void)) {
51 // Swizzle [NSWindow isKeyWindow] so that BrowserWindow::IsActive will
52 // return true and the bubble can be displayed.
53 ScopedClassSwizzler swizzler(
54 [NSWindow class], [AlwaysKeyNSWindow class], @selector(isKeyWindow));
55 block();
56 }
57
58 virtual ManagePasswordsIcon* view() OVERRIDE {
59 NSWindow* window = browser()->window()->GetNativeWindow();
60 BrowserWindowController* bwc =
61 [BrowserWindowController browserWindowControllerForWindow:window];
62 return [bwc locationBarBridge]->manage_passwords_decoration()->icon();
63 }
64 };
65
66 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest,
67 PasswordEntryShowsPendingSaveView) {
68 EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance());
69 DoWithSwizzledNSWindow(^{ SetupPendingPassword(); });
70 EXPECT_TRUE(ManagePasswordsBubbleCocoa::instance());
71 EXPECT_EQ([ManagePasswordsBubblePendingViewController class],
72 [controller().currentController class]);
73 EXPECT_TRUE(view()->active());
74 }
75
76 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest,
77 IconInactiveStateDismissesBubble) {
78 DoWithSwizzledNSWindow(^{ SetupPendingPassword(); });
79 EXPECT_TRUE(ManagePasswordsBubbleCocoa::instance());
80
81 // Disable animations so that the bubbles close immediately.
82 InfoBubbleWindow* window =
83 base::mac::ObjCCast<InfoBubbleWindow>([controller() window]);
84 [window setAllowedAnimations:info_bubble::kAnimateNone];
85
86 view()->SetState(password_manager::ui::INACTIVE_STATE);
87 EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance());
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698