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 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 | 1011 |
1012 const BookmarkNode* parent = model->bookmark_bar_node(); | 1012 const BookmarkNode* parent = model->bookmark_bar_node(); |
1013 model->AddURL(parent, parent->child_count(), | 1013 model->AddURL(parent, parent->child_count(), |
1014 ASCIIToUTF16("title"), GURL("http://one.com")); | 1014 ASCIIToUTF16("title"), GURL("http://one.com")); |
1015 | 1015 |
1016 [bar_ loaded:model]; | 1016 [bar_ loaded:model]; |
1017 | 1017 |
1018 // Make sure the internal bookmark button also is the correct height. | 1018 // Make sure the internal bookmark button also is the correct height. |
1019 NSArray* buttons = [bar_ buttons]; | 1019 NSArray* buttons = [bar_ buttons]; |
1020 EXPECT_GT([buttons count], 0u); | 1020 EXPECT_GT([buttons count], 0u); |
1021 const bool kIsModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | |
1022 | 1021 |
1023 for (NSButton* button in buttons) { | 1022 for (NSButton* button in buttons) { |
1024 if (kIsModeMaterial) { | 1023 EXPECT_FLOAT_EQ((chrome::kMinimumBookmarkBarHeight + |
1025 EXPECT_FLOAT_EQ((chrome::kMinimumBookmarkBarHeight + | 1024 bookmarks::kMaterialVisualHeightOffset) - |
1026 bookmarks::kMaterialVisualHeightOffset) - | 1025 2 * bookmarks::kBookmarkVerticalPadding, |
1027 2 * bookmarks::BookmarkVerticalPadding(), | 1026 [button frame].size.height); |
1028 [button frame].size.height); | |
1029 } else { | |
1030 EXPECT_FLOAT_EQ( | |
1031 (chrome::kMinimumBookmarkBarHeight + bookmarks::kVisualHeightOffset) - | |
1032 2 * bookmarks::BookmarkVerticalPadding(), | |
1033 [button frame].size.height); | |
1034 } | |
1035 } | 1027 } |
1036 } | 1028 } |
1037 | 1029 |
1038 TEST_F(BookmarkBarControllerTest, DropBookmarks) { | 1030 TEST_F(BookmarkBarControllerTest, DropBookmarks) { |
1039 const char* urls[] = { | 1031 const char* urls[] = { |
1040 "http://qwantz.com", | 1032 "http://qwantz.com", |
1041 "http://xkcd.com", | 1033 "http://xkcd.com", |
1042 "javascript:alert('lolwut')", | 1034 "javascript:alert('lolwut')", |
1043 "file://localhost/tmp/local-file.txt" // As if dragged from the desktop. | 1035 "file://localhost/tmp/local-file.txt" // As if dragged from the desktop. |
1044 }; | 1036 }; |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 // |view_widths[1]| and |view_widths[4]| which will cause a visible button | 1596 // |view_widths[1]| and |view_widths[4]| which will cause a visible button |
1605 // transition from 1 -> 2 and 2 -> 3, respectively. With those two widths you | 1597 // transition from 1 -> 2 and 2 -> 3, respectively. With those two widths you |
1606 // can easily compute all widths from 0 through 6. |view_widths[7]| is always | 1598 // can easily compute all widths from 0 through 6. |view_widths[7]| is always |
1607 // 200.0, and the remainder are the reverse of widths 0 through 6. When all | 1599 // 200.0, and the remainder are the reverse of widths 0 through 6. When all |
1608 // three buttons are visible, be sure to sanity check with frames (i.e. under | 1600 // three buttons are visible, be sure to sanity check with frames (i.e. under |
1609 // MD the first button should start at x=10, and there should be 16pt of space | 1601 // MD the first button should start at x=10, and there should be 16pt of space |
1610 // between the buttons). | 1602 // between the buttons). |
1611 // | 1603 // |
1612 // The default font changed between OSX Mavericks, OSX Yosemite, and | 1604 // The default font changed between OSX Mavericks, OSX Yosemite, and |
1613 // OSX El Capitan, so this test requires different widths to trigger the | 1605 // OSX El Capitan, so this test requires different widths to trigger the |
1614 // appropriate results. Button widths and locations also changed with | 1606 // appropriate results. |
1615 // Material Design. | |
1616 CGFloat view_widths_el_capitan[] = | 1607 CGFloat view_widths_el_capitan[] = |
1617 { 121.0, 122.0, 149.0, 150.0, 151.0, 152.0, | |
1618 153.0, 200.0, 153.0, 152.0, 151.0, 150.0, | |
1619 149.0, 122.0, 121.0 }; | |
1620 CGFloat view_widths_yosemite[] = | |
1621 { 121.0, 122.0, 148.0, 149.0, 150.0, 151.0, | |
1622 152.0, 200.0, 152.0, 151.0, 150.0, 149.0, | |
1623 148.0, 122.0, 121.0 }; | |
1624 CGFloat view_widths_rest[] = | |
1625 { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0, | |
1626 155.0, 200.0, 155.0, 154.0, 153.0, 152.0, | |
1627 151.0, 124.0, 123.0 }; | |
1628 CGFloat material_view_widths_el_capitan[] = | |
1629 { 139.0, 140.0, 150.0, 151.0, 152.0, 153.0, | 1608 { 139.0, 140.0, 150.0, 151.0, 152.0, 153.0, |
1630 154.0, 200.0, 154.0, 153.0, 152.0, 151.0, | 1609 154.0, 200.0, 154.0, 153.0, 152.0, 151.0, |
1631 150.0, 140.0, 139.0 }; | 1610 150.0, 140.0, 139.0 }; |
1632 CGFloat material_view_widths_yosemite[] = | 1611 CGFloat view_widths_yosemite[] = |
1633 { 140.0, 141.0, 150.0, 151.0, 152.0, 153.0, | 1612 { 140.0, 141.0, 150.0, 151.0, 152.0, 153.0, |
1634 154.0, 200.0, 154.0, 153.0, 152.0, 151.0, | 1613 154.0, 200.0, 154.0, 153.0, 152.0, 151.0, |
1635 150.0, 141.0, 140.0 }; | 1614 150.0, 141.0, 140.0 }; |
1636 CGFloat material_view_widths_rest[] = | 1615 CGFloat view_widths_rest[] = |
1637 { 142.0, 143.0, 153.0, 154.0, 155.0, 156.0, | 1616 { 142.0, 143.0, 153.0, 154.0, 155.0, 156.0, |
1638 157.0, 200.0, 157.0, 156.0, 155.0, 154.0, | 1617 157.0, 200.0, 157.0, 156.0, 155.0, 154.0, |
1639 153.0, 143.0, 142.0 }; | 1618 153.0, 143.0, 142.0 }; |
1640 CGFloat* view_widths = NULL; | 1619 CGFloat* view_widths = NULL; |
1641 bool is_mode_material = ui::MaterialDesignController::IsModeMaterial(); | |
1642 if (base::mac::IsOS10_11()) { | 1620 if (base::mac::IsOS10_11()) { |
1643 view_widths = is_mode_material ? material_view_widths_el_capitan | 1621 view_widths = view_widths_el_capitan; |
1644 : view_widths_el_capitan; | |
1645 } else if (base::mac::IsOS10_10()) { | 1622 } else if (base::mac::IsOS10_10()) { |
1646 view_widths = is_mode_material ? material_view_widths_yosemite | 1623 view_widths = view_widths_yosemite; |
1647 : view_widths_yosemite; | |
1648 } else { | 1624 } else { |
1649 view_widths = is_mode_material ? material_view_widths_rest | 1625 view_widths = view_widths_rest; |
1650 : view_widths_rest; | |
1651 } | 1626 } |
1652 | 1627 |
1653 BOOL off_the_side_button_is_hidden_results[] = | 1628 BOOL off_the_side_button_is_hidden_results[] = |
1654 { NO, NO, NO, NO, YES, YES, YES, YES, YES, YES, YES, NO, NO, NO, NO}; | 1629 { NO, NO, NO, NO, YES, YES, YES, YES, YES, YES, YES, NO, NO, NO, NO}; |
1655 int displayed_button_count_results[] = | 1630 int displayed_button_count_results[] = |
1656 { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1 }; | 1631 { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1 }; |
1657 for (unsigned int i = 0; i < arraysize(view_widths_yosemite); ++i) { | 1632 for (unsigned int i = 0; i < arraysize(view_widths_yosemite); ++i) { |
1658 NSRect frame = [[bar_ view] frame]; | 1633 NSRect frame = [[bar_ view] frame]; |
1659 frame.size.width = view_widths[i] + bookmarks::BookmarkRightMargin(); | 1634 frame.size.width = view_widths[i] + bookmarks::kBookmarkRightMargin; |
1660 [[bar_ view] setFrame:frame]; | 1635 [[bar_ view] setFrame:frame]; |
1661 EXPECT_EQ(off_the_side_button_is_hidden_results[i], | 1636 EXPECT_EQ(off_the_side_button_is_hidden_results[i], |
1662 [bar_ offTheSideButtonIsHidden]); | 1637 [bar_ offTheSideButtonIsHidden]); |
1663 EXPECT_EQ(displayed_button_count_results[i], [bar_ displayedButtonCount]); | 1638 EXPECT_EQ(displayed_button_count_results[i], [bar_ displayedButtonCount]); |
1664 } | 1639 } |
1665 } | 1640 } |
1666 | 1641 |
1667 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) { | 1642 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) { |
1668 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 1643 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
1669 const BookmarkNode* root = model->bookmark_bar_node(); | 1644 const BookmarkNode* root = model->bookmark_bar_node(); |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2107 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 2082 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
2108 | 2083 |
2109 // Validate initial model. | 2084 // Validate initial model. |
2110 std::string actualModel = bookmarks::test::ModelStringFromNode(root); | 2085 std::string actualModel = bookmarks::test::ModelStringFromNode(root); |
2111 EXPECT_EQ(model_string, actualModel); | 2086 EXPECT_EQ(model_string, actualModel); |
2112 | 2087 |
2113 // Test a series of points starting at the right edge of the bar. | 2088 // Test a series of points starting at the right edge of the bar. |
2114 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; | 2089 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; |
2115 ASSERT_TRUE(targetButton); | 2090 ASSERT_TRUE(targetButton); |
2116 NSPoint targetPoint = [targetButton left]; | 2091 NSPoint targetPoint = [targetButton left]; |
2117 CGFloat leftMarginIndicatorPosition = bookmarks::BookmarkLeftMargin() - 0.5 * | 2092 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 * |
2118 bookmarks::BookmarkHorizontalPadding(); | 2093 bookmarks::kBookmarkHorizontalPadding; |
2119 const CGFloat baseOffset = targetPoint.x; | 2094 const CGFloat baseOffset = targetPoint.x; |
2120 CGFloat expected = leftMarginIndicatorPosition; | 2095 CGFloat expected = leftMarginIndicatorPosition; |
2121 CGFloat actual = [bar_ indicatorPosForDragToPoint:targetPoint]; | 2096 CGFloat actual = [bar_ indicatorPosForDragToPoint:targetPoint]; |
2122 EXPECT_CGFLOAT_EQ(expected, actual); | 2097 EXPECT_CGFLOAT_EQ(expected, actual); |
2123 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; | 2098 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; |
2124 actual = [bar_ indicatorPosForDragToPoint:[targetButton right]]; | 2099 actual = [bar_ indicatorPosForDragToPoint:[targetButton right]]; |
2125 targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; | 2100 targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; |
2126 expected = [targetButton left].x - baseOffset + leftMarginIndicatorPosition; | 2101 expected = [targetButton left].x - baseOffset + leftMarginIndicatorPosition; |
2127 EXPECT_CGFLOAT_EQ(expected, actual); | 2102 EXPECT_CGFLOAT_EQ(expected, actual); |
2128 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; | 2103 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; |
2129 targetPoint = [targetButton right]; | 2104 targetPoint = [targetButton right]; |
2130 targetPoint.x += 100; // Somewhere off to the right. | 2105 targetPoint.x += 100; // Somewhere off to the right. |
2131 CGFloat xDelta = 0.5 * bookmarks::BookmarkHorizontalPadding(); | 2106 CGFloat xDelta = 0.5 * bookmarks::kBookmarkHorizontalPadding; |
2132 expected = NSMaxX([targetButton frame]) + xDelta; | 2107 expected = NSMaxX([targetButton frame]) + xDelta; |
2133 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; | 2108 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; |
2134 EXPECT_CGFLOAT_EQ(expected, actual); | 2109 EXPECT_CGFLOAT_EQ(expected, actual); |
2135 } | 2110 } |
2136 | 2111 |
2137 TEST_F(BookmarkBarControllerDragDropTest, PulseButton) { | 2112 TEST_F(BookmarkBarControllerDragDropTest, PulseButton) { |
2138 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 2113 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
2139 const BookmarkNode* root = model->bookmark_bar_node(); | 2114 const BookmarkNode* root = model->bookmark_bar_node(); |
2140 GURL gurl("http://www.google.com"); | 2115 GURL gurl("http://www.google.com"); |
2141 const BookmarkNode* node = model->AddURL(root, root->child_count(), | 2116 const BookmarkNode* node = model->AddURL(root, root->child_count(), |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2205 "2f3b ] 4b "); | 2180 "2f3b ] 4b "); |
2206 actual = bookmarks::test::ModelStringFromNode(root); | 2181 actual = bookmarks::test::ModelStringFromNode(root); |
2207 EXPECT_EQ(expected, actual); | 2182 EXPECT_EQ(expected, actual); |
2208 | 2183 |
2209 // Verify that the other bookmark folder can't be deleted. | 2184 // Verify that the other bookmark folder can't be deleted. |
2210 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2185 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
2211 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2186 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
2212 } | 2187 } |
2213 | 2188 |
2214 } // namespace | 2189 } // namespace |
OLD | NEW |