12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "chrome/browser/bookmarks/bookmark_test_helpers.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/profiles/profile.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/search_engines/template_url_service.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/search_engines/template_url_service_factory.h" 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_util.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/pref_names.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/url_constants.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/test/base/browser_with_test_window_test.h" 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/test/base/scoped_testing_local_state.h" 17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/test/base/testing_browser_process.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/views/controls/button/text_button.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class BookmarkBarViewInstantExtendedTest : public BrowserWithTestWindowTest { 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BookmarkBarViewInstantExtendedTest() { 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual TestingProfile* CreateProfile() OVERRIDE { 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile(); 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TemplateURLService is normally NULL during testing. Instant extended 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // needs this service so set a custom factory function. 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TemplateURLServiceFactory::GetInstance()->SetTestingFactory( 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile, &BookmarkBarViewInstantExtendedTest::CreateTemplateURLService); 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return profile; 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static BrowserContextKeyedService* CreateTemplateURLService( 37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) content::BrowserContext* profile) { 38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return new TemplateURLService(static_cast<Profile*>(profile)); 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BookmarkBarViewInstantExtendedTest); 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Verify that in instant extended mode the visibility of the apps shortcut 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// button properly follows the pref value. 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(BookmarkBarViewInstantExtendedTest, AppsShortcutVisibility) { 47c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) ScopedTestingLocalState local_state(TestingBrowserProcess::GetGlobal()); 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) profile()->CreateBookmarkModel(true); 4958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) test::WaitForBookmarkModelToLoad(profile()); 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) BookmarkBarView bookmark_bar_view(browser(), NULL); 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bookmark_bar_view.set_owned_by_client(); 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->profile()->GetPrefs()->SetBoolean( 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs::kShowAppsShortcutInBookmarkBar, false); 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible()); 55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 56c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Try to make the Apps shortcut visible. Its visibility depends on whether 57c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // the app launcher is enabled. 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->profile()->GetPrefs()->SetBoolean( 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs::kShowAppsShortcutInBookmarkBar, true); 604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (IsAppLauncherEnabled()) { 61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible()); 62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } else { 63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) EXPECT_TRUE(bookmark_bar_view.apps_page_shortcut_->visible()); 64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make sure we can also properly transition from true to false. 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) browser()->profile()->GetPrefs()->SetBoolean( 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) prefs::kShowAppsShortcutInBookmarkBar, false); 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(bookmark_bar_view.apps_page_shortcut_->visible()); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 71