1 // Copyright (c) 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. 4 5 #include "chrome/browser/search_engines/template_url_service.h" 6 #include "chrome/browser/search_engines/template_url_service_factory.h" 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" 8 #include "chrome/common/url_constants.h" 9 #include "chrome/test/base/browser_with_test_window_test.h" 10 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/web_contents.h" 12 13 typedef BrowserWithTestWindowTest BookmarkTest; 14 15 // Verify that the detached bookmark bar is visible on the new tab page. 16 TEST_F(BookmarkTest, DetachedBookmarkBarOnNTP) { 17 AddTab(browser(), GURL(chrome::kChromeUINewTabURL)); 18 EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state()); 19 } 20 21 // Verify that the detached bookmark bar is hidden on custom NTP pages. 22 TEST_F(BookmarkTest, DetachedBookmarkBarOnCustomNTP) { 23 // Create a empty commited web contents. 24 content::WebContents* web_contents = content::WebContents::Create( 25 content::WebContents::CreateParams(browser()->profile())); 26 web_contents->GetController().LoadURL(GURL(url::kAboutBlankURL), 27 content::Referrer(), 28 content::PAGE_TRANSITION_LINK, 29 std::string()); 30 31 // Give it a NTP virtual URL. 32 content::NavigationController* controller = &web_contents->GetController(); 33 content::NavigationEntry* entry = controller->GetVisibleEntry(); 34 entry->SetVirtualURL(GURL(chrome::kChromeUINewTabURL)); 35 36 // Verify that the detached bookmark bar is hidden. 37 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); 38 browser()->tab_strip_model()->AppendWebContents(web_contents, true); 39 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); 40 } 41 42 class BookmarkInstantExtendedTest : public BrowserWithTestWindowTest { 43 public: 44 BookmarkInstantExtendedTest() { 45 } 46 47 protected: 48 virtual TestingProfile* CreateProfile() OVERRIDE { 49 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile(); 50 // TemplateURLService is normally NULL during testing. Instant extended 51 // needs this service so set a custom factory function. 52 TemplateURLServiceFactory::GetInstance()->SetTestingFactory( 53 profile, &BookmarkInstantExtendedTest::CreateTemplateURLService); 54 return profile; 55 } 56 57 private: 58 static KeyedService* CreateTemplateURLService( 59 content::BrowserContext* profile) { 60 return new TemplateURLService(static_cast<Profile*>(profile)); 61 } 62 63 DISALLOW_COPY_AND_ASSIGN(BookmarkInstantExtendedTest); 64 }; 65 66 // Verify that in instant extended mode the detached bookmark bar is visible on 67 // the new tab page. 68 TEST_F(BookmarkInstantExtendedTest, DetachedBookmarkBarOnNTP) { 69 AddTab(browser(), GURL(chrome::kChromeUINewTabURL)); 70 EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state()); 71 } 72