1 // Copyright (c) 2012 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/ui/gtk/bookmarks/bookmark_bar_gtk.h"
7 #include "base/compiler_specific.h"
8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h"
11 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
12 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/gtk/tabstrip_origin_provider.h"
15 #include "chrome/test/base/test_browser_window.h"
16 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 // Dummy implementation that's good enough for the tests; we don't test
21 // rendering here so all we need is a non-NULL object.
22 class EmptyTabstripOriginProvider
: public TabstripOriginProvider
{
24 virtual gfx::Point
GetTabStripOriginForWidget(GtkWidget
* widget
) OVERRIDE
{
25 return gfx::Point(0, 0);
29 class BookmarkBarGtkUnittest
: public testing::Test
{
31 virtual void SetUp() OVERRIDE
{
32 profile_
.reset(new TestingProfile());
33 profile_
->CreateBookmarkModel(true);
34 model_
= BookmarkModelFactory::GetForProfile(profile_
.get());
35 test::WaitForBookmarkModelToLoad(model_
);
37 Browser::CreateParams
native_params(profile_
.get(),
38 chrome::GetActiveDesktop());
40 chrome::CreateBrowserWithTestWindowForParams(&native_params
));
41 origin_provider_
.reset(new EmptyTabstripOriginProvider
);
42 bookmark_bar_
.reset(new BookmarkBarGtk(NULL
, browser_
.get(),
43 origin_provider_
.get()));
46 virtual void TearDown() OVERRIDE
{
47 base::RunLoop().RunUntilIdle();
49 bookmark_bar_
.reset();
50 origin_provider_
.reset();
55 BookmarkModel
* model_
;
57 content::TestBrowserThreadBundle thread_bundle_
;
59 scoped_ptr
<TestingProfile
> profile_
;
60 scoped_ptr
<Browser
> browser_
;
61 scoped_ptr
<TabstripOriginProvider
> origin_provider_
;
62 scoped_ptr
<BookmarkBarGtk
> bookmark_bar_
;
65 TEST_F(BookmarkBarGtkUnittest
, DisplaysHelpMessageOnEmpty
) {
66 bookmark_bar_
->BookmarkModelLoaded(model_
, false);
68 // There are no bookmarks in the model by default. Expect that the
69 // |instructions_label| is shown.
70 EXPECT_TRUE(bookmark_bar_
->show_instructions_
);
73 TEST_F(BookmarkBarGtkUnittest
, HidesHelpMessageWithBookmark
) {
74 const BookmarkNode
* parent
= model_
->bookmark_bar_node();
75 model_
->AddURL(parent
, parent
->child_count(),
76 base::ASCIIToUTF16("title"), GURL("http://one.com"));
78 bookmark_bar_
->BookmarkModelLoaded(model_
, false);
79 EXPECT_FALSE(bookmark_bar_
->show_instructions_
);
82 TEST_F(BookmarkBarGtkUnittest
, BuildsButtons
) {
83 const BookmarkNode
* parent
= model_
->bookmark_bar_node();
84 model_
->AddURL(parent
, parent
->child_count(),
85 base::ASCIIToUTF16("title"), GURL("http://one.com"));
86 model_
->AddURL(parent
, parent
->child_count(),
87 base::ASCIIToUTF16("other"), GURL("http://two.com"));
89 bookmark_bar_
->BookmarkModelLoaded(model_
, false);
91 // We should expect two children to the bookmark bar's toolbar.
92 GList
* children
= gtk_container_get_children(
93 GTK_CONTAINER(bookmark_bar_
->bookmark_toolbar_
.get()));
94 EXPECT_EQ(2U, g_list_length(children
));
95 g_list_free(children
);