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