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) { | |
(unused - use chromium)
2011/10/28 04:46:34
Nice test!
| |
73 CreateBrowserWindow(); | |
74 AppendTabToStrip(); | |
75 TabContents* fullscreen_tab = browser()->GetSelectedTabContents(); | |
76 { | |
77 base::mac::ScopedNSAutoreleasePool pool; | |
78 ui_test_utils::WindowedNotificationObserver fullscreen_observer( | |
79 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
80 content::NotificationService::AllSources()); | |
81 browser()->ToggleFullscreenModeForTab(fullscreen_tab, true); | |
82 fullscreen_observer.Wait(); | |
83 ASSERT_TRUE(browser()->window()->IsFullscreen()); | |
84 } | |
85 | |
86 NSWindow* window = browser()->window()->GetNativeHandle(); | |
87 BrowserWindowController* bwc = [BrowserWindowController | |
88 browserWindowControllerForWindow:window]; | |
89 FullscreenExitBubbleController* fseb = [bwc fullscreenExitBubbleController]; | |
(unused - use chromium)
2011/10/28 04:46:34
no abbreviations; maybe just `bubble`. (`bwc` abov
jeremya
2011/10/28 06:43:37
Done.
| |
90 ASSERT_TRUE(fseb); | |
91 { | |
92 ui_test_utils::WindowedNotificationObserver fullscreen_observer( | |
93 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
94 content::NotificationService::AllSources()); | |
95 [fseb deny:nil]; | |
96 fullscreen_observer.Wait(); | |
97 } | |
98 EXPECT_FALSE([bwc fullscreenExitBubbleController]); | |
99 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
100 CloseBrowserWindow(); | |
101 } | |
102 | |
54 TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) { | 103 TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) { |
55 EXPECT_FALSE([controller_ exitLabelPlaceholder]); | 104 EXPECT_FALSE([controller_ exitLabelPlaceholder]); |
56 EXPECT_TRUE([controller_ exitLabel]); | 105 EXPECT_TRUE([controller_ exitLabel]); |
57 } | 106 } |
58 | 107 |
59 TEST_F(FullscreenExitBubbleControllerTest, LabelContainsShortcut) { | 108 TEST_F(FullscreenExitBubbleControllerTest, LabelContainsShortcut) { |
60 NSString* shortcut = [FullscreenExitBubbleController keyCommandString]; | 109 NSString* shortcut = [FullscreenExitBubbleController keyCommandString]; |
61 EXPECT_GT([shortcut length], 0U); | 110 EXPECT_GT([shortcut length], 0U); |
62 | 111 |
63 NSString* message = [[[controller_ exitLabel] textStorage] string]; | 112 NSString* message = [[[controller_ exitLabel] textStorage] string]; |
64 | 113 |
65 NSRange range = [message rangeOfString:shortcut]; | 114 NSRange range = [message rangeOfString:shortcut]; |
66 EXPECT_NE(NSNotFound, range.location); | 115 EXPECT_NE(NSNotFound, range.location); |
67 } | 116 } |
68 | 117 |
69 TEST_F(FullscreenExitBubbleControllerTest, ShortcutText) { | 118 TEST_F(FullscreenExitBubbleControllerTest, ShortcutText) { |
70 ui::AcceleratorCocoa cmd_F(@"F", NSCommandKeyMask); | 119 ui::AcceleratorCocoa cmd_F(@"F", NSCommandKeyMask); |
71 ui::AcceleratorCocoa cmd_shift_f(@"f", NSCommandKeyMask|NSShiftKeyMask); | 120 ui::AcceleratorCocoa cmd_shift_f(@"f", NSCommandKeyMask|NSShiftKeyMask); |
72 NSString* cmd_F_text = [FullscreenExitBubbleController | 121 NSString* cmd_F_text = [FullscreenExitBubbleController |
73 keyCombinationForAccelerator:cmd_F]; | 122 keyCombinationForAccelerator:cmd_F]; |
74 NSString* cmd_shift_f_text = [FullscreenExitBubbleController | 123 NSString* cmd_shift_f_text = [FullscreenExitBubbleController |
75 keyCombinationForAccelerator:cmd_shift_f]; | 124 keyCombinationForAccelerator:cmd_shift_f]; |
76 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); | 125 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); |
77 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); | 126 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); |
78 } | 127 } |
OLD | NEW |