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_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"
13 typedef BrowserWithTestWindowTest BookmarkTest
;
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());
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(
27 GURL(content::kAboutBlankURL
), content::Referrer(),
28 content::PAGE_TRANSITION_LINK
, std::string());
30 // Give it a NTP virtual URL.
31 content::NavigationController
* controller
= &web_contents
->GetController();
32 content::NavigationEntry
* entry
= controller
->GetVisibleEntry();
33 entry
->SetVirtualURL(GURL(chrome::kChromeUINewTabURL
));
35 // Verify that the detached bookmark bar is hidden.
36 EXPECT_EQ(BookmarkBar::HIDDEN
, browser()->bookmark_bar_state());
37 browser()->tab_strip_model()->AppendWebContents(web_contents
, true);
38 EXPECT_EQ(BookmarkBar::HIDDEN
, browser()->bookmark_bar_state());
41 class BookmarkInstantExtendedTest
: public BrowserWithTestWindowTest
{
43 BookmarkInstantExtendedTest() {
47 virtual TestingProfile
* CreateProfile() OVERRIDE
{
48 TestingProfile
* profile
= BrowserWithTestWindowTest::CreateProfile();
49 // TemplateURLService is normally NULL during testing. Instant extended
50 // needs this service so set a custom factory function.
51 TemplateURLServiceFactory::GetInstance()->SetTestingFactory(
52 profile
, &BookmarkInstantExtendedTest::CreateTemplateURLService
);
57 static BrowserContextKeyedService
* CreateTemplateURLService(
58 content::BrowserContext
* profile
) {
59 return new TemplateURLService(static_cast<Profile
*>(profile
));
62 DISALLOW_COPY_AND_ASSIGN(BookmarkInstantExtendedTest
);
65 // Verify that in instant extended mode the detached bookmark bar is visible on
67 TEST_F(BookmarkInstantExtendedTest
, DetachedBookmarkBarOnNTP
) {
68 AddTab(browser(), GURL(chrome::kChromeUINewTabURL
));
69 EXPECT_EQ(BookmarkBar::DETACHED
, browser()->bookmark_bar_state());