OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/fullscreen_exit_bubble_controller.h" |
6 | 6 |
7 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 11 #include "chrome/browser/tabs/tab_strip_model.h" |
| 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/test/base/ui_test_utils.h" |
| 14 #include "content/browser/site_instance.h" |
8 #include "testing/gtest_mac.h" | 15 #include "testing/gtest_mac.h" |
9 #include "ui/base/models/accelerator_cocoa.h" | 16 #include "ui/base/models/accelerator_cocoa.h" |
10 | 17 |
11 @interface FullscreenExitBubbleController(JustForTesting) | 18 @interface FullscreenExitBubbleController(JustForTesting) |
12 // Already defined. | 19 // Already defined. |
13 + (NSString*)keyCommandString; | 20 + (NSString*)keyCommandString; |
14 + (NSString*)keyCombinationForAccelerator:(const ui::AcceleratorCocoa&)item; | 21 + (NSString*)keyCombinationForAccelerator:(const ui::AcceleratorCocoa&)item; |
15 @end | 22 @end |
16 | 23 |
17 @interface FullscreenExitBubbleController(ExposedForTesting) | 24 @interface FullscreenExitBubbleController(ExposedForTesting) |
18 - (NSTextField*)exitLabelPlaceholder; | 25 - (NSTextField*)exitLabelPlaceholder; |
19 - (NSTextView*)exitLabel; | 26 - (NSTextView*)exitLabel; |
20 @end | 27 @end |
21 | 28 |
22 @implementation FullscreenExitBubbleController(ExposedForTesting) | 29 @implementation FullscreenExitBubbleController(ExposedForTesting) |
23 - (NSTextField*)exitLabelPlaceholder { | 30 - (NSTextField*)exitLabelPlaceholder { |
24 return exitLabelPlaceholder_; | 31 return exitLabelPlaceholder_; |
25 } | 32 } |
26 | 33 |
27 - (NSTextView*)exitLabel { | 34 - (NSTextView*)exitLabel { |
28 return exitLabel_; | 35 return exitLabel_; |
29 } | 36 } |
30 @end | 37 @end |
31 | 38 |
32 class FullscreenExitBubbleControllerTest : public CocoaTest { | 39 class FullscreenExitBubbleControllerTest : public CocoaProfileTest { |
33 public: | 40 public: |
34 virtual void SetUp() { | 41 virtual void SetUp() { |
35 CocoaTest::SetUp(); | 42 CocoaProfileTest::SetUp(); |
| 43 ASSERT_TRUE(profile()); |
36 | 44 |
| 45 site_instance_ = SiteInstance::CreateSiteInstance(profile()); |
37 controller_.reset( | 46 controller_.reset( |
38 [[FullscreenExitBubbleController alloc] initWithOwner:nil | 47 [[FullscreenExitBubbleController alloc] initWithOwner:nil |
39 browser:nil | 48 browser:browser() |
40 url:GURL() | 49 url:GURL() |
41 bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]); | 50 bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]); |
42 EXPECT_TRUE([controller_ window]); | 51 EXPECT_TRUE([controller_ window]); |
43 } | 52 } |
44 | 53 |
45 virtual void TearDown() { | 54 virtual void TearDown() { |
46 [controller_ close]; | 55 [controller_ close]; |
47 controller_.reset(); | 56 controller_.reset(); |
48 CocoaTest::TearDown(); | 57 CocoaProfileTest::TearDown(); |
49 } | 58 } |
50 | 59 |
| 60 void AppendTabToStrip() { |
| 61 TabContentsWrapper* tab_contents = Browser::TabContentsFactory( |
| 62 profile(), site_instance_, MSG_ROUTING_NONE, |
| 63 NULL, NULL); |
| 64 browser()->tabstrip_model()->AppendTabContents( |
| 65 tab_contents, /*foreground=*/true); |
| 66 } |
| 67 |
| 68 scoped_refptr<SiteInstance> site_instance_; |
51 scoped_nsobject<FullscreenExitBubbleController> controller_; | 69 scoped_nsobject<FullscreenExitBubbleController> controller_; |
52 }; | 70 }; |
53 | 71 |
| 72 TEST_F(FullscreenExitBubbleControllerTest, DenyExitsFullscreen) { |
| 73 // This test goes with r107841, which was merged from trunk. However, it |
| 74 // doesn't seem to compile on 912. As such, commenting it out, since it's not |
| 75 // important that this be run on the branch (as long as it's passing on |
| 76 // trunk). |
| 77 #if 0 |
| 78 CreateBrowserWindow(); |
| 79 AppendTabToStrip(); |
| 80 TabContents* fullscreen_tab = browser()->GetSelectedTabContents(); |
| 81 { |
| 82 base::mac::ScopedNSAutoreleasePool pool; |
| 83 ui_test_utils::WindowedNotificationObserver fullscreen_observer( |
| 84 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 85 content::NotificationService::AllSources()); |
| 86 browser()->ToggleFullscreenModeForTab(fullscreen_tab, true); |
| 87 fullscreen_observer.Wait(); |
| 88 ASSERT_TRUE(browser()->window()->IsFullscreen()); |
| 89 } |
| 90 |
| 91 NSWindow* window = browser()->window()->GetNativeHandle(); |
| 92 BrowserWindowController* bwc = [BrowserWindowController |
| 93 browserWindowControllerForWindow:window]; |
| 94 FullscreenExitBubbleController* bubble = [bwc fullscreenExitBubbleController]; |
| 95 ASSERT_TRUE(bubble); |
| 96 { |
| 97 ui_test_utils::WindowedNotificationObserver fullscreen_observer( |
| 98 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 99 content::NotificationService::AllSources()); |
| 100 [bubble deny:nil]; |
| 101 fullscreen_observer.Wait(); |
| 102 } |
| 103 EXPECT_FALSE([bwc fullscreenExitBubbleController]); |
| 104 EXPECT_FALSE(browser()->window()->IsFullscreen()); |
| 105 CloseBrowserWindow(); |
| 106 #endif |
| 107 } |
| 108 |
54 TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) { | 109 TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) { |
55 EXPECT_FALSE([controller_ exitLabelPlaceholder]); | 110 EXPECT_FALSE([controller_ exitLabelPlaceholder]); |
56 EXPECT_TRUE([controller_ exitLabel]); | 111 EXPECT_TRUE([controller_ exitLabel]); |
57 } | 112 } |
58 | 113 |
59 TEST_F(FullscreenExitBubbleControllerTest, LabelContainsShortcut) { | 114 TEST_F(FullscreenExitBubbleControllerTest, LabelContainsShortcut) { |
60 NSString* shortcut = [FullscreenExitBubbleController keyCommandString]; | 115 NSString* shortcut = [FullscreenExitBubbleController keyCommandString]; |
61 EXPECT_GT([shortcut length], 0U); | 116 EXPECT_GT([shortcut length], 0U); |
62 | 117 |
63 NSString* message = [[[controller_ exitLabel] textStorage] string]; | 118 NSString* message = [[[controller_ exitLabel] textStorage] string]; |
64 | 119 |
65 NSRange range = [message rangeOfString:shortcut]; | 120 NSRange range = [message rangeOfString:shortcut]; |
66 EXPECT_NE(NSNotFound, range.location); | 121 EXPECT_NE(NSNotFound, range.location); |
67 } | 122 } |
68 | 123 |
69 TEST_F(FullscreenExitBubbleControllerTest, ShortcutText) { | 124 TEST_F(FullscreenExitBubbleControllerTest, ShortcutText) { |
70 ui::AcceleratorCocoa cmd_F(@"F", NSCommandKeyMask); | 125 ui::AcceleratorCocoa cmd_F(@"F", NSCommandKeyMask); |
71 ui::AcceleratorCocoa cmd_shift_f(@"f", NSCommandKeyMask|NSShiftKeyMask); | 126 ui::AcceleratorCocoa cmd_shift_f(@"f", NSCommandKeyMask|NSShiftKeyMask); |
72 NSString* cmd_F_text = [FullscreenExitBubbleController | 127 NSString* cmd_F_text = [FullscreenExitBubbleController |
73 keyCombinationForAccelerator:cmd_F]; | 128 keyCombinationForAccelerator:cmd_F]; |
74 NSString* cmd_shift_f_text = [FullscreenExitBubbleController | 129 NSString* cmd_shift_f_text = [FullscreenExitBubbleController |
75 keyCombinationForAccelerator:cmd_shift_f]; | 130 keyCombinationForAccelerator:cmd_shift_f]; |
76 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); | 131 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); |
77 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); | 132 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); |
78 } | 133 } |
OLD | NEW |