Home | History | Annotate | Download | only in bookmarks
      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(
     27         GURL(content::kAboutBlankURL), content::Referrer(),
     28         content::PAGE_TRANSITION_LINK, std::string());
     29 
     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));
     34 
     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());
     39 }
     40 
     41 class BookmarkInstantExtendedTest : public BrowserWithTestWindowTest {
     42  public:
     43   BookmarkInstantExtendedTest() {
     44   }
     45 
     46  protected:
     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);
     53     return profile;
     54   }
     55 
     56  private:
     57   static BrowserContextKeyedService* CreateTemplateURLService(
     58       content::BrowserContext* profile) {
     59     return new TemplateURLService(static_cast<Profile*>(profile));
     60   }
     61 
     62   DISALLOW_COPY_AND_ASSIGN(BookmarkInstantExtendedTest);
     63 };
     64 
     65 // Verify that in instant extended mode the detached bookmark bar is visible on
     66 // the new tab page.
     67 TEST_F(BookmarkInstantExtendedTest, DetachedBookmarkBarOnNTP) {
     68   AddTab(browser(), GURL(chrome::kChromeUINewTabURL));
     69   EXPECT_EQ(BookmarkBar::DETACHED, browser()->bookmark_bar_state());
     70 }
     71