1 // Copyright (c) 2012 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.
5 #import "chrome/browser/ui/cocoa/exclusive_access_bubble_window_controller.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/site_instance.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/test_utils.h"
19 #include "testing/gtest_mac.h"
20 #include "ui/base/accelerators/platform_accelerator_cocoa.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/l10n/l10n_util_mac.h"
23 #import "ui/base/cocoa/controls/hyperlink_text_view.h"
25 using content::SiteInstance;
26 using content::WebContents;
28 @interface ExclusiveAccessBubbleWindowController (JustForTesting)
30 + (NSString*)keyCommandString;
31 + (NSString*)keyCombinationForAccelerator:
32 (const ui::PlatformAcceleratorCocoa&)item;
33 - (void)initializeLabelAndButton;
36 @interface ExclusiveAccessBubbleWindowController (ExposedForTesting)
37 - (NSTextField*)exitLabelPlaceholder;
38 - (NSTextView*)exitLabel;
39 - (NSString*)denyButtonText;
42 @implementation ExclusiveAccessBubbleWindowController (ExposedForTesting)
43 - (NSTextField*)exitLabelPlaceholder {
44 return exitLabelPlaceholder_;
47 - (HyperlinkTextView*)exitLabel {
51 - (NSString*)denyButtonText {
52 return [denyButton_ title];
56 class ExclusiveAccessBubbleWindowControllerTest : public CocoaProfileTest {
58 void SetUp() override {
59 CocoaProfileTest::SetUp();
60 ASSERT_TRUE(profile());
62 site_instance_ = SiteInstance::Create(profile());
63 controller_.reset([[ExclusiveAccessBubbleWindowController alloc]
65 exclusive_access_manager:browser()->exclusive_access_manager()
66 profile:browser()->profile()
69 EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]);
70 EXPECT_TRUE([controller_ window]);
73 void TearDown() override {
76 CocoaProfileTest::TearDown();
79 void AppendTabToStrip() {
80 WebContents* web_contents = WebContents::Create(
81 content::WebContents::CreateParams(profile(), site_instance_.get()));
82 browser()->tab_strip_model()->AppendWebContents(web_contents,
86 scoped_refptr<SiteInstance> site_instance_;
87 base::scoped_nsobject<ExclusiveAccessBubbleWindowController> controller_;
90 // http://crbug.com/103912
91 TEST_F(ExclusiveAccessBubbleWindowControllerTest,
92 DISABLED_DenyExitsFullscreen) {
93 NSWindow* window = browser()->window()->GetNativeWindow();
94 BrowserWindowController* bwc =
95 [BrowserWindowController browserWindowControllerForWindow:window];
100 WebContents* fullscreen_tab =
101 browser()->tab_strip_model()->GetActiveWebContents();
103 base::mac::ScopedNSAutoreleasePool pool;
104 content::WindowedNotificationObserver fullscreen_observer(
105 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
106 content::NotificationService::AllSources());
107 browser()->EnterFullscreenModeForTab(fullscreen_tab, GURL());
108 fullscreen_observer.Wait();
109 ASSERT_TRUE(browser()->window()->IsFullscreen());
112 ExclusiveAccessBubbleWindowController* bubble =
113 [bwc exclusiveAccessBubbleWindowController];
116 content::WindowedNotificationObserver fullscreen_observer(
117 chrome::NOTIFICATION_FULLSCREEN_CHANGED,
118 content::NotificationService::AllSources());
120 fullscreen_observer.Wait();
122 EXPECT_FALSE([bwc exclusiveAccessBubbleWindowController]);
123 EXPECT_FALSE(browser()->window()->IsFullscreen());
124 CloseBrowserWindow();
127 TEST_F(ExclusiveAccessBubbleWindowControllerTest, LabelWasReplaced) {
128 EXPECT_FALSE([controller_ exitLabelPlaceholder]);
129 EXPECT_TRUE([controller_ exitLabel]);
132 TEST_F(ExclusiveAccessBubbleWindowControllerTest, ShortcutText) {
133 ui::PlatformAcceleratorCocoa cmd_F(@"F", NSCommandKeyMask);
134 ui::PlatformAcceleratorCocoa cmd_shift_f(@"f",
135 NSCommandKeyMask | NSShiftKeyMask);
136 NSString* cmd_F_text = [ExclusiveAccessBubbleWindowController
137 keyCombinationForAccelerator:cmd_F];
138 NSString* cmd_shift_f_text = [ExclusiveAccessBubbleWindowController
139 keyCombinationForAccelerator:cmd_shift_f];
140 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text);
141 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text);
144 // http://crbug.com/139944
145 TEST_F(ExclusiveAccessBubbleWindowControllerTest, DenyButtonText) {
146 controller_.reset([[ExclusiveAccessBubbleWindowController alloc]
148 exclusive_access_manager:browser()->exclusive_access_manager()
149 profile:browser()->profile()
151 bubbleType:EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS]);
152 [controller_ initializeLabelAndButton];
153 NSString* mouselock_deny_button_text = [controller_ denyButtonText];
154 EXPECT_NSEQ(l10n_util::GetNSString(IDS_FULLSCREEN_DENY),
155 mouselock_deny_button_text);
157 controller_.reset([[ExclusiveAccessBubbleWindowController alloc]
159 exclusive_access_manager:browser()->exclusive_access_manager()
160 profile:browser()->profile()
163 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS]);
164 [controller_ initializeLabelAndButton];
165 NSString* fullscreen_mouselock_deny_button_text =
166 [controller_ denyButtonText];
167 EXPECT_NSEQ(l10n_util::GetNSString(IDS_FULLSCREEN_EXIT),
168 fullscreen_mouselock_deny_button_text);