1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ui/app_list/app_list_util.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/browser_with_test_window_test.h"
16 #include "chrome/test/base/scoped_testing_local_state.h"
17 #include "chrome/test/base/testing_browser_process.h"
18 #include "ui/views/controls/button/text_button.h"
20 class BookmarkBarViewInstantExtendedTest
: public BrowserWithTestWindowTest
{
22 BookmarkBarViewInstantExtendedTest() {
26 virtual TestingProfile
* CreateProfile() OVERRIDE
{
27 TestingProfile
* profile
= BrowserWithTestWindowTest::CreateProfile();
28 // TemplateURLService is normally NULL during testing. Instant extended
29 // needs this service so set a custom factory function.
30 TemplateURLServiceFactory::GetInstance()->SetTestingFactory(
31 profile
, &BookmarkBarViewInstantExtendedTest::CreateTemplateURLService
);
36 static BrowserContextKeyedService
* CreateTemplateURLService(
37 content::BrowserContext
* profile
) {
38 return new TemplateURLService(static_cast<Profile
*>(profile
));
41 DISALLOW_COPY_AND_ASSIGN(BookmarkBarViewInstantExtendedTest
);
44 // Verify that in instant extended mode the visibility of the apps shortcut
45 // button properly follows the pref value.
46 TEST_F(BookmarkBarViewInstantExtendedTest
, AppsShortcutVisibility
) {
47 ScopedTestingLocalState
local_state(TestingBrowserProcess::GetGlobal());
48 profile()->CreateBookmarkModel(true);
49 test::WaitForBookmarkModelToLoad(profile());
50 BookmarkBarView
bookmark_bar_view(browser(), NULL
);
51 bookmark_bar_view
.set_owned_by_client();
52 browser()->profile()->GetPrefs()->SetBoolean(
53 prefs::kShowAppsShortcutInBookmarkBar
, false);
54 EXPECT_FALSE(bookmark_bar_view
.apps_page_shortcut_
->visible());
56 // Try to make the Apps shortcut visible. Its visibility depends on whether
57 // the app launcher is enabled.
58 browser()->profile()->GetPrefs()->SetBoolean(
59 prefs::kShowAppsShortcutInBookmarkBar
, true);
60 if (IsAppLauncherEnabled()) {
61 EXPECT_FALSE(bookmark_bar_view
.apps_page_shortcut_
->visible());
63 EXPECT_TRUE(bookmark_bar_view
.apps_page_shortcut_
->visible());
66 // Make sure we can also properly transition from true to false.
67 browser()->profile()->GetPrefs()->SetBoolean(
68 prefs::kShowAppsShortcutInBookmarkBar
, false);
69 EXPECT_FALSE(bookmark_bar_view
.apps_page_shortcut_
->visible());