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 "base/memory/scoped_ptr.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 "components/search_engines/search_terms_data.h"
11 #include "components/search_engines/template_url_service.h"
12 #include "components/search_engines/template_url_service_client.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/web_contents.h"
16 typedef BrowserWithTestWindowTest BookmarkTest
;
18 // Verify that the detached bookmark bar is visible on the new tab page.
19 TEST_F(BookmarkTest
, DetachedBookmarkBarOnNTP
) {
20 AddTab(browser(), GURL(chrome::kChromeUINewTabURL
));
21 EXPECT_EQ(BookmarkBar::DETACHED
, browser()->bookmark_bar_state());
24 // Verify that the detached bookmark bar is hidden on custom NTP pages.
25 TEST_F(BookmarkTest
, DetachedBookmarkBarOnCustomNTP
) {
26 // Create a empty commited web contents.
27 content::WebContents
* web_contents
= content::WebContents::Create(
28 content::WebContents::CreateParams(browser()->profile()));
29 web_contents
->GetController().LoadURL(GURL(url::kAboutBlankURL
),
31 ui::PAGE_TRANSITION_LINK
,
34 // Give it a NTP virtual URL.
35 content::NavigationController
* controller
= &web_contents
->GetController();
36 content::NavigationEntry
* entry
= controller
->GetVisibleEntry();
37 entry
->SetVirtualURL(GURL(chrome::kChromeUINewTabURL
));
39 // Verify that the detached bookmark bar is hidden.
40 EXPECT_EQ(BookmarkBar::HIDDEN
, browser()->bookmark_bar_state());
41 browser()->tab_strip_model()->AppendWebContents(web_contents
, true);
42 EXPECT_EQ(BookmarkBar::HIDDEN
, browser()->bookmark_bar_state());
45 class BookmarkInstantExtendedTest
: public BrowserWithTestWindowTest
{
47 BookmarkInstantExtendedTest() {
51 TestingProfile
* CreateProfile() override
{
52 TestingProfile
* profile
= BrowserWithTestWindowTest::CreateProfile();
53 // TemplateURLService is normally NULL during testing. Instant extended
54 // needs this service so set a custom factory function.
55 TemplateURLServiceFactory::GetInstance()->SetTestingFactory(
56 profile
, &BookmarkInstantExtendedTest::CreateTemplateURLService
);
61 static scoped_ptr
<KeyedService
> CreateTemplateURLService(
62 content::BrowserContext
* profile
) {
63 return make_scoped_ptr(new TemplateURLService(
64 static_cast<Profile
*>(profile
)->GetPrefs(),
65 make_scoped_ptr(new SearchTermsData
), NULL
,
66 scoped_ptr
<TemplateURLServiceClient
>(), NULL
, NULL
, base::Closure()));
69 DISALLOW_COPY_AND_ASSIGN(BookmarkInstantExtendedTest
);
72 // Verify that in instant extended mode the detached bookmark bar is visible on
74 TEST_F(BookmarkInstantExtendedTest
, DetachedBookmarkBarOnNTP
) {
75 AddTab(browser(), GURL(chrome::kChromeUINewTabURL
));
76 EXPECT_EQ(BookmarkBar::DETACHED
, browser()->bookmark_bar_state());