Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_bar_view_unittest.cc
blob460fb0f56067ed50be406bc6e8fc2f49537f9955
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 "apps/app_launcher.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search/search.h"
11 #include "chrome/browser/search_engines/template_url_service.h"
12 #include "chrome/browser/search_engines/template_url_service_factory.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 "chrome/test/base/ui_test_utils.h"
19 #include "ui/views/controls/button/text_button.h"
21 typedef BrowserWithTestWindowTest BookmarkBarViewTest;
23 // Verify that the apps shortcut is never visible without instant extended.
24 TEST_F(BookmarkBarViewTest, NoAppsShortcutWithoutInstantExtended) {
25 ScopedTestingLocalState local_state(TestingBrowserProcess::GetGlobal());
26 profile()->CreateBookmarkModel(true);
27 ui_test_utils::WaitForBookmarkModelToLoad(profile());
28 BookmarkBarView bookmark_bar_view(browser(), NULL);
29 bookmark_bar_view.set_owned_by_client();
30 EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible());
31 browser()->profile()->GetPrefs()->SetBoolean(
32 prefs::kShowAppsShortcutInBookmarkBar, true);
33 EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible());
36 class BookmarkBarViewInstantExtendedTest : public BrowserWithTestWindowTest {
37 public:
38 BookmarkBarViewInstantExtendedTest() {
39 chrome::EnableInstantExtendedAPIForTesting();
42 protected:
43 virtual TestingProfile* CreateProfile() OVERRIDE {
44 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile();
45 // TemplateURLService is normally NULL during testing. Instant extended
46 // needs this service so set a custom factory function.
47 TemplateURLServiceFactory::GetInstance()->SetTestingFactory(
48 profile, &BookmarkBarViewInstantExtendedTest::CreateTemplateURLService);
49 return profile;
52 private:
53 static BrowserContextKeyedService* CreateTemplateURLService(
54 content::BrowserContext* profile) {
55 return new TemplateURLService(static_cast<Profile*>(profile));
58 DISALLOW_COPY_AND_ASSIGN(BookmarkBarViewInstantExtendedTest);
61 // Verify that in instant extended mode the visibility of the apps shortcut
62 // button properly follows the pref value.
63 TEST_F(BookmarkBarViewInstantExtendedTest, AppsShortcutVisibility) {
64 ScopedTestingLocalState local_state(TestingBrowserProcess::GetGlobal());
65 profile()->CreateBookmarkModel(true);
66 ui_test_utils::WaitForBookmarkModelToLoad(profile());
67 BookmarkBarView bookmark_bar_view(browser(), NULL);
68 bookmark_bar_view.set_owned_by_client();
69 browser()->profile()->GetPrefs()->SetBoolean(
70 prefs::kShowAppsShortcutInBookmarkBar, false);
71 EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible());
73 // Try to make the Apps shortcut visible. Its visibility depends on whether
74 // the app launcher is enabled.
75 browser()->profile()->GetPrefs()->SetBoolean(
76 prefs::kShowAppsShortcutInBookmarkBar, true);
77 if (apps::IsAppLauncherEnabled()) {
78 EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible());
79 } else {
80 EXPECT_TRUE(bookmark_bar_view.apps_page_shortcut_->visible());
83 // Make sure we can also properly transition from true to false.
84 browser()->profile()->GetPrefs()->SetBoolean(
85 prefs::kShowAppsShortcutInBookmarkBar, false);
86 EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible());