| 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 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "components/bookmarks/browser/bookmark_utils.h" | 32 #include "components/bookmarks/browser/bookmark_utils.h" |
| 33 #include "components/bookmarks/common/bookmark_pref_names.h" | 33 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 34 #include "components/bookmarks/test/bookmark_test_helpers.h" | 34 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 35 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 35 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #import "testing/gtest_mac.h" | 37 #import "testing/gtest_mac.h" |
| 38 #include "testing/platform_test.h" | 38 #include "testing/platform_test.h" |
| 39 #import "third_party/ocmock/OCMock/OCMock.h" | 39 #import "third_party/ocmock/OCMock/OCMock.h" |
| 40 #include "third_party/ocmock/gtest_support.h" | 40 #include "third_party/ocmock/gtest_support.h" |
| 41 #include "ui/base/cocoa/animation_utils.h" | 41 #include "ui/base/cocoa/animation_utils.h" |
| 42 #include "ui/base/material_design/material_design_controller.h" |
| 42 #include "ui/base/theme_provider.h" | 43 #include "ui/base/theme_provider.h" |
| 43 #include "ui/events/test/cocoa_test_event_utils.h" | 44 #include "ui/events/test/cocoa_test_event_utils.h" |
| 44 #include "ui/gfx/image/image_skia.h" | 45 #include "ui/gfx/image/image_skia.h" |
| 45 | 46 |
| 46 using base::ASCIIToUTF16; | 47 using base::ASCIIToUTF16; |
| 47 using bookmarks::BookmarkModel; | 48 using bookmarks::BookmarkModel; |
| 48 using bookmarks::BookmarkNode; | 49 using bookmarks::BookmarkNode; |
| 49 | 50 |
| 50 // Unit tests don't need time-consuming asynchronous animations. | 51 // Unit tests don't need time-consuming asynchronous animations. |
| 51 @interface BookmarkBarControllerTestable : BookmarkBarController { | 52 @interface BookmarkBarControllerTestable : BookmarkBarController { |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 | 1008 |
| 1008 const BookmarkNode* parent = model->bookmark_bar_node(); | 1009 const BookmarkNode* parent = model->bookmark_bar_node(); |
| 1009 model->AddURL(parent, parent->child_count(), | 1010 model->AddURL(parent, parent->child_count(), |
| 1010 ASCIIToUTF16("title"), GURL("http://one.com")); | 1011 ASCIIToUTF16("title"), GURL("http://one.com")); |
| 1011 | 1012 |
| 1012 [bar_ loaded:model]; | 1013 [bar_ loaded:model]; |
| 1013 | 1014 |
| 1014 // Make sure the internal bookmark button also is the correct height. | 1015 // Make sure the internal bookmark button also is the correct height. |
| 1015 NSArray* buttons = [bar_ buttons]; | 1016 NSArray* buttons = [bar_ buttons]; |
| 1016 EXPECT_GT([buttons count], 0u); | 1017 EXPECT_GT([buttons count], 0u); |
| 1018 const bool kIsModeMaterial = ui::MaterialDesignController::IsModeMaterial(); |
| 1019 |
| 1017 for (NSButton* button in buttons) { | 1020 for (NSButton* button in buttons) { |
| 1018 EXPECT_FLOAT_EQ( | 1021 if (kIsModeMaterial) { |
| 1019 (chrome::kBookmarkBarHeight + bookmarks::kVisualHeightOffset) - | 1022 EXPECT_FLOAT_EQ( |
| 1020 2 * bookmarks::kBookmarkVerticalPadding, | 1023 (chrome::kBookmarkBarHeight + bookmarks::VisualHeightOffset()) - |
| 1021 [button frame].size.height); | 1024 2 * bookmarks::kMaterialBookmarkVerticalPadding, |
| 1025 [button frame].size.height); |
| 1026 } else { |
| 1027 EXPECT_FLOAT_EQ( |
| 1028 (chrome::kBookmarkBarHeight + bookmarks::VisualHeightOffset()) - |
| 1029 2 * bookmarks::kBookmarkVerticalPadding, |
| 1030 [button frame].size.height); |
| 1031 } |
| 1022 } | 1032 } |
| 1023 } | 1033 } |
| 1024 | 1034 |
| 1025 TEST_F(BookmarkBarControllerTest, DropBookmarks) { | 1035 TEST_F(BookmarkBarControllerTest, DropBookmarks) { |
| 1026 const char* urls[] = { | 1036 const char* urls[] = { |
| 1027 "http://qwantz.com", | 1037 "http://qwantz.com", |
| 1028 "http://xkcd.com", | 1038 "http://xkcd.com", |
| 1029 "javascript:alert('lolwut')", | 1039 "javascript:alert('lolwut')", |
| 1030 "file://localhost/tmp/local-file.txt" // As if dragged from the desktop. | 1040 "file://localhost/tmp/local-file.txt" // As if dragged from the desktop. |
| 1031 }; | 1041 }; |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1587 151.0, 124.0, 123.0 }; | 1597 151.0, 124.0, 123.0 }; |
| 1588 CGFloat* viewWidths = base::mac::IsOSYosemite() ? viewWidthsYosemite : | 1598 CGFloat* viewWidths = base::mac::IsOSYosemite() ? viewWidthsYosemite : |
| 1589 viewWidthsRest; | 1599 viewWidthsRest; |
| 1590 | 1600 |
| 1591 BOOL offTheSideButtonIsHiddenResults[] = { NO, NO, NO, NO, YES, YES, YES, YES, | 1601 BOOL offTheSideButtonIsHiddenResults[] = { NO, NO, NO, NO, YES, YES, YES, YES, |
| 1592 YES, YES, YES, NO, NO, NO, NO}; | 1602 YES, YES, YES, NO, NO, NO, NO}; |
| 1593 int displayedButtonCountResults[] = { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, | 1603 int displayedButtonCountResults[] = { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, |
| 1594 2, 1 }; | 1604 2, 1 }; |
| 1595 for (unsigned int i = 0; i < arraysize(viewWidthsYosemite); ++i) { | 1605 for (unsigned int i = 0; i < arraysize(viewWidthsYosemite); ++i) { |
| 1596 NSRect frame = [[bar_ view] frame]; | 1606 NSRect frame = [[bar_ view] frame]; |
| 1597 frame.size.width = viewWidths[i] + bookmarks::kBookmarkRightMargin; | 1607 frame.size.width = viewWidths[i] + bookmarks::BookmarkRightMargin(); |
| 1598 [[bar_ view] setFrame:frame]; | 1608 [[bar_ view] setFrame:frame]; |
| 1599 EXPECT_EQ(offTheSideButtonIsHiddenResults[i], | 1609 EXPECT_EQ(offTheSideButtonIsHiddenResults[i], |
| 1600 [bar_ offTheSideButtonIsHidden]); | 1610 [bar_ offTheSideButtonIsHidden]); |
| 1601 EXPECT_EQ(displayedButtonCountResults[i], [bar_ displayedButtonCount]); | 1611 EXPECT_EQ(displayedButtonCountResults[i], [bar_ displayedButtonCount]); |
| 1602 } | 1612 } |
| 1603 } | 1613 } |
| 1604 | 1614 |
| 1605 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) { | 1615 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) { |
| 1606 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 1616 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 1607 const BookmarkNode* root = model->bookmark_bar_node(); | 1617 const BookmarkNode* root = model->bookmark_bar_node(); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2043 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 2053 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 2044 | 2054 |
| 2045 // Validate initial model. | 2055 // Validate initial model. |
| 2046 std::string actualModel = bookmarks::test::ModelStringFromNode(root); | 2056 std::string actualModel = bookmarks::test::ModelStringFromNode(root); |
| 2047 EXPECT_EQ(model_string, actualModel); | 2057 EXPECT_EQ(model_string, actualModel); |
| 2048 | 2058 |
| 2049 // Test a series of points starting at the right edge of the bar. | 2059 // Test a series of points starting at the right edge of the bar. |
| 2050 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; | 2060 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; |
| 2051 ASSERT_TRUE(targetButton); | 2061 ASSERT_TRUE(targetButton); |
| 2052 NSPoint targetPoint = [targetButton left]; | 2062 NSPoint targetPoint = [targetButton left]; |
| 2053 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * | 2063 CGFloat leftMarginIndicatorPosition = bookmarks::BookmarkLeftMargin() - 0.5 * |
| 2054 bookmarks::kBookmarkHorizontalPadding; | 2064 bookmarks::BookmarkHorizontalPadding(); |
| 2055 const CGFloat baseOffset = targetPoint.x; | 2065 const CGFloat baseOffset = targetPoint.x; |
| 2056 CGFloat expected = leftMarginIndicatorPosition; | 2066 CGFloat expected = leftMarginIndicatorPosition; |
| 2057 CGFloat actual = [bar_ indicatorPosForDragToPoint:targetPoint]; | 2067 CGFloat actual = [bar_ indicatorPosForDragToPoint:targetPoint]; |
| 2058 EXPECT_CGFLOAT_EQ(expected, actual); | 2068 EXPECT_CGFLOAT_EQ(expected, actual); |
| 2059 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; | 2069 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; |
| 2060 actual = [bar_ indicatorPosForDragToPoint:[targetButton right]]; | 2070 actual = [bar_ indicatorPosForDragToPoint:[targetButton right]]; |
| 2061 targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; | 2071 targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; |
| 2062 expected = [targetButton left].x - baseOffset + leftMarginIndicatorPosition; | 2072 expected = [targetButton left].x - baseOffset + leftMarginIndicatorPosition; |
| 2063 EXPECT_CGFLOAT_EQ(expected, actual); | 2073 EXPECT_CGFLOAT_EQ(expected, actual); |
| 2064 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; | 2074 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; |
| 2065 targetPoint = [targetButton right]; | 2075 targetPoint = [targetButton right]; |
| 2066 targetPoint.x += 100; // Somewhere off to the right. | 2076 targetPoint.x += 100; // Somewhere off to the right. |
| 2067 CGFloat xDelta = 0.5 * bookmarks::kBookmarkHorizontalPadding; | 2077 CGFloat xDelta = 0.5 * bookmarks::BookmarkHorizontalPadding(); |
| 2068 expected = NSMaxX([targetButton frame]) + xDelta; | 2078 expected = NSMaxX([targetButton frame]) + xDelta; |
| 2069 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; | 2079 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; |
| 2070 EXPECT_CGFLOAT_EQ(expected, actual); | 2080 EXPECT_CGFLOAT_EQ(expected, actual); |
| 2071 } | 2081 } |
| 2072 | 2082 |
| 2073 TEST_F(BookmarkBarControllerDragDropTest, PulseButton) { | 2083 TEST_F(BookmarkBarControllerDragDropTest, PulseButton) { |
| 2074 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 2084 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
| 2075 const BookmarkNode* root = model->bookmark_bar_node(); | 2085 const BookmarkNode* root = model->bookmark_bar_node(); |
| 2076 GURL gurl("http://www.google.com"); | 2086 GURL gurl("http://www.google.com"); |
| 2077 const BookmarkNode* node = model->AddURL(root, root->child_count(), | 2087 const BookmarkNode* node = model->AddURL(root, root->child_count(), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 "2f3b ] 4b "); | 2151 "2f3b ] 4b "); |
| 2142 actual = bookmarks::test::ModelStringFromNode(root); | 2152 actual = bookmarks::test::ModelStringFromNode(root); |
| 2143 EXPECT_EQ(expected, actual); | 2153 EXPECT_EQ(expected, actual); |
| 2144 | 2154 |
| 2145 // Verify that the other bookmark folder can't be deleted. | 2155 // Verify that the other bookmark folder can't be deleted. |
| 2146 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2156 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
| 2147 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2157 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
| 2148 } | 2158 } |
| 2149 | 2159 |
| 2150 } // namespace | 2160 } // namespace |
| OLD | NEW |