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( |
55 [[FullscreenExitBubbleController alloc] initWithOwner:nil | 55 [[ExclusiveAccessBubbleWindowController alloc] initWithOwner:nil |
56 browser:browser() | 56 browser:browser() |
57 url:GURL() | 57 url:GURL() |
58 bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]); | 58 bubbleType:EAB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]); |
59 EXPECT_TRUE([controller_ window]); | 59 EXPECT_TRUE([controller_ window]); |
60 } | 60 } |
61 | 61 |
62 virtual void TearDown() { | 62 virtual void TearDown() { |
63 [controller_ close]; | 63 [controller_ close]; |
64 controller_.reset(); | 64 controller_.reset(); |
65 CocoaProfileTest::TearDown(); | 65 CocoaProfileTest::TearDown(); |
66 } | 66 } |
67 | 67 |
68 void AppendTabToStrip() { | 68 void AppendTabToStrip() { |
69 WebContents* web_contents = WebContents::Create( | 69 WebContents* web_contents = WebContents::Create( |
70 content::WebContents::CreateParams(profile(), site_instance_.get())); | 70 content::WebContents::CreateParams(profile(), site_instance_.get())); |
71 browser()->tab_strip_model()->AppendWebContents( | 71 browser()->tab_strip_model()->AppendWebContents( |
72 web_contents, /*foreground=*/true); | 72 web_contents, /*foreground=*/true); |
73 } | 73 } |
74 | 74 |
75 scoped_refptr<SiteInstance> site_instance_; | 75 scoped_refptr<SiteInstance> site_instance_; |
76 base::scoped_nsobject<FullscreenExitBubbleController> controller_; | 76 base::scoped_nsobject<ExclusiveAccessBubbleWindowController> controller_; |
77 }; | 77 }; |
78 | 78 |
79 // http://crbug.com/103912 | 79 // http://crbug.com/103912 |
80 TEST_F(FullscreenExitBubbleControllerTest, DISABLED_DenyExitsFullscreen) { | 80 TEST_F(ExclusiveAccessBubbleWindowControllerTest, |
| 81 DISABLED_DenyExitsFullscreen) { |
81 NSWindow* window = browser()->window()->GetNativeWindow(); | 82 NSWindow* window = browser()->window()->GetNativeWindow(); |
82 BrowserWindowController* bwc = [BrowserWindowController | 83 BrowserWindowController* bwc = [BrowserWindowController |
83 browserWindowControllerForWindow:window]; | 84 browserWindowControllerForWindow:window]; |
84 | 85 |
85 [bwc showWindow:nil]; | 86 [bwc showWindow:nil]; |
86 | 87 |
87 AppendTabToStrip(); | 88 AppendTabToStrip(); |
88 WebContents* fullscreen_tab = | 89 WebContents* fullscreen_tab = |
89 browser()->tab_strip_model()->GetActiveWebContents(); | 90 browser()->tab_strip_model()->GetActiveWebContents(); |
90 { | 91 { |
91 base::mac::ScopedNSAutoreleasePool pool; | 92 base::mac::ScopedNSAutoreleasePool pool; |
92 content::WindowedNotificationObserver fullscreen_observer( | 93 content::WindowedNotificationObserver fullscreen_observer( |
93 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 94 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
94 content::NotificationService::AllSources()); | 95 content::NotificationService::AllSources()); |
95 browser()->ToggleFullscreenModeForTab(fullscreen_tab, true); | 96 browser()->ToggleFullscreenModeForTab(fullscreen_tab, true); |
96 fullscreen_observer.Wait(); | 97 fullscreen_observer.Wait(); |
97 ASSERT_TRUE(browser()->window()->IsFullscreen()); | 98 ASSERT_TRUE(browser()->window()->IsFullscreen()); |
98 } | 99 } |
99 | 100 |
100 FullscreenExitBubbleController* bubble = [bwc fullscreenExitBubbleController]; | 101 ExclusiveAccessBubbleWindowController* bubble = |
| 102 [bwc exclusiveAccessBubbleWindowController]; |
101 EXPECT_TRUE(bubble); | 103 EXPECT_TRUE(bubble); |
102 { | 104 { |
103 content::WindowedNotificationObserver fullscreen_observer( | 105 content::WindowedNotificationObserver fullscreen_observer( |
104 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 106 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
105 content::NotificationService::AllSources()); | 107 content::NotificationService::AllSources()); |
106 [bubble deny:nil]; | 108 [bubble deny:nil]; |
107 fullscreen_observer.Wait(); | 109 fullscreen_observer.Wait(); |
108 } | 110 } |
109 EXPECT_FALSE([bwc fullscreenExitBubbleController]); | 111 EXPECT_FALSE([bwc exclusiveAccessBubbleWindowController]); |
110 EXPECT_FALSE(browser()->window()->IsFullscreen()); | 112 EXPECT_FALSE(browser()->window()->IsFullscreen()); |
111 CloseBrowserWindow(); | 113 CloseBrowserWindow(); |
112 } | 114 } |
113 | 115 |
114 TEST_F(FullscreenExitBubbleControllerTest, LabelWasReplaced) { | 116 TEST_F(ExclusiveAccessBubbleWindowControllerTest, LabelWasReplaced) { |
115 EXPECT_FALSE([controller_ exitLabelPlaceholder]); | 117 EXPECT_FALSE([controller_ exitLabelPlaceholder]); |
116 EXPECT_TRUE([controller_ exitLabel]); | 118 EXPECT_TRUE([controller_ exitLabel]); |
117 } | 119 } |
118 | 120 |
119 TEST_F(FullscreenExitBubbleControllerTest, ShortcutText) { | 121 TEST_F(ExclusiveAccessBubbleWindowControllerTest, ShortcutText) { |
120 ui::PlatformAcceleratorCocoa cmd_F(@"F", NSCommandKeyMask); | 122 ui::PlatformAcceleratorCocoa cmd_F(@"F", NSCommandKeyMask); |
121 ui::PlatformAcceleratorCocoa cmd_shift_f( | 123 ui::PlatformAcceleratorCocoa cmd_shift_f( |
122 @"f", NSCommandKeyMask | NSShiftKeyMask); | 124 @"f", NSCommandKeyMask | NSShiftKeyMask); |
123 NSString* cmd_F_text = [FullscreenExitBubbleController | 125 NSString* cmd_F_text = [ExclusiveAccessBubbleWindowController |
124 keyCombinationForAccelerator:cmd_F]; | 126 keyCombinationForAccelerator:cmd_F]; |
125 NSString* cmd_shift_f_text = [FullscreenExitBubbleController | 127 NSString* cmd_shift_f_text = [ExclusiveAccessBubbleWindowController |
126 keyCombinationForAccelerator:cmd_shift_f]; | 128 keyCombinationForAccelerator:cmd_shift_f]; |
127 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); | 129 EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); |
128 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); | 130 EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); |
129 } | 131 } |
OLD | NEW |