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/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
15 #include "chrome/browser/extensions/test_extension_system.h" | 15 #include "chrome/browser/extensions/test_extension_system.h" |
16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" | 16 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" |
17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" | 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_unittest_helper.h" |
20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h" | 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_view.h" |
21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" | 22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
23 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 23 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
24 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" | 24 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/test/base/testing_pref_service_syncable.h" |
27 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
28 #include "components/bookmarks/browser/bookmark_model.h" | 29 #include "components/bookmarks/browser/bookmark_model.h" |
29 #include "components/bookmarks/browser/bookmark_utils.h" | 30 #include "components/bookmarks/browser/bookmark_utils.h" |
30 #include "components/bookmarks/test/bookmark_test_helpers.h" | 31 #include "components/bookmarks/test/bookmark_test_helpers.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 #import "testing/gtest_mac.h" | 33 #import "testing/gtest_mac.h" |
33 #include "testing/platform_test.h" | 34 #include "testing/platform_test.h" |
34 #import "third_party/ocmock/OCMock/OCMock.h" | 35 #import "third_party/ocmock/OCMock/OCMock.h" |
35 #include "third_party/ocmock/gtest_support.h" | 36 #include "third_party/ocmock/gtest_support.h" |
36 #include "ui/base/cocoa/animation_utils.h" | 37 #include "ui/base/cocoa/animation_utils.h" |
(...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 // Removing the Apps button should move the no item containers to the left. | 1601 // Removing the Apps button should move the no item containers to the left. |
1601 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, | 1602 profile()->GetPrefs()->SetBoolean(prefs::kShowAppsShortcutInBookmarkBar, |
1602 false); | 1603 false); |
1603 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); | 1604 ASSERT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
1604 EXPECT_GT(apps_button_right, | 1605 EXPECT_GT(apps_button_right, |
1605 NSMinX([[[bar_ buttonView] noItemTextfield] frame])); | 1606 NSMinX([[[bar_ buttonView] noItemTextfield] frame])); |
1606 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]), | 1607 EXPECT_LE(NSMaxX([[[bar_ buttonView] noItemTextfield] frame]), |
1607 NSMinX([[[bar_ buttonView] importBookmarksButton] frame])); | 1608 NSMinX([[[bar_ buttonView] importBookmarksButton] frame])); |
1608 } | 1609 } |
1609 | 1610 |
| 1611 TEST_F(BookmarkBarControllerTest, ManagedShowAppsShortcutInBookmarksBar) { |
| 1612 // By default the pref is not managed and the apps shortcut is shown. |
| 1613 TestingPrefServiceSyncable* prefs = profile()->GetTestingPrefService(); |
| 1614 EXPECT_FALSE( |
| 1615 prefs->IsManagedPreference(prefs::kShowAppsShortcutInBookmarkBar)); |
| 1616 EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
| 1617 |
| 1618 // Hide the apps shortcut by policy, via the managed pref. |
| 1619 prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar, |
| 1620 new base::FundamentalValue(false)); |
| 1621 EXPECT_TRUE([bar_ appsPageShortcutButtonIsHidden]); |
| 1622 |
| 1623 // And try showing it via policy too. |
| 1624 prefs->SetManagedPref(prefs::kShowAppsShortcutInBookmarkBar, |
| 1625 new base::FundamentalValue(true)); |
| 1626 EXPECT_FALSE([bar_ appsPageShortcutButtonIsHidden]); |
| 1627 } |
| 1628 |
1610 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { | 1629 class BookmarkBarControllerOpenAllTest : public BookmarkBarControllerTest { |
1611 public: | 1630 public: |
1612 virtual void SetUp() { | 1631 virtual void SetUp() { |
1613 BookmarkBarControllerTest::SetUp(); | 1632 BookmarkBarControllerTest::SetUp(); |
1614 ASSERT_TRUE(profile()); | 1633 ASSERT_TRUE(profile()); |
1615 | 1634 |
1616 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 1635 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
1617 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); | 1636 NSRect parent_frame = NSMakeRect(0, 0, 800, 50); |
1618 bar_.reset( | 1637 bar_.reset( |
1619 [[BookmarkBarControllerOpenAllPong alloc] | 1638 [[BookmarkBarControllerOpenAllPong alloc] |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 "2f3b ] 4b "); | 2093 "2f3b ] 4b "); |
2075 actual = test::ModelStringFromNode(root); | 2094 actual = test::ModelStringFromNode(root); |
2076 EXPECT_EQ(expected, actual); | 2095 EXPECT_EQ(expected, actual); |
2077 | 2096 |
2078 // Verify that the other bookmark folder can't be deleted. | 2097 // Verify that the other bookmark folder can't be deleted. |
2079 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; | 2098 BookmarkButton *otherButton = [bar_ otherBookmarksButton]; |
2080 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); | 2099 EXPECT_FALSE([bar_ canDragBookmarkButtonToTrash:otherButton]); |
2081 } | 2100 } |
2082 | 2101 |
2083 } // namespace | 2102 } // namespace |
OLD | NEW |