Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller_unittest.mm

Issue 1986963004: Revert of [Mac][Material Design] Update bookmarks bar to Material Design. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
43 #include "ui/base/theme_provider.h" 42 #include "ui/base/theme_provider.h"
44 #include "ui/events/test/cocoa_test_event_utils.h" 43 #include "ui/events/test/cocoa_test_event_utils.h"
45 #include "ui/gfx/image/image_skia.h" 44 #include "ui/gfx/image/image_skia.h"
46 45
47 using base::ASCIIToUTF16; 46 using base::ASCIIToUTF16;
48 using bookmarks::BookmarkModel; 47 using bookmarks::BookmarkModel;
49 using bookmarks::BookmarkNode; 48 using bookmarks::BookmarkNode;
50 49
51 // Unit tests don't need time-consuming asynchronous animations. 50 // Unit tests don't need time-consuming asynchronous animations.
52 @interface BookmarkBarControllerTestable : BookmarkBarController { 51 @interface BookmarkBarControllerTestable : BookmarkBarController {
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 1007
1009 const BookmarkNode* parent = model->bookmark_bar_node(); 1008 const BookmarkNode* parent = model->bookmark_bar_node();
1010 model->AddURL(parent, parent->child_count(), 1009 model->AddURL(parent, parent->child_count(),
1011 ASCIIToUTF16("title"), GURL("http://one.com")); 1010 ASCIIToUTF16("title"), GURL("http://one.com"));
1012 1011
1013 [bar_ loaded:model]; 1012 [bar_ loaded:model];
1014 1013
1015 // Make sure the internal bookmark button also is the correct height. 1014 // Make sure the internal bookmark button also is the correct height.
1016 NSArray* buttons = [bar_ buttons]; 1015 NSArray* buttons = [bar_ buttons];
1017 EXPECT_GT([buttons count], 0u); 1016 EXPECT_GT([buttons count], 0u);
1018 const bool kIsModeMaterial = ui::MaterialDesignController::IsModeMaterial();
1019
1020 for (NSButton* button in buttons) { 1017 for (NSButton* button in buttons) {
1021 if (kIsModeMaterial) { 1018 EXPECT_FLOAT_EQ(
1022 EXPECT_FLOAT_EQ( 1019 (chrome::kBookmarkBarHeight + bookmarks::kVisualHeightOffset) -
1023 (chrome::kBookmarkBarHeight + 1020 2 * bookmarks::kBookmarkVerticalPadding,
1024 bookmarks::kMaterialVisualHeightOffset) - 1021 [button frame].size.height);
1025 2 * bookmarks::BookmarkVerticalPadding(),
1026 [button frame].size.height);
1027 } else {
1028 EXPECT_FLOAT_EQ(
1029 (chrome::kBookmarkBarHeight + bookmarks::kVisualHeightOffset) -
1030 2 * bookmarks::BookmarkVerticalPadding(),
1031 [button frame].size.height);
1032 }
1033 } 1022 }
1034 } 1023 }
1035 1024
1036 TEST_F(BookmarkBarControllerTest, DropBookmarks) { 1025 TEST_F(BookmarkBarControllerTest, DropBookmarks) {
1037 const char* urls[] = { 1026 const char* urls[] = {
1038 "http://qwantz.com", 1027 "http://qwantz.com",
1039 "http://xkcd.com", 1028 "http://xkcd.com",
1040 "javascript:alert('lolwut')", 1029 "javascript:alert('lolwut')",
1041 "file://localhost/tmp/local-file.txt" // As if dragged from the desktop. 1030 "file://localhost/tmp/local-file.txt" // As if dragged from the desktop.
1042 }; 1031 };
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 [bar_ shrinkOrHideView:view forMaxX:40.0]; 1556 [bar_ shrinkOrHideView:view forMaxX:40.0];
1568 EXPECT_EQ(40.0, NSWidth([view frame])); 1557 EXPECT_EQ(40.0, NSWidth([view frame]));
1569 EXPECT_FALSE([view isHidden]); 1558 EXPECT_FALSE([view isHidden]);
1570 [bar_ shrinkOrHideView:view forMaxX:31.0]; 1559 [bar_ shrinkOrHideView:view forMaxX:31.0];
1571 EXPECT_EQ(31.0, NSWidth([view frame])); 1560 EXPECT_EQ(31.0, NSWidth([view frame]));
1572 EXPECT_FALSE([view isHidden]); 1561 EXPECT_FALSE([view isHidden]);
1573 [bar_ shrinkOrHideView:view forMaxX:29.0]; 1562 [bar_ shrinkOrHideView:view forMaxX:29.0];
1574 EXPECT_TRUE([view isHidden]); 1563 EXPECT_TRUE([view isHidden]);
1575 } 1564 }
1576 1565
1577 // Simiulate browser window width change and ensure that the bookmark buttons
1578 // that should be visible are visible.
1579 TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) { 1566 TEST_F(BookmarkBarControllerTest, LastBookmarkResizeBehavior) {
1580 // Hide the apps shortcut. 1567 // Hide the apps shortcut.
1581 profile()->GetPrefs()->SetBoolean( 1568 profile()->GetPrefs()->SetBoolean(
1582 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false); 1569 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, false);
1583 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); 1570 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
1584 1571
1585 // Add three buttons to the bookmark bar.
1586 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); 1572 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
1587 const BookmarkNode* root = model->bookmark_bar_node(); 1573 const BookmarkNode* root = model->bookmark_bar_node();
1588 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); 1574 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b ");
1589 bookmarks::test::AddNodesFromModelString(model, root, model_string); 1575 bookmarks::test::AddNodesFromModelString(model, root, model_string);
1590 [bar_ frameDidChange]; 1576 [bar_ frameDidChange];
1591 1577
1592 // Step through simulated window resizings. In resizing from the first width
1593 // to the second, the bookmark bar should transition from displaying one
1594 // button to two. Of the next 5 widths, the third transitions the bar from
1595 // displaying two buttons to three. The next width (200.0) resizes the bar to
1596 // a large width that does not change the number of visible buttons, and the
1597 // remaining widths step through all the previous resizings in reverse, which
1598 // should correspond to the previous number of visible buttons.
1599 //
1600 // To recalibrate this test for new OS releases, etc., determine values for
1601 // |view_widths[1]| and |view_widths[4]| which will cause a visible button
1602 // transition from 1 -> 2 and 2 -> 3, respectively. With those two widths you
1603 // can easily compute all widths from 0 through 6. |view_widths[7]| is always
1604 // 200.0, and the remainder are the reverse of widths 0 through 6. When all
1605 // three buttons are visible, be sure to sanity check with frames (i.e. under
1606 // MD the first button should start at x=10, and there should be 16pt of space
1607 // between the buttons).
1608 //
1609 // The default font changed between OSX Mavericks, OSX Yosemite, and 1578 // The default font changed between OSX Mavericks, OSX Yosemite, and
1610 // OSX El Capitan, so this test requires different widths to trigger the 1579 // OSX El Capitan, so this test requires different widths to trigger the
1611 // appropriate results. Button widths and locations also changed with 1580 // appropriate results. The Mavericks and El Capitan font widths are close
1612 // Material Design. 1581 // enough to use the same sizes.
1613 CGFloat view_widths_el_capitan[] = 1582 CGFloat viewWidthsYosemite[] = { 121.0, 122.0, 148.0, 149.0, 150.0, 151.0,
1614 { 121.0, 122.0, 149.0, 150.0, 151.0, 152.0, 1583 152.0, 200.0, 152.0, 151.0, 150.0, 149.0,
1615 153.0, 200.0, 153.0, 152.0, 151.0, 150.0, 1584 148.0, 122.0, 121.0 };
1616 149.0, 122.0, 121.0 }; 1585 CGFloat viewWidthsRest[] = { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0,
1617 CGFloat view_widths_yosemite[] = 1586 155.0, 200.0, 155.0, 154.0, 153.0, 152.0,
1618 { 121.0, 122.0, 148.0, 149.0, 150.0, 151.0, 1587 151.0, 124.0, 123.0 };
1619 152.0, 200.0, 152.0, 151.0, 150.0, 149.0, 1588 CGFloat* viewWidths = base::mac::IsOSYosemite() ? viewWidthsYosemite :
1620 148.0, 122.0, 121.0 }; 1589 viewWidthsRest;
1621 CGFloat view_widths_rest[] =
1622 { 123.0, 124.0, 151.0, 152.0, 153.0, 154.0,
1623 155.0, 200.0, 155.0, 154.0, 153.0, 152.0,
1624 151.0, 124.0, 123.0 };
1625 CGFloat material_view_widths_el_capitan[] =
1626 { 139.0, 140.0, 150.0, 151.0, 152.0, 153.0,
1627 154.0, 200.0, 154.0, 153.0, 152.0, 151.0,
1628 150.0, 140.0, 139.0 };
1629 CGFloat material_view_widths_yosemite[] =
1630 { 140.0, 141.0, 150.0, 151.0, 152.0, 153.0,
1631 154.0, 200.0, 154.0, 153.0, 152.0, 151.0,
1632 150.0, 141.0, 140.0 };
1633 CGFloat material_view_widths_rest[] =
1634 { 142.0, 143.0, 153.0, 154.0, 155.0, 156.0,
1635 157.0, 200.0, 157.0, 156.0, 155.0, 154.0,
1636 153.0, 143.0, 142.0 };
1637 CGFloat* view_widths = NULL;
1638 bool is_mode_material = ui::MaterialDesignController::IsModeMaterial();
1639 if (base::mac::IsOSElCapitan()) {
1640 view_widths = is_mode_material ? material_view_widths_el_capitan
1641 : view_widths_el_capitan;
1642 } else if (base::mac::IsOSYosemite()) {
1643 view_widths = is_mode_material ? material_view_widths_yosemite
1644 : view_widths_yosemite;
1645 } else {
1646 view_widths = is_mode_material ? material_view_widths_rest
1647 : view_widths_rest;
1648 }
1649 1590
1650 BOOL off_the_side_button_is_hidden_results[] = 1591 BOOL offTheSideButtonIsHiddenResults[] = { NO, NO, NO, NO, YES, YES, YES, YES,
1651 { NO, NO, NO, NO, YES, YES, YES, YES, YES, YES, YES, NO, NO, NO, NO}; 1592 YES, YES, YES, NO, NO, NO, NO};
1652 int displayed_button_count_results[] = 1593 int displayedButtonCountResults[] = { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2,
1653 { 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1 }; 1594 2, 1 };
1654 for (unsigned int i = 0; i < arraysize(view_widths_yosemite); ++i) { 1595 for (unsigned int i = 0; i < arraysize(viewWidthsYosemite); ++i) {
1655 NSRect frame = [[bar_ view] frame]; 1596 NSRect frame = [[bar_ view] frame];
1656 frame.size.width = view_widths[i] + bookmarks::BookmarkRightMargin(); 1597 frame.size.width = viewWidths[i] + bookmarks::kBookmarkRightMargin;
1657 [[bar_ view] setFrame:frame]; 1598 [[bar_ view] setFrame:frame];
1658 EXPECT_EQ(off_the_side_button_is_hidden_results[i], 1599 EXPECT_EQ(offTheSideButtonIsHiddenResults[i],
1659 [bar_ offTheSideButtonIsHidden]); 1600 [bar_ offTheSideButtonIsHidden]);
1660 EXPECT_EQ(displayed_button_count_results[i], [bar_ displayedButtonCount]); 1601 EXPECT_EQ(displayedButtonCountResults[i], [bar_ displayedButtonCount]);
1661 } 1602 }
1662 } 1603 }
1663 1604
1664 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) { 1605 TEST_F(BookmarkBarControllerTest, BookmarksWithAppsPageShortcut) {
1665 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); 1606 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
1666 const BookmarkNode* root = model->bookmark_bar_node(); 1607 const BookmarkNode* root = model->bookmark_bar_node();
1667 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b "); 1608 const std::string model_string("1b 2f:[ 2f1b 2f2b ] 3b ");
1668 bookmarks::test::AddNodesFromModelString(model, root, model_string); 1609 bookmarks::test::AddNodesFromModelString(model, root, model_string);
1669 [bar_ frameDidChange]; 1610 [bar_ frameDidChange];
1670 1611
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); 2043 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]);
2103 2044
2104 // Validate initial model. 2045 // Validate initial model.
2105 std::string actualModel = bookmarks::test::ModelStringFromNode(root); 2046 std::string actualModel = bookmarks::test::ModelStringFromNode(root);
2106 EXPECT_EQ(model_string, actualModel); 2047 EXPECT_EQ(model_string, actualModel);
2107 2048
2108 // Test a series of points starting at the right edge of the bar. 2049 // Test a series of points starting at the right edge of the bar.
2109 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"]; 2050 BookmarkButton* targetButton = [bar_ buttonWithTitleEqualTo:@"1b"];
2110 ASSERT_TRUE(targetButton); 2051 ASSERT_TRUE(targetButton);
2111 NSPoint targetPoint = [targetButton left]; 2052 NSPoint targetPoint = [targetButton left];
2112 CGFloat leftMarginIndicatorPosition = bookmarks::BookmarkLeftMargin() - 0.5 * 2053 CGFloat leftMarginIndicatorPosition = bookmarks::kBookmarkLeftMargin - 0.5 *
2113 bookmarks::BookmarkHorizontalPadding(); 2054 bookmarks::kBookmarkHorizontalPadding;
2114 const CGFloat baseOffset = targetPoint.x; 2055 const CGFloat baseOffset = targetPoint.x;
2115 CGFloat expected = leftMarginIndicatorPosition; 2056 CGFloat expected = leftMarginIndicatorPosition;
2116 CGFloat actual = [bar_ indicatorPosForDragToPoint:targetPoint]; 2057 CGFloat actual = [bar_ indicatorPosForDragToPoint:targetPoint];
2117 EXPECT_CGFLOAT_EQ(expected, actual); 2058 EXPECT_CGFLOAT_EQ(expected, actual);
2118 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"]; 2059 targetButton = [bar_ buttonWithTitleEqualTo:@"2f"];
2119 actual = [bar_ indicatorPosForDragToPoint:[targetButton right]]; 2060 actual = [bar_ indicatorPosForDragToPoint:[targetButton right]];
2120 targetButton = [bar_ buttonWithTitleEqualTo:@"3b"]; 2061 targetButton = [bar_ buttonWithTitleEqualTo:@"3b"];
2121 expected = [targetButton left].x - baseOffset + leftMarginIndicatorPosition; 2062 expected = [targetButton left].x - baseOffset + leftMarginIndicatorPosition;
2122 EXPECT_CGFLOAT_EQ(expected, actual); 2063 EXPECT_CGFLOAT_EQ(expected, actual);
2123 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"]; 2064 targetButton = [bar_ buttonWithTitleEqualTo:@"4b"];
2124 targetPoint = [targetButton right]; 2065 targetPoint = [targetButton right];
2125 targetPoint.x += 100; // Somewhere off to the right. 2066 targetPoint.x += 100; // Somewhere off to the right.
2126 CGFloat xDelta = 0.5 * bookmarks::BookmarkHorizontalPadding(); 2067 CGFloat xDelta = 0.5 * bookmarks::kBookmarkHorizontalPadding;
2127 expected = NSMaxX([targetButton frame]) + xDelta; 2068 expected = NSMaxX([targetButton frame]) + xDelta;
2128 actual = [bar_ indicatorPosForDragToPoint:targetPoint]; 2069 actual = [bar_ indicatorPosForDragToPoint:targetPoint];
2129 EXPECT_CGFLOAT_EQ(expected, actual); 2070 EXPECT_CGFLOAT_EQ(expected, actual);
2130 } 2071 }
2131 2072
2132 TEST_F(BookmarkBarControllerDragDropTest, PulseButton) { 2073 TEST_F(BookmarkBarControllerDragDropTest, PulseButton) {
2133 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); 2074 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
2134 const BookmarkNode* root = model->bookmark_bar_node(); 2075 const BookmarkNode* root = model->bookmark_bar_node();
2135 GURL gurl("http://www.google.com"); 2076 GURL gurl("http://www.google.com");
2136 const BookmarkNode* node = model->AddURL(root, root->child_count(), 2077 const BookmarkNode* node = model->AddURL(root, root->child_count(),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2200 "2f3b ] 4b "); 2141 "2f3b ] 4b ");
2201 actual = bookmarks::test::ModelStringFromNode(root); 2142 actual = bookmarks::test::ModelStringFromNode(root);
2202 EXPECT_EQ(expected, actual); 2143 EXPECT_EQ(expected, actual);
2203 2144
2204 // Verify that the other bookmark folder can't be deleted. 2145 // Verify that the other bookmark folder can't be deleted.
2205 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; 2146 BookmarkButton *otherButton = [bar_ otherBookmarksButton];
2206 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); 2147 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]);
2207 } 2148 }
2208 2149
2209 } // namespace 2150 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698