| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h" | 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h" |
| 6 | 6 |
| 7 #include "base/task.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" |
| 8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/gtk/tabstrip_origin_provider.h" | 12 #include "chrome/browser/ui/gtk/tabstrip_origin_provider.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/test/test_browser_thread.h" | 14 #include "content/test/test_browser_thread.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 using content::BrowserThread; | 17 using content::BrowserThread; |
| 17 | 18 |
| 18 // Dummy implementation that's good enough for the tests; we don't test | 19 // Dummy implementation that's good enough for the tests; we don't test |
| 19 // rendering here so all we need is a non-NULL object. | 20 // rendering here so all we need is a non-NULL object. |
| 20 class EmptyTabstripOriginProvider : public TabstripOriginProvider { | 21 class EmptyTabstripOriginProvider : public TabstripOriginProvider { |
| 21 public: | 22 public: |
| 22 virtual gfx::Point GetTabStripOriginForWidget(GtkWidget* widget) { | 23 virtual gfx::Point GetTabStripOriginForWidget(GtkWidget* widget) { |
| 23 return gfx::Point(0, 0); | 24 return gfx::Point(0, 0); |
| 24 } | 25 } |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 class BookmarkBarGtkUnittest : public testing::Test { | 28 class BookmarkBarGtkUnittest : public testing::Test { |
| 28 protected: | 29 protected: |
| 29 BookmarkBarGtkUnittest() | 30 BookmarkBarGtkUnittest() |
| 30 : ui_thread_(BrowserThread::UI, &message_loop_), | 31 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 31 file_thread_(BrowserThread::FILE, &message_loop_) { | 32 file_thread_(BrowserThread::FILE, &message_loop_) { |
| 32 } | 33 } |
| 33 | 34 |
| 34 virtual void SetUp() { | 35 virtual void SetUp() OVERRIDE { |
| 35 profile_.reset(new TestingProfile()); | 36 profile_.reset(new TestingProfile()); |
| 36 profile_->CreateBookmarkModel(true); | 37 profile_->CreateBookmarkModel(true); |
| 37 profile_->BlockUntilBookmarkModelLoaded(); | 38 profile_->BlockUntilBookmarkModelLoaded(); |
| 39 model_ = profile_->GetBookmarkModel(); |
| 40 |
| 38 browser_.reset(new Browser(Browser::TYPE_TABBED, profile_.get())); | 41 browser_.reset(new Browser(Browser::TYPE_TABBED, profile_.get())); |
| 39 | |
| 40 origin_provider_.reset(new EmptyTabstripOriginProvider); | 42 origin_provider_.reset(new EmptyTabstripOriginProvider); |
| 41 bookmark_bar_.reset(new BookmarkBarGtk(NULL, browser_.get(), | 43 bookmark_bar_.reset(new BookmarkBarGtk(NULL, browser_.get(), |
| 42 origin_provider_.get())); | 44 origin_provider_.get())); |
| 43 } | 45 } |
| 44 | 46 |
| 45 virtual void TearDown() { | 47 virtual void TearDown() OVERRIDE { |
| 46 message_loop_.RunAllPending(); | 48 message_loop_.RunAllPending(); |
| 47 | 49 |
| 48 bookmark_bar_.reset(); | 50 bookmark_bar_.reset(); |
| 49 origin_provider_.reset(); | 51 origin_provider_.reset(); |
| 50 browser_.reset(); | 52 browser_.reset(); |
| 51 profile_.reset(); | 53 profile_.reset(); |
| 52 } | 54 } |
| 53 | 55 |
| 56 BookmarkModel* model_; |
| 57 |
| 54 MessageLoopForUI message_loop_; | 58 MessageLoopForUI message_loop_; |
| 55 content::TestBrowserThread ui_thread_; | 59 content::TestBrowserThread ui_thread_; |
| 56 content::TestBrowserThread file_thread_; | 60 content::TestBrowserThread file_thread_; |
| 57 | 61 |
| 58 scoped_ptr<TestingProfile> profile_; | 62 scoped_ptr<TestingProfile> profile_; |
| 59 scoped_ptr<Browser> browser_; | 63 scoped_ptr<Browser> browser_; |
| 60 scoped_ptr<TabstripOriginProvider> origin_provider_; | 64 scoped_ptr<TabstripOriginProvider> origin_provider_; |
| 61 scoped_ptr<BookmarkBarGtk> bookmark_bar_; | 65 scoped_ptr<BookmarkBarGtk> bookmark_bar_; |
| 62 }; | 66 }; |
| 63 | 67 |
| 64 TEST_F(BookmarkBarGtkUnittest, DisplaysHelpMessageOnEmpty) { | 68 TEST_F(BookmarkBarGtkUnittest, DisplaysHelpMessageOnEmpty) { |
| 65 BookmarkModel* model = profile_->GetBookmarkModel(); | 69 bookmark_bar_->Loaded(model_, false); |
| 66 bookmark_bar_->Loaded(model, false); | |
| 67 | 70 |
| 68 // There are no bookmarks in the model by default. Expect that the | 71 // There are no bookmarks in the model by default. Expect that the |
| 69 // |instructions_label| is shown. | 72 // |instructions_label| is shown. |
| 70 EXPECT_TRUE(bookmark_bar_->show_instructions_); | 73 EXPECT_TRUE(bookmark_bar_->show_instructions_); |
| 71 } | 74 } |
| 72 | 75 |
| 73 TEST_F(BookmarkBarGtkUnittest, HidesHelpMessageWithBookmark) { | 76 TEST_F(BookmarkBarGtkUnittest, HidesHelpMessageWithBookmark) { |
| 74 BookmarkModel* model = profile_->GetBookmarkModel(); | 77 const BookmarkNode* parent = model_->bookmark_bar_node(); |
| 78 model_->AddURL(parent, parent->child_count(), |
| 79 ASCIIToUTF16("title"), GURL("http://one.com")); |
| 75 | 80 |
| 76 const BookmarkNode* parent = model->bookmark_bar_node(); | 81 bookmark_bar_->Loaded(model_, false); |
| 77 model->AddURL(parent, parent->child_count(), | |
| 78 ASCIIToUTF16("title"), GURL("http://one.com")); | |
| 79 | |
| 80 bookmark_bar_->Loaded(model, false); | |
| 81 EXPECT_FALSE(bookmark_bar_->show_instructions_); | 82 EXPECT_FALSE(bookmark_bar_->show_instructions_); |
| 82 } | 83 } |
| 83 | 84 |
| 84 TEST_F(BookmarkBarGtkUnittest, BuildsButtons) { | 85 TEST_F(BookmarkBarGtkUnittest, BuildsButtons) { |
| 85 BookmarkModel* model = profile_->GetBookmarkModel(); | 86 const BookmarkNode* parent = model_->bookmark_bar_node(); |
| 87 model_->AddURL(parent, parent->child_count(), |
| 88 ASCIIToUTF16("title"), GURL("http://one.com")); |
| 89 model_->AddURL(parent, parent->child_count(), |
| 90 ASCIIToUTF16("other"), GURL("http://two.com")); |
| 86 | 91 |
| 87 const BookmarkNode* parent = model->bookmark_bar_node(); | 92 bookmark_bar_->Loaded(model_, false); |
| 88 model->AddURL(parent, parent->child_count(), | |
| 89 ASCIIToUTF16("title"), GURL("http://one.com")); | |
| 90 model->AddURL(parent, parent->child_count(), | |
| 91 ASCIIToUTF16("other"), GURL("http://two.com")); | |
| 92 | |
| 93 bookmark_bar_->Loaded(model, false); | |
| 94 | 93 |
| 95 // We should expect two children to the bookmark bar's toolbar. | 94 // We should expect two children to the bookmark bar's toolbar. |
| 96 GList* children = gtk_container_get_children( | 95 GList* children = gtk_container_get_children( |
| 97 GTK_CONTAINER(bookmark_bar_->bookmark_toolbar_.get())); | 96 GTK_CONTAINER(bookmark_bar_->bookmark_toolbar_.get())); |
| 98 EXPECT_EQ(2U, g_list_length(children)); | 97 EXPECT_EQ(2U, g_list_length(children)); |
| 99 g_list_free(children); | 98 g_list_free(children); |
| 100 } | 99 } |
| OLD | NEW |