| 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/fullscreen_exit_bubble_controller.h" | |
| 6 | |
| 7 #include "base/mac/mac_util.h" | |
| 8 #include "chrome/browser/chrome_notification_types.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_window.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/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 | |
| 22 using content::SiteInstance; | |
| 23 using content::WebContents; | |
| 24 | |
| 25 @interface FullscreenExitBubbleController(JustForTesting) | |
| 26 // Already defined. | |
| 27 + (NSString*)keyCommandString; | |
| 28 + (NSString*)keyCombinationForAccelerator: | |
| 29 (const ui::PlatformAcceleratorCocoa&)item; | |
| 30 @end | |
| 31 | |
| 32 @interface FullscreenExitBubbleController(ExposedForTesting) | |
| 33 - (NSTextField*)exitLabelPlaceholder; | |
| 34 - (NSTextView*)exitLabel; | |
| 35 @end | |
| 36 | |
| 37 @implementation FullscreenExitBubbleController(ExposedForTesting) | |
| 38 - (NSTextField*)exitLabelPlaceholder { | |
| 39 return exitLabelPlaceholder_; | |
| 40 } | |
| 41 | |
| 42 - (NSTextView*)exitLabel { | |
| 43 return exitLabel_; | |
| 44 } | |
| 45 @end | |
| 46 | |
| 47 class FullscreenExitBubbleControllerTest : public CocoaProfileTest { | |
| 48 public: | |
| 49 virtual void SetUp() { | |
| 50 CocoaProfileTest::SetUp(); | |
| 51 ASSERT_TRUE(profile()); | |
| 52 | |
| 53 site_instance_ = SiteInstance::Create(profile()); | |
| 54 controller_.reset( | |
| 55 [[FullscreenExitBubbleController alloc] initWithOwner:nil | |
| 56 browser:browser() | |
| 57 url:GURL() | |
| 58 bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]); | |
| 59 EXPECT_TRUE([controller_ window]); | |
| 60 } | |
| 61 | |
| 62 virtual void TearDown() { | |
| 63 [controller_ close]; | |
| 64 controller_.reset(); | |
| 65 CocoaProfileTest::TearDown(); | |
| 66 } | |
| 67 | |
| 68 void AppendTabToStrip() { | |
| 69 WebContents* web_contents = WebContents::Create( | |
| 70 content::WebContents::CreateParams(profile(), site_instance_.get())); | |
| 71 browser()->tab_strip_model()->AppendWebContents( | |
| 72 web_contents, /*foreground=*/true); | |
| 73 } | |
| 74 | |
| 75 scoped_refptr<SiteInstance> site_instance_; | |
| 76 base::scoped_nsobject<FullscreenExitBubbleController> controller_; | |
| 77 }; | |
| 78 | |
| 79 // http://crbug.com/103912 | |
| 80 TEST_F(FullscreenExitBubbleControllerTest, DISABLED_DenyExitsFullscreen) { | |
| 81 NSWindow* window = browser()->window()->GetNativeWindow(); | |
| 82 BrowserWindowController* bwc = [BrowserWindowController | |
| 83 browserWindowControllerForWindow:window]; | |
| 84 | |
| 85 [bwc showWindow:nil]; | |
| 86 | |
| 87 AppendTabToStrip(); | |
| 88 WebContents* fullscreen_tab = | |
| 89 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 90 { | |
| 91 base::mac::ScopedNSAutoreleasePool pool; | |
| 92 content::WindowedNotificationObserver fullscreen_observer( | |
| 93 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 94 content::NotificationService::AllSources()); | |
| 95 browser()->ToggleFullscreenModeForTab(fullscreen_tab, true); | |
| 96 fullscreen_observer.Wait(); | |
| 97 ASSERT_TRUE(browser()->window()->IsFullscreen()); | |
| 98 } | |
| 99 | |
| 100 FullscreenExitBubbleController* bubble = [bwc fullscreenExitBubbleController]; | |
| 101 EXPECT_TRUE(bubble); | |
| 102 { | |
| 103 content::WindowedNotificationObserver fullscreen_observer( | |
| 104 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
| 105 content::NotificationService::AllSources()); | |
| 106 [bubble deny:nil]; | |
| 107 fullscreen_observer.Wait(); | |
| 108 } | |
| 109 EXPECT_FALSE([bwc fullscreenExitBubbleController]); | |
| 110 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 111 CloseBrowserWindow(); | |
| 112 } | |
| 113 | |
| 114 TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) { | |
| 115 EXPECT_FALSE([controller_ exitLabelPlaceholder]); | |
| 116 EXPECT_TRUE([controller_ exitLabel]); | |
| 117 } | |
| 118 | |
| 119 TEST_F(FullscreenExitBubbleControllerTest, ShortcutText) { | |
| 120 ui::PlatformAcceleratorCocoa cmd_F(@"F", NSCommandKeyMask); | |
| 121 ui::PlatformAcceleratorCocoa cmd_shift_f( | |
| 122 @"f", NSCommandKeyMask | NSShiftKeyMask); | |
| 123 NSString* cmd_F_text = [FullscreenExitBubbleController | |
| 124 keyCombinationForAccelerator:cmd_F]; | |
| 125 NSString* cmd_shift_f_text = [FullscreenExitBubbleController | |
| 126 keyCombinationForAccelerator:cmd_shift_f]; | |
| 127 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); | |
| 128 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); | |
| 129 } | |
| OLD | NEW |