Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_touch_bar_unittest.mm

Issue 2860163004: [Mac] Fix for Tab Fullscreen Touch Bar (Closed)
Patch Set: Nits Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_touch_bar.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 21 matching lines...) Expand all
32 [[[bwc_ stub] andReturnValue:OCMOCK_VALUE(yes)] 32 [[[bwc_ stub] andReturnValue:OCMOCK_VALUE(yes)]
33 isKindOfClass:[BrowserWindowController class]]; 33 isKindOfClass:[BrowserWindowController class]];
34 [[bwc_ stub] invalidateTouchBar]; 34 [[bwc_ stub] invalidateTouchBar];
35 35
36 touch_bar_.reset([[BrowserWindowTouchBar alloc] initWithBrowser:browser() 36 touch_bar_.reset([[BrowserWindowTouchBar alloc] initWithBrowser:browser()
37 browserWindowController:bwc_]); 37 browserWindowController:bwc_]);
38 } 38 }
39 39
40 id bwc() const { return bwc_; } 40 id bwc() const { return bwc_; }
41 41
42 NSString* GetFullscreenTouchBarItemId(NSString* id) {
43 return [BrowserWindowTouchBar identifierForTouchBarId:@"tab-fullscreen"
44 itemId:id];
45 }
46
47 NSString* GetBrowserTouchBarItemId(NSString* id) {
48 return [BrowserWindowTouchBar identifierForTouchBarId:@"browser-window"
Avi (use Gerrit) 2017/05/05 19:09:34 :( Can't we reuse the constants that you declared?
spqchan 2017/05/05 22:38:09 Done.
49 itemId:id];
50 }
51
42 void TearDown() override { CocoaProfileTest::TearDown(); } 52 void TearDown() override { CocoaProfileTest::TearDown(); }
43 53
44 // A mock BrowserWindowController object. 54 // A mock BrowserWindowController object.
45 id bwc_; 55 id bwc_;
46 56
47 // Used to enable the the browser window touch bar. 57 // Used to enable the the browser window touch bar.
48 base::test::ScopedFeatureList feature_list; 58 base::test::ScopedFeatureList feature_list;
49 59
50 base::scoped_nsobject<BrowserWindowTouchBar> touch_bar_; 60 base::scoped_nsobject<BrowserWindowTouchBar> touch_bar_;
51 }; 61 };
52 62
53 // Tests to check if the touch bar contains the correct items. 63 // Tests to check if the touch bar contains the correct items.
54 TEST_F(BrowserWindowTouchBarUnitTest, TouchBarItems) { 64 TEST_F(BrowserWindowTouchBarUnitTest, TouchBarItems) {
55 if (!base::mac::IsAtLeastOS10_12()) 65 if (!base::mac::IsAtLeastOS10_12())
56 return; 66 return;
57 67
58 BOOL yes = YES; 68 BOOL yes = YES;
59 [[[bwc() expect] andReturnValue:OCMOCK_VALUE(yes)] 69 [[[bwc() expect] andReturnValue:OCMOCK_VALUE(yes)]
60 isFullscreenForTabContentOrExtension]; 70 isFullscreenForTabContentOrExtension];
61 71
62 PrefService* prefs = profile()->GetPrefs(); 72 PrefService* prefs = profile()->GetPrefs();
63 DCHECK(prefs); 73 DCHECK(prefs);
64 prefs->SetBoolean(prefs::kShowHomeButton, true); 74 prefs->SetBoolean(prefs::kShowHomeButton, true);
65 75
66 // The touch bar should be empty since the toolbar is hidden when the browser 76 // The touch bar should be empty since the toolbar is hidden when the browser
67 // is in tab fullscreen. 77 // is in tab fullscreen.
68 NSTouchBar* touch_bar = [touch_bar_ makeTouchBar]; 78 NSTouchBar* touch_bar = [touch_bar_ makeTouchBar];
69 NSArray* touch_bar_items = [touch_bar itemIdentifiers]; 79 NSArray* touch_bar_items = [touch_bar itemIdentifiers];
70 EXPECT_TRUE([touch_bar_items 80 EXPECT_TRUE([touch_bar_items
71 containsObject:[BrowserWindowTouchBar 81 containsObject:GetFullscreenTouchBarItemId(@"FULLSCREEN-ORIGIN-LABEL")]);
72 touchBarIdForItemId:@"FULLSCREEN-ORIGIN-LABEL"]]);
73 EXPECT_TRUE([[touch_bar escapeKeyReplacementItemIdentifier] 82 EXPECT_TRUE([[touch_bar escapeKeyReplacementItemIdentifier]
74 isEqualToString:[BrowserWindowTouchBar 83 isEqualToString:GetFullscreenTouchBarItemId(@"EXIT-FULLSCREEN")]);
75 touchBarIdForItemId:@"EXIT-FULLSCREEN"]]);
76 84
77 BOOL no = NO; 85 BOOL no = NO;
78 [[[bwc() stub] andReturnValue:OCMOCK_VALUE(no)] 86 [[[bwc() stub] andReturnValue:OCMOCK_VALUE(no)]
79 isFullscreenForTabContentOrExtension]; 87 isFullscreenForTabContentOrExtension];
80 88
81 touch_bar_items = [[touch_bar_ makeTouchBar] itemIdentifiers]; 89 touch_bar_items = [[touch_bar_ makeTouchBar] itemIdentifiers];
90 EXPECT_TRUE(
91 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"BACK-FWD")]);
82 EXPECT_TRUE([touch_bar_items 92 EXPECT_TRUE([touch_bar_items
83 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"BACK-FWD"]]); 93 containsObject:GetBrowserTouchBarItemId(@"RELOAD-STOP")]);
84 EXPECT_TRUE( 94 EXPECT_TRUE(
85 [touch_bar_items containsObject:[BrowserWindowTouchBar 95 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"HOME")]);
86 touchBarIdForItemId:@"RELOAD-STOP"]]); 96 EXPECT_TRUE(
87 EXPECT_TRUE([touch_bar_items 97 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"SEARCH")]);
88 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"HOME"]]); 98 EXPECT_TRUE(
89 EXPECT_TRUE([touch_bar_items 99 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"BOOKMARK")]);
90 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"SEARCH"]]); 100 EXPECT_TRUE(
91 EXPECT_TRUE([touch_bar_items 101 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"NEW-TAB")]);
92 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"BOOKMARK"]]);
93 EXPECT_TRUE([touch_bar_items
94 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"NEW-TAB"]]);
95 102
96 prefs->SetBoolean(prefs::kShowHomeButton, false); 103 prefs->SetBoolean(prefs::kShowHomeButton, false);
97 touch_bar_items = [[touch_bar_ makeTouchBar] itemIdentifiers]; 104 touch_bar_items = [[touch_bar_ makeTouchBar] itemIdentifiers];
105 EXPECT_TRUE(
106 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"BACK-FWD")]);
98 EXPECT_TRUE([touch_bar_items 107 EXPECT_TRUE([touch_bar_items
99 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"BACK-FWD"]]); 108 containsObject:GetBrowserTouchBarItemId(@"RELOAD-STOP")]);
100 EXPECT_TRUE( 109 EXPECT_TRUE(
101 [touch_bar_items containsObject:[BrowserWindowTouchBar 110 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"SEARCH")]);
102 touchBarIdForItemId:@"RELOAD-STOP"]]); 111 EXPECT_TRUE(
103 EXPECT_TRUE([touch_bar_items 112 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"BOOKMARK")]);
104 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"SEARCH"]]); 113 EXPECT_TRUE(
105 EXPECT_TRUE([touch_bar_items 114 [touch_bar_items containsObject:GetBrowserTouchBarItemId(@"NEW-TAB")]);
106 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"BOOKMARK"]]);
107 EXPECT_TRUE([touch_bar_items
108 containsObject:[BrowserWindowTouchBar touchBarIdForItemId:@"NEW-TAB"]]);
109 } 115 }
110 116
111 // Tests the reload or stop touch bar item. 117 // Tests the reload or stop touch bar item.
112 TEST_F(BrowserWindowTouchBarUnitTest, ReloadOrStopTouchBarItem) { 118 TEST_F(BrowserWindowTouchBarUnitTest, ReloadOrStopTouchBarItem) {
113 if (!base::mac::IsAtLeastOS10_12()) 119 if (!base::mac::IsAtLeastOS10_12())
114 return; 120 return;
115 121
116 BOOL no = NO; 122 BOOL no = NO;
117 [[[bwc() stub] andReturnValue:OCMOCK_VALUE(no)] 123 [[[bwc() stub] andReturnValue:OCMOCK_VALUE(no)]
118 isFullscreenForTabContentOrExtension]; 124 isFullscreenForTabContentOrExtension];
119 125
120 NSTouchBar* touch_bar = [touch_bar_ makeTouchBar]; 126 NSTouchBar* touch_bar = [touch_bar_ makeTouchBar];
121 [touch_bar_ setIsPageLoading:NO]; 127 [touch_bar_ setIsPageLoading:NO];
122 128
123 NSTouchBarItem* item = 129 NSTouchBarItem* item =
124 [touch_bar_ touchBar:touch_bar 130 [touch_bar_ touchBar:touch_bar
125 makeItemForIdentifier:[BrowserWindowTouchBar 131 makeItemForIdentifier:GetBrowserTouchBarItemId(@"RELOAD-STOP")];
126 touchBarIdForItemId:@"RELOAD-STOP"]];
127 EXPECT_EQ(IDC_RELOAD, [[item view] tag]); 132 EXPECT_EQ(IDC_RELOAD, [[item view] tag]);
128 133
129 [touch_bar_ setIsPageLoading:YES]; 134 [touch_bar_ setIsPageLoading:YES];
130 item = [touch_bar_ touchBar:touch_bar 135 item = [touch_bar_ touchBar:touch_bar
131 makeItemForIdentifier:[BrowserWindowTouchBar 136 makeItemForIdentifier:GetBrowserTouchBarItemId(@"RELOAD-STOP")];
132 touchBarIdForItemId:@"RELOAD-STOP"]];
133 EXPECT_EQ(IDC_STOP, [[item view] tag]); 137 EXPECT_EQ(IDC_STOP, [[item view] tag]);
134 } 138 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_touch_bar.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698