| 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/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/scoped_feature_list.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 14 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 13 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
| 14 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" | 16 #include "chrome/browser/ui/bookmarks/bookmark_bubble_observer.h" |
| 15 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" | 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h" |
| 18 #include "chrome/browser/ui/cocoa/browser_window_controller.h" | 20 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 21 #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h" |
| 19 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 22 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 20 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" | 23 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" |
| 24 #include "chrome/common/chrome_features.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/bookmarks/browser/bookmark_model.h" | 26 #include "components/bookmarks/browser/bookmark_model.h" |
| 23 #include "components/bookmarks/managed/managed_bookmark_service.h" | 27 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 24 #include "components/signin/core/browser/signin_manager.h" | 28 #include "components/signin/core/browser/signin_manager.h" |
| 25 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #import "testing/gtest_mac.h" | 31 #import "testing/gtest_mac.h" |
| 28 #include "testing/platform_test.h" | 32 #include "testing/platform_test.h" |
| 33 #import "ui/base/cocoa/touch_bar_forward_declarations.h" |
| 34 #import "ui/base/cocoa/touch_bar_util.h" |
| 29 #include "ui/base/material_design/material_design_controller.h" | 35 #include "ui/base/material_design/material_design_controller.h" |
| 30 | 36 |
| 31 using base::ASCIIToUTF16; | 37 using base::ASCIIToUTF16; |
| 32 using bookmarks::BookmarkBubbleObserver; | 38 using bookmarks::BookmarkBubbleObserver; |
| 33 using bookmarks::BookmarkModel; | 39 using bookmarks::BookmarkModel; |
| 34 using bookmarks::BookmarkNode; | 40 using bookmarks::BookmarkNode; |
| 35 using content::WebContents; | 41 using content::WebContents; |
| 36 | 42 |
| 37 namespace { | 43 namespace { |
| 38 | 44 |
| 39 // URL of the test bookmark. | 45 // URL of the test bookmark. |
| 40 const char kTestBookmarkURL[] = "http://www.google.com"; | 46 const char kTestBookmarkURL[] = "http://www.google.com"; |
| 41 | 47 |
| 48 // Touch bar identifier. |
| 49 NSString* const kBookmarkBubbleTouchBarId = @"bookmark-bubble"; |
| 50 |
| 51 // Touch bar item identifiers. |
| 52 NSString* const kRemoveTouchBarId = @"REMOVE"; |
| 53 NSString* const kEditTouchBarId = @"EDIT"; |
| 54 NSString* const kDoneTouchBarId = @"DONE"; |
| 55 |
| 42 class TestBookmarkBubbleObserver : public BookmarkBubbleObserver { | 56 class TestBookmarkBubbleObserver : public BookmarkBubbleObserver { |
| 43 public: | 57 public: |
| 44 TestBookmarkBubbleObserver() {} | 58 TestBookmarkBubbleObserver() {} |
| 45 ~TestBookmarkBubbleObserver() override{}; | 59 ~TestBookmarkBubbleObserver() override{}; |
| 46 | 60 |
| 47 // bookmarks::BookmarkBubbleObserver. | 61 // bookmarks::BookmarkBubbleObserver. |
| 48 void OnBookmarkBubbleShown(const BookmarkNode* node) override { | 62 void OnBookmarkBubbleShown(const BookmarkNode* node) override { |
| 49 ++shown_count_; | 63 ++shown_count_; |
| 50 } | 64 } |
| 51 void OnBookmarkBubbleHidden() override { ++hidden_count_; } | 65 void OnBookmarkBubbleHidden() override { ++hidden_count_; } |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 TEST_F(BookmarkBubbleControllerTest, SyncPromoSignedIn) { | 478 TEST_F(BookmarkBubbleControllerTest, SyncPromoSignedIn) { |
| 465 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); | 479 SigninManager* signin = SigninManagerFactory::GetForProfile(profile()); |
| 466 signin->SetAuthenticatedAccountInfo("fake_username", "fake_username"); | 480 signin->SetAuthenticatedAccountInfo("fake_username", "fake_username"); |
| 467 | 481 |
| 468 const BookmarkNode* node = CreateTestBookmark(); | 482 const BookmarkNode* node = CreateTestBookmark(); |
| 469 BookmarkBubbleController* controller = ControllerForNode(node); | 483 BookmarkBubbleController* controller = ControllerForNode(node); |
| 470 | 484 |
| 471 EXPECT_EQ(0u, [[controller.syncPromoPlaceholder subviews] count]); | 485 EXPECT_EQ(0u, [[controller.syncPromoPlaceholder subviews] count]); |
| 472 } | 486 } |
| 473 | 487 |
| 488 // Verifies the bubble's touch bar. |
| 489 TEST_F(BookmarkBubbleControllerTest, TouchBar) { |
| 490 if (!base::mac::IsAtLeastOS10_12()) |
| 491 return; |
| 492 |
| 493 base::test::ScopedFeatureList feature_list; |
| 494 feature_list.InitAndEnableFeature(features::kBrowserTouchBar); |
| 495 |
| 496 const BookmarkNode* node = CreateTestBookmark(); |
| 497 NSTouchBar* touch_bar = [ControllerForNode(node) makeTouchBar]; |
| 498 NSArray* touch_bar_items = [touch_bar itemIdentifiers]; |
| 499 EXPECT_TRUE([touch_bar_items |
| 500 containsObject:ui::GetTouchBarItemId(kBookmarkBubbleTouchBarId, |
| 501 kRemoveTouchBarId)]); |
| 502 EXPECT_TRUE([touch_bar_items |
| 503 containsObject:ui::GetTouchBarItemId(kBookmarkBubbleTouchBarId, |
| 504 kEditTouchBarId)]); |
| 505 EXPECT_TRUE([touch_bar_items |
| 506 containsObject:ui::GetTouchBarItemId(kBookmarkBubbleTouchBarId, |
| 507 kDoneTouchBarId)]); |
| 508 } |
| 509 |
| 474 } // namespace | 510 } // namespace |
| 475 | 511 |
| 476 @implementation NSApplication (BookmarkBubbleUnitTest) | 512 @implementation NSApplication (BookmarkBubbleUnitTest) |
| 477 // Add handler for the editBookmarkNode: action to NSApp for testing purposes. | 513 // Add handler for the editBookmarkNode: action to NSApp for testing purposes. |
| 478 // Normally this would be sent up the responder tree correctly, but since | 514 // Normally this would be sent up the responder tree correctly, but since |
| 479 // tests run in the background, key window and main window are never set on | 515 // tests run in the background, key window and main window are never set on |
| 480 // NSApplication. Adding it to NSApplication directly removes the need for | 516 // NSApplication. Adding it to NSApplication directly removes the need for |
| 481 // worrying about what the current window with focus is. | 517 // worrying about what the current window with focus is. |
| 482 - (void)editBookmarkNode:(id)sender { | 518 - (void)editBookmarkNode:(id)sender { |
| 483 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); | 519 EXPECT_TRUE([sender respondsToSelector:@selector(node)]); |
| 484 BookmarkBubbleControllerTest::edits_++; | 520 BookmarkBubbleControllerTest::edits_++; |
| 485 } | 521 } |
| 486 | 522 |
| 487 @end | 523 @end |
| OLD | NEW |