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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell_unittest.mm

Issue 2794123002: [Mac] Bookmark button cell updates (Closed)
Patch Set: Add comment to test Created 3 years, 8 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/bookmarks/bookmark_button_cell.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 (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/bookmarks/bookmark_button_cell.h"
5 #include "base/mac/scoped_nsobject.h" 6 #include "base/mac/scoped_nsobject.h"
7 #include "base/strings/sys_string_conversions.h"
6 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
8 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h"
9 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" 10 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
10 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" 11 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
11 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
12 #include "components/bookmarks/browser/bookmark_model.h" 13 #include "components/bookmarks/browser/bookmark_model.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
15 #include "ui/base/material_design/material_design_controller.h" 16 #include "ui/base/material_design/material_design_controller.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/image/image.h" 18 #include "ui/gfx/image/image.h"
18 #include "ui/resources/grit/ui_resources.h" 19 #include "ui/resources/grit/ui_resources.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 base::scoped_nsobject<BookmarkButtonCell> cell( 115 base::scoped_nsobject<BookmarkButtonCell> cell(
115 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]); 116 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]);
116 117
117 const BookmarkNode* node = model->bookmark_bar_node(); 118 const BookmarkNode* node = model->bookmark_bar_node();
118 [cell setBookmarkNode:node]; 119 [cell setBookmarkNode:node];
119 EXPECT_EQ(node, [cell bookmarkNode]); 120 EXPECT_EQ(node, [cell bookmarkNode]);
120 121
121 node = model->other_node(); 122 node = model->other_node();
122 [cell setBookmarkNode:node]; 123 [cell setBookmarkNode:node];
123 EXPECT_EQ(node, [cell bookmarkNode]); 124 EXPECT_EQ(node, [cell bookmarkNode]);
125 EXPECT_EQ(node->GetTitle(), base::SysNSStringToUTF16([cell title]));
124 } 126 }
125 127
126 TEST_F(BookmarkButtonCellTest, BookmarkMouseForwarding) { 128 TEST_F(BookmarkButtonCellTest, BookmarkMouseForwarding) {
127 base::scoped_nsobject<BookmarkButtonCell> cell( 129 base::scoped_nsobject<BookmarkButtonCell> cell(
128 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]); 130 [[BookmarkButtonCell alloc] initTextCell:@"Testing"]);
129 base::scoped_nsobject<ButtonRemembersMouseEnterExit> button( 131 base::scoped_nsobject<ButtonRemembersMouseEnterExit> button(
130 [[ButtonRemembersMouseEnterExit alloc] 132 [[ButtonRemembersMouseEnterExit alloc]
131 initWithFrame:NSMakeRect(0, 0, 50, 50)]); 133 initWithFrame:NSMakeRect(0, 0, 50, 50)]);
132 [button setCell:cell.get()]; 134 [button setCell:cell.get()];
133 EXPECT_EQ(0, button.get()->enters_); 135 EXPECT_EQ(0, button.get()->enters_);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 208
207 EXPECT_NE([bookmark_cell verticalTextOffset], 209 EXPECT_NE([bookmark_cell verticalTextOffset],
208 [gradient_cell verticalTextOffset]); 210 [gradient_cell verticalTextOffset]);
209 } 211 }
210 212
211 TEST_F(BookmarkButtonCellTest, OffTheSideCell) { 213 TEST_F(BookmarkButtonCellTest, OffTheSideCell) {
212 Class offTheSideButtonCellClass = NSClassFromString(@"OffTheSideButtonCell"); 214 Class offTheSideButtonCellClass = NSClassFromString(@"OffTheSideButtonCell");
213 EXPECT_TRUE([[BookmarkButtonCell offTheSideButtonCell] 215 EXPECT_TRUE([[BookmarkButtonCell offTheSideButtonCell]
214 isKindOfClass:offTheSideButtonCellClass]); 216 isKindOfClass:offTheSideButtonCellClass]);
215 } 217 }
218
219 // Ensure the |cellWidthForNode:image:| class method reports the same
220 // width as an instantiated cell with the same node and image.
221 TEST_F(BookmarkButtonCellTest, CellWidthForNode) {
222 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
223
224 const BookmarkNode* bar = model->bookmark_bar_node();
225 const BookmarkNode* node_a =
226 model->AddURL(bar, bar->child_count(), base::ASCIIToUTF16("A cell"),
227 GURL("http://www.google.com"));
228 const BookmarkNode* node_b =
229 model->AddURL(bar, bar->child_count(),
230 base::ASCIIToUTF16("This cell has a longer title "),
231 GURL("http://www.google.com/a"));
232 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
233 base::scoped_nsobject<NSImage> image(
234 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
235 CGFloat width_for_node_a =
236 [BookmarkButtonCell cellWidthForNode:node_a image:image];
237 CGFloat width_for_node_b =
238 [BookmarkButtonCell cellWidthForNode:node_b image:image];
239 base::scoped_nsobject<BookmarkButtonCell> bookmark_cell(
240 [[BookmarkButtonCell alloc] initForNode:node_a
241 text:nil
242 image:image
243 menuController:nil]);
244 EXPECT_CGFLOAT_EQ([bookmark_cell cellSize].width, width_for_node_a);
245 [bookmark_cell setBookmarkNode:node_b image:image];
246 EXPECT_CGFLOAT_EQ([bookmark_cell cellSize].width, width_for_node_b);
247 }
216 } // namespace 248 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698