| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #import "chrome/browser/ui/cocoa/exclusive_access_bubble_window_controller.h" | |
| 6 | |
| 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/exclusive_access_controller_views.h" | |
| 11 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | |
| 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 14 #include "chrome/grit/generated_resources.h" | |
| 15 #include "chrome/test/base/testing_profile.h" | |
| 16 #include "content/public/browser/notification_service.h" | |
| 17 #include "content/public/browser/site_instance.h" | |
| 18 #include "content/public/browser/web_contents.h" | |
| 19 #include "content/public/test/test_utils.h" | |
| 20 #include "testing/gtest_mac.h" | |
| 21 #include "ui/base/accelerators/platform_accelerator_cocoa.h" | |
| 22 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | |
| 23 #include "ui/base/l10n/l10n_util.h" | |
| 24 #include "ui/base/l10n/l10n_util_mac.h" | |
| 25 | |
| 26 using content::SiteInstance; | |
| 27 using content::WebContents; | |
| 28 | |
| 29 @interface ExclusiveAccessBubbleWindowController (JustForTesting) | |
| 30 // Already defined. | |
| 31 + (NSString*)keyCombinationForAccelerator: | |
| 32 (const ui::PlatformAcceleratorCocoa&)item; | |
| 33 - (void)initializeLabelAndButton; | |
| 34 @end | |
| 35 | |
| 36 @interface ExclusiveAccessBubbleWindowController (ExposedForTesting) | |
| 37 - (NSTextField*)exitLabelPlaceholder; | |
| 38 - (NSTextView*)exitLabel; | |
| 39 - (NSString*)denyButtonText; | |
| 40 @end | |
| 41 | |
| 42 @implementation ExclusiveAccessBubbleWindowController (ExposedForTesting) | |
| 43 - (NSTextField*)exitLabelPlaceholder { | |
| 44 return exitLabelPlaceholder_; | |
| 45 } | |
| 46 | |
| 47 - (HyperlinkTextView*)exitLabel { | |
| 48 return exitLabel_; | |
| 49 } | |
| 50 | |
| 51 - (NSString*)denyButtonText { | |
| 52 return [denyButton_ title]; | |
| 53 } | |
| 54 @end | |
| 55 | |
| 56 class ExclusiveAccessBubbleWindowControllerTest : public CocoaProfileTest { | |
| 57 public: | |
| 58 void SetUp() override { | |
| 59 CocoaProfileTest::SetUp(); | |
| 60 ASSERT_TRUE(profile()); | |
| 61 | |
| 62 site_instance_ = SiteInstance::Create(profile()); | |
| 63 controller_.reset([[ExclusiveAccessBubbleWindowController alloc] | |
| 64 initWithOwner:nil | |
| 65 exclusive_access_manager:browser()->exclusive_access_manager() | |
| 66 profile:browser()->profile() | |
| 67 url:GURL() | |
| 68 bubbleType: | |
| 69 EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_I
NSTRUCTION]); | |
| 70 EXPECT_TRUE([controller_ window]); | |
| 71 } | |
| 72 | |
| 73 void TearDown() override { | |
| 74 [controller_ close]; | |
| 75 controller_.reset(); | |
| 76 CocoaProfileTest::TearDown(); | |
| 77 } | |
| 78 | |
| 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, | |
| 83 /*foreground=*/true); | |
| 84 } | |
| 85 | |
| 86 scoped_refptr<SiteInstance> site_instance_; | |
| 87 base::scoped_nsobject<ExclusiveAccessBubbleWindowController> controller_; | |
| 88 }; | |
| 89 | |
| 90 TEST_F(ExclusiveAccessBubbleWindowControllerTest, LabelWasReplaced) { | |
| 91 EXPECT_FALSE([controller_ exitLabelPlaceholder]); | |
| 92 EXPECT_TRUE([controller_ exitLabel]); | |
| 93 } | |
| 94 | |
| 95 TEST_F(ExclusiveAccessBubbleWindowControllerTest, ShortcutText) { | |
| 96 ui::PlatformAcceleratorCocoa cmd_F(@"F", NSCommandKeyMask); | |
| 97 ui::PlatformAcceleratorCocoa cmd_shift_f(@"f", | |
| 98 NSCommandKeyMask | NSShiftKeyMask); | |
| 99 NSString* cmd_F_text = [ExclusiveAccessBubbleWindowController | |
| 100 keyCombinationForAccelerator:cmd_F]; | |
| 101 NSString* cmd_shift_f_text = [ExclusiveAccessBubbleWindowController | |
| 102 keyCombinationForAccelerator:cmd_shift_f]; | |
| 103 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); | |
| 104 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); | |
| 105 } | |
| 106 | |
| 107 // http://crbug.com/139944 | |
| 108 TEST_F(ExclusiveAccessBubbleWindowControllerTest, DenyButtonText) { | |
| 109 controller_.reset([[ExclusiveAccessBubbleWindowController alloc] | |
| 110 initWithOwner:nil | |
| 111 exclusive_access_manager:browser()->exclusive_access_manager() | |
| 112 profile:browser()->profile() | |
| 113 url:GURL() | |
| 114 bubbleType:EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS]); | |
| 115 [controller_ initializeLabelAndButton]; | |
| 116 NSString* mouselock_deny_button_text = [controller_ denyButtonText]; | |
| 117 EXPECT_NSEQ(l10n_util::GetNSString(IDS_FULLSCREEN_DENY), | |
| 118 mouselock_deny_button_text); | |
| 119 | |
| 120 controller_.reset([[ExclusiveAccessBubbleWindowController alloc] | |
| 121 initWithOwner:nil | |
| 122 exclusive_access_manager:browser()->exclusive_access_manager() | |
| 123 profile:browser()->profile() | |
| 124 url:GURL() | |
| 125 bubbleType: | |
| 126 EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTON
S]); | |
| 127 [controller_ initializeLabelAndButton]; | |
| 128 NSString* fullscreen_mouselock_deny_button_text = | |
| 129 [controller_ denyButtonText]; | |
| 130 EXPECT_NSEQ(l10n_util::GetNSString(IDS_FULLSCREEN_EXIT), | |
| 131 fullscreen_mouselock_deny_button_text); | |
| 132 } | |
| OLD | NEW |