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/compiler_specific.h" | |
7 #include "base/task.h" | 8 #include "base/task.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(); |
38 browser_.reset(new Browser(Browser::TYPE_TABBED, profile_.get())); | 39 browser_.reset(new Browser(Browser::TYPE_TABBED, profile_.get())); |
39 | 40 |
41 model_ = profile_->GetBookmarkModel(); | |
42 | |
40 origin_provider_.reset(new EmptyTabstripOriginProvider); | 43 origin_provider_.reset(new EmptyTabstripOriginProvider); |
41 bookmark_bar_.reset(new BookmarkBarGtk(NULL, browser_.get(), | 44 bookmark_bar_.reset(new BookmarkBarGtk(NULL, browser_.get(), |
42 origin_provider_.get())); | 45 origin_provider_.get())); |
43 } | 46 } |
44 | 47 |
45 virtual void TearDown() { | 48 virtual void TearDown() OVERRIDE { |
46 message_loop_.RunAllPending(); | 49 message_loop_.RunAllPending(); |
47 | 50 |
48 bookmark_bar_.reset(); | 51 bookmark_bar_.reset(); |
49 origin_provider_.reset(); | 52 origin_provider_.reset(); |
50 browser_.reset(); | 53 browser_.reset(); |
51 profile_.reset(); | 54 profile_.reset(); |
52 } | 55 } |
53 | 56 |
57 protected: | |
58 BookmarkModel* model_; | |
59 scoped_ptr<BookmarkBarGtk> bookmark_bar_; | |
Elliot Glaysher
2011/11/15 17:55:59
If you're going to make this protected, violate th
tfarina
2011/11/15 20:56:26
Done.
| |
60 | |
61 private: | |
54 MessageLoopForUI message_loop_; | 62 MessageLoopForUI message_loop_; |
55 content::TestBrowserThread ui_thread_; | 63 content::TestBrowserThread ui_thread_; |
56 content::TestBrowserThread file_thread_; | 64 content::TestBrowserThread file_thread_; |
57 | 65 |
58 scoped_ptr<TestingProfile> profile_; | 66 scoped_ptr<TestingProfile> profile_; |
59 scoped_ptr<Browser> browser_; | 67 scoped_ptr<Browser> browser_; |
60 scoped_ptr<TabstripOriginProvider> origin_provider_; | 68 scoped_ptr<TabstripOriginProvider> origin_provider_; |
61 scoped_ptr<BookmarkBarGtk> bookmark_bar_; | |
62 }; | 69 }; |
63 | 70 |
64 TEST_F(BookmarkBarGtkUnittest, DisplaysHelpMessageOnEmpty) { | 71 TEST_F(BookmarkBarGtkUnittest, DisplaysHelpMessageOnEmpty) { |
65 BookmarkModel* model = profile_->GetBookmarkModel(); | 72 bookmark_bar_->Loaded(model_, false); |
66 bookmark_bar_->Loaded(model, false); | |
67 | 73 |
68 // There are no bookmarks in the model by default. Expect that the | 74 // There are no bookmarks in the model by default. Expect that the |
69 // |instructions_label| is shown. | 75 // |instructions_label| is shown. |
70 EXPECT_TRUE(bookmark_bar_->show_instructions_); | 76 EXPECT_TRUE(bookmark_bar_->show_instructions_); |
71 } | 77 } |
72 | 78 |
73 TEST_F(BookmarkBarGtkUnittest, HidesHelpMessageWithBookmark) { | 79 TEST_F(BookmarkBarGtkUnittest, HidesHelpMessageWithBookmark) { |
74 BookmarkModel* model = profile_->GetBookmarkModel(); | 80 const BookmarkNode* parent = model_->bookmark_bar_node(); |
81 model_->AddURL(parent, parent->child_count(), | |
82 ASCIIToUTF16("title"), GURL("http://one.com")); | |
75 | 83 |
76 const BookmarkNode* parent = model->bookmark_bar_node(); | 84 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_); | 85 EXPECT_FALSE(bookmark_bar_->show_instructions_); |
82 } | 86 } |
83 | 87 |
84 TEST_F(BookmarkBarGtkUnittest, BuildsButtons) { | 88 TEST_F(BookmarkBarGtkUnittest, BuildsButtons) { |
85 BookmarkModel* model = profile_->GetBookmarkModel(); | 89 const BookmarkNode* parent = model_->bookmark_bar_node(); |
90 model_->AddURL(parent, parent->child_count(), | |
91 ASCIIToUTF16("title"), GURL("http://one.com")); | |
92 model_->AddURL(parent, parent->child_count(), | |
93 ASCIIToUTF16("other"), GURL("http://two.com")); | |
86 | 94 |
87 const BookmarkNode* parent = model->bookmark_bar_node(); | 95 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 | 96 |
95 // We should expect two children to the bookmark bar's toolbar. | 97 // We should expect two children to the bookmark bar's toolbar. |
96 GList* children = gtk_container_get_children( | 98 GList* children = gtk_container_get_children( |
97 GTK_CONTAINER(bookmark_bar_->bookmark_toolbar_.get())); | 99 GTK_CONTAINER(bookmark_bar_->bookmark_toolbar_.get())); |
98 EXPECT_EQ(2U, g_list_length(children)); | 100 EXPECT_EQ(2U, g_list_length(children)); |
99 g_list_free(children); | 101 g_list_free(children); |
100 } | 102 } |
OLD | NEW |