| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" |
| 7 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/scoped_feature_list.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" | 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_editor_controller.h" |
| 11 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" | 13 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" |
| 14 #include "chrome/common/chrome_features.h" |
| 15 #include "chrome/grit/generated_resources.h" |
| 12 #include "chrome/test/base/test_browser_window.h" | 16 #include "chrome/test/base/test_browser_window.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/bookmarks/browser/bookmark_model.h" | 18 #include "components/bookmarks/browser/bookmark_model.h" |
| 15 #include "components/strings/grit/components_strings.h" | 19 #include "components/strings/grit/components_strings.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #import "testing/gtest_mac.h" | 21 #import "testing/gtest_mac.h" |
| 18 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
| 23 #import "ui/base/cocoa/touch_bar_forward_declarations.h" |
| 24 #import "ui/base/cocoa/touch_bar_util.h" |
| 19 #include "ui/base/l10n/l10n_util_mac.h" | 25 #include "ui/base/l10n/l10n_util_mac.h" |
| 20 | 26 |
| 21 using base::ASCIIToUTF16; | 27 using base::ASCIIToUTF16; |
| 22 using bookmarks::BookmarkExpandedStateTracker; | 28 using bookmarks::BookmarkExpandedStateTracker; |
| 23 using bookmarks::BookmarkModel; | 29 using bookmarks::BookmarkModel; |
| 24 using bookmarks::BookmarkNode; | 30 using bookmarks::BookmarkNode; |
| 25 | 31 |
| 32 namespace { |
| 33 |
| 34 // Touch bar identifier. |
| 35 NSString* const kBookmarkEditDialogTouchBarId = @"bookmark-edit-dialog"; |
| 36 |
| 37 // Touch bar item identifiers. |
| 38 NSString* const kNewFolderTouchBarId = @"NEW-FOLDER"; |
| 39 NSString* const kCancelTouchBarId = @"CANCEL"; |
| 40 NSString* const kSaveTouchBarId = @"SAVE"; |
| 41 |
| 42 } // end namespace |
| 43 |
| 26 class BookmarkEditorBaseControllerTest : public CocoaProfileTest { | 44 class BookmarkEditorBaseControllerTest : public CocoaProfileTest { |
| 27 public: | 45 public: |
| 28 BookmarkEditorBaseController* controller_; // weak | 46 BookmarkEditorBaseController* controller_; // weak |
| 29 const BookmarkNode* folder_a_; | 47 const BookmarkNode* folder_a_; |
| 30 const BookmarkNode* folder_b_; | 48 const BookmarkNode* folder_b_; |
| 31 const BookmarkNode* folder_b_0_; | 49 const BookmarkNode* folder_b_0_; |
| 32 const BookmarkNode* folder_b_3_; | 50 const BookmarkNode* folder_b_3_; |
| 33 const BookmarkNode* folder_c_; | 51 const BookmarkNode* folder_c_; |
| 34 | 52 |
| 35 void CreateModel() { | 53 void CreateModel() { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 273 |
| 256 [controller_ expandNodes:nodes]; | 274 [controller_ expandNodes:nodes]; |
| 257 | 275 |
| 258 actual = [controller_ getExpandedNodes]; | 276 actual = [controller_ getExpandedNodes]; |
| 259 | 277 |
| 260 EXPECT_EQ(nodes, actual); | 278 EXPECT_EQ(nodes, actual); |
| 261 | 279 |
| 262 [controller_ cancel:nil]; | 280 [controller_ cancel:nil]; |
| 263 } | 281 } |
| 264 | 282 |
| 283 // Verifies the dialog's touch bar. |
| 284 TEST_F(BookmarkEditorBaseControllerTest, TouchBar) { |
| 285 if (!base::mac::IsAtLeastOS10_12()) { |
| 286 [controller_ cancel:nil]; |
| 287 return; |
| 288 } |
| 289 |
| 290 base::test::ScopedFeatureList feature_list; |
| 291 feature_list.InitAndEnableFeature(features::kBrowserTouchBar); |
| 292 |
| 293 NSTouchBar* touch_bar = [controller_ makeTouchBar]; |
| 294 NSArray* touch_bar_items = [touch_bar itemIdentifiers]; |
| 295 EXPECT_TRUE([touch_bar_items |
| 296 containsObject:ui::GetTouchBarItemId(kBookmarkEditDialogTouchBarId, |
| 297 kNewFolderTouchBarId)]); |
| 298 EXPECT_TRUE([touch_bar_items |
| 299 containsObject:ui::GetTouchBarItemId(kBookmarkEditDialogTouchBarId, |
| 300 kCancelTouchBarId)]); |
| 301 EXPECT_TRUE([touch_bar_items |
| 302 containsObject:ui::GetTouchBarItemId(kBookmarkEditDialogTouchBarId, |
| 303 kSaveTouchBarId)]); |
| 304 |
| 305 [controller_ cancel:nil]; |
| 306 } |
| 307 |
| 265 class BookmarkFolderInfoTest : public CocoaTest { }; | 308 class BookmarkFolderInfoTest : public CocoaTest { }; |
| 266 | 309 |
| 267 TEST_F(BookmarkFolderInfoTest, Construction) { | 310 TEST_F(BookmarkFolderInfoTest, Construction) { |
| 268 NSMutableArray* children = [NSMutableArray arrayWithObject:@"child"]; | 311 NSMutableArray* children = [NSMutableArray arrayWithObject:@"child"]; |
| 269 // We just need a pointer, and any pointer will do. | 312 // We just need a pointer, and any pointer will do. |
| 270 const BookmarkNode* fakeNode = | 313 const BookmarkNode* fakeNode = |
| 271 reinterpret_cast<const BookmarkNode*>(&children); | 314 reinterpret_cast<const BookmarkNode*>(&children); |
| 272 BookmarkFolderInfo* info = | 315 BookmarkFolderInfo* info = |
| 273 [BookmarkFolderInfo bookmarkFolderInfoWithFolderName:@"name" | 316 [BookmarkFolderInfo bookmarkFolderInfoWithFolderName:@"name" |
| 274 folderNode:fakeNode | 317 folderNode:fakeNode |
| 275 children:children]; | 318 children:children]; |
| 276 EXPECT_TRUE(info); | 319 EXPECT_TRUE(info); |
| 277 EXPECT_EQ([info folderName], @"name"); | 320 EXPECT_EQ([info folderName], @"name"); |
| 278 EXPECT_EQ([info children], children); | 321 EXPECT_EQ([info children], children); |
| 279 EXPECT_EQ([info folderNode], fakeNode); | 322 EXPECT_EQ([info folderNode], fakeNode); |
| 280 } | 323 } |
| OLD | NEW |