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

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

Issue 1411733009: Bulk rename files in chrome/browser/ui/cocoa/passwords/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-federation
Patch Set: Created 5 years, 1 month 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
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 "base/mac/scoped_objc_class_swizzler.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_window.h"
9 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
10 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
11 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
12 #include "chrome/browser/ui/cocoa/location_bar/manage_passwords_decoration.h"
13 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_cocoa.h"
14 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_controller.h "
15 #include "chrome/browser/ui/cocoa/passwords/manage_passwords_bubble_pending_view _controller.h"
16 #include "chrome/browser/ui/passwords/manage_passwords_test.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "content/public/test/test_utils.h"
19 #include "testing/gtest_mac.h"
20
21 // A helper class to swizzle [NSWindow isKeyWindow] to always return true.
22 @interface AlwaysKeyNSWindow : NSWindow
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 void SetUpOnMainThread() override {
36 ManagePasswordsTest::SetUpOnMainThread();
37 browser()->window()->Show();
38 }
39
40 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 base::mac::ScopedObjCClassSwizzler swizzler(
54 [NSWindow class], [AlwaysKeyNSWindow class], @selector(isKeyWindow));
55 block();
56 }
57
58 void DisableAnimationsOnController() {
59 InfoBubbleWindow* window =
60 base::mac::ObjCCast<InfoBubbleWindow>([controller() window]);
61 [window setAllowedAnimations:info_bubble::kAnimateNone];
62 }
63
64 ManagePasswordsDecoration* decoration() {
65 NSWindow* window = browser()->window()->GetNativeWindow();
66 BrowserWindowController* bwc =
67 [BrowserWindowController browserWindowControllerForWindow:window];
68 return [bwc locationBarBridge]->manage_passwords_decoration();
69 }
70
71 ManagePasswordsIcon* view() override { return decoration()->icon(); }
72 };
73
74 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest,
75 PasswordEntryShowsPendingSaveView) {
76 EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance());
77 DoWithSwizzledNSWindow(^{ SetupPendingPassword(); });
78 EXPECT_TRUE(ManagePasswordsBubbleCocoa::instance());
79 EXPECT_EQ([ManagePasswordsBubblePendingViewController class],
80 [controller().currentController class]);
81 EXPECT_TRUE(view()->active());
82 }
83
84 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, IconClickTogglesBubble) {
85 // Show the bubble automatically.
86 DoWithSwizzledNSWindow(^{ SetupPendingPassword(); });
87
88 // Close the bubble by clicking on the decoration.
89 DisableAnimationsOnController();
90 decoration()->OnMousePressed(NSZeroRect, NSZeroPoint);
91 EXPECT_FALSE(ManagePasswordsBubbleCocoa::instance());
92
93 // Show the bubble by clicking on the decoration.
94 DoWithSwizzledNSWindow(^{
95 decoration()->OnMousePressed(NSZeroRect, NSZeroPoint);
96 });
97 EXPECT_TRUE(ManagePasswordsBubbleCocoa::instance());
98 }
99
100 IN_PROC_BROWSER_TEST_F(ManagePasswordsBubbleTest, TabChangeTogglesIcon) {
101 // Show the bubble (and icon) automatically.
102 DoWithSwizzledNSWindow(^{ SetupPendingPassword(); });
103 EXPECT_TRUE(decoration()->IsVisible());
104
105 // Open a new tab.
106 int firstTab = browser()->tab_strip_model()->active_index();
107 AddTabAtIndex(
108 firstTab + 1, GURL("http://foo.bar/"), ui::PAGE_TRANSITION_TYPED);
109 EXPECT_FALSE(decoration()->IsVisible());
110
111 // Switch back to the previous tab.
112 browser()->tab_strip_model()->ActivateTabAt(firstTab, true);
113 EXPECT_TRUE(decoration()->IsVisible());
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698