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.
5 #include "chrome/browser/search/search.h"
6 #include "chrome/browser/search_engines/template_url_service.h"
7 #include "chrome/browser/search_engines/template_url_service_factory.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/base/browser_with_test_window_test.h"
11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/web_contents.h"
14 typedef BrowserWithTestWindowTest BookmarkTest;
16 // Verify that the detached bookmark bar is visible on the new tab page.
17 TEST_F(BookmarkTest, DetachedBookmarkBarOnNTP) {
18 AddTab(browser(), GURL(chrome::kChromeUINewTabURL));
19 EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state());
22 // Verify that the detached bookmark bar is hidden on custom NTP pages.
23 TEST_F(BookmarkTest, DetachedBookmarkBarOnCustomNTP) {
24 // Create a empty commited web contents.
25 content::WebContents* web_contents = content::WebContents::Create(
26 content::WebContents::CreateParams(browser()->profile()));
27 web_contents->GetController().LoadURL(
28 GURL(content::kAboutBlankURL), content::Referrer(),
29 content::PAGE_TRANSITION_LINK, std::string());
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));
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());
42 class BookmarkInstantExtendedTest : public BrowserWithTestWindowTest {
44 BookmarkInstantExtendedTest() {
45 chrome::EnableInstantExtendedAPIForTesting();
49 virtual TestingProfile* CreateProfile() OVERRIDE {
50 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile();
51 // TemplateURLService is normally NULL during testing. Instant extended
52 // needs this service so set a custom factory function.
53 TemplateURLServiceFactory::GetInstance()->SetTestingFactory(
54 profile, &BookmarkInstantExtendedTest::CreateTemplateURLService);
59 static BrowserContextKeyedService* CreateTemplateURLService(
60 content::BrowserContext* profile) {
61 return new TemplateURLService(static_cast<Profile*>(profile));
64 DISALLOW_COPY_AND_ASSIGN(BookmarkInstantExtendedTest);
67 // Verify that in instant extended mode the detached bookmark bar is visible on
69 TEST_F(BookmarkInstantExtendedTest, DetachedBookmarkBarOnNTP) {
70 AddTab(browser(), GURL(chrome::kChromeUINewTabURL));
71 EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state());