Chromium Code Reviews| 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/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 Loading... | |
| 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 Loading... | |
| 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 TEST_F(BookmarkButtonCellTest, CellWidthForNode) { | |
| 220 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | |
| 221 | |
| 222 const BookmarkNode* bar = model->bookmark_bar_node(); | |
| 223 const BookmarkNode* node_a = | |
| 224 model->AddURL(bar, bar->child_count(), base::ASCIIToUTF16("A cell"), | |
| 225 GURL("http://www.google.com")); | |
| 226 const BookmarkNode* node_b = | |
| 227 model->AddURL(bar, bar->child_count(), | |
| 228 base::ASCIIToUTF16("This cell has a longer title "), | |
| 229 GURL("http://www.google.com/a")); | |
| 230 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 231 base::scoped_nsobject<NSImage> image( | |
| 232 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); | |
| 233 CGFloat width_for_node_a = | |
| 234 [BookmarkButtonCell cellWidthForNode:node_a image:image]; | |
| 235 CGFloat width_for_node_b = | |
| 236 [BookmarkButtonCell cellWidthForNode:node_b image:image]; | |
| 237 base::scoped_nsobject<BookmarkButtonCell> bookmark_cell( | |
| 238 [[BookmarkButtonCell alloc] initForNode:node_a | |
| 239 text:nil | |
| 240 image:image | |
| 241 menuController:nil]); | |
| 242 EXPECT_CGFLOAT_EQ([bookmark_cell cellSize].width, width_for_node_a); | |
|
Elly Fong-Jones
2017/04/04 15:04:36
what is this actually testing?
lgrey
2017/04/04 15:12:27
|width_for_node_a| comes from the class method, |c
Elly Fong-Jones
2017/04/05 11:26:37
Got it - can you add a comment to that effect?
lgrey
2017/04/05 15:21:56
Done.
| |
| 243 [bookmark_cell setBookmarkNode:node_b image:image]; | |
| 244 EXPECT_CGFLOAT_EQ([bookmark_cell cellSize].width, width_for_node_b); | |
| 245 } | |
| 216 } // namespace | 246 } // namespace |
| OLD | NEW |