OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "chrome/browser/automation/ui_controls.h" | 6 #include "chrome/browser/automation/ui_controls.h" |
7 #include "chrome/browser/bookmarks/bookmark_bar_model.h" | 7 #include "chrome/browser/bookmarks/bookmark_model.h" |
8 #include "chrome/browser/page_navigator.h" | 8 #include "chrome/browser/page_navigator.h" |
9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
10 #include "chrome/browser/views/bookmark_bar_view.h" | 10 #include "chrome/browser/views/bookmark_bar_view.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "chrome/common/pref_service.h" | 12 #include "chrome/common/pref_service.h" |
13 #include "chrome/test/testing_profile.h" | 13 #include "chrome/test/testing_profile.h" |
14 #include "chrome/test/interactive_ui/view_event_test_base.h" | 14 #include "chrome/test/interactive_ui/view_event_test_base.h" |
15 #include "chrome/views/chrome_menu.h" | 15 #include "chrome/views/chrome_menu.h" |
16 #include "chrome/views/text_button.h" | 16 #include "chrome/views/text_button.h" |
17 #include "chrome/views/window.h" | 17 #include "chrome/views/window.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 BookmarkBarViewEventTestBase() | 66 BookmarkBarViewEventTestBase() |
67 : ViewEventTestBase(), bb_view_(NULL), model_(NULL) { | 67 : ViewEventTestBase(), bb_view_(NULL), model_(NULL) { |
68 } | 68 } |
69 | 69 |
70 virtual void SetUp() { | 70 virtual void SetUp() { |
71 ChromeViews::MenuItemView::allow_task_nesting_during_run_ = true; | 71 ChromeViews::MenuItemView::allow_task_nesting_during_run_ = true; |
72 BookmarkBarView::testing_ = true; | 72 BookmarkBarView::testing_ = true; |
73 | 73 |
74 profile_.reset(new TestingProfile()); | 74 profile_.reset(new TestingProfile()); |
75 profile_->set_has_history_service(true); | 75 profile_->set_has_history_service(true); |
76 profile_->CreateBookmarkBarModel(true); | 76 profile_->CreateBookmarkModel(true); |
77 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); | 77 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); |
78 | 78 |
79 model_ = profile_->GetBookmarkBarModel(); | 79 model_ = profile_->GetBookmarkModel(); |
80 | 80 |
81 bb_view_ = new BookmarkBarView(profile_.get(), NULL); | 81 bb_view_ = new BookmarkBarView(profile_.get(), NULL); |
82 bb_view_->SetPageNavigator(&navigator_); | 82 bb_view_->SetPageNavigator(&navigator_); |
83 | 83 |
84 AddTestData(CreateBigMenu()); | 84 AddTestData(CreateBigMenu()); |
85 | 85 |
86 // Calculate the preferred size so that one button doesn't fit, which | 86 // Calculate the preferred size so that one button doesn't fit, which |
87 // triggers the overflow button to appear. | 87 // triggers the overflow button to appear. |
88 // | 88 // |
89 // BookmarkBarView::Layout does nothing if the parent is NULL and | 89 // BookmarkBarView::Layout does nothing if the parent is NULL and |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 protected: | 122 protected: |
123 virtual ChromeViews::View* CreateContentsView() { | 123 virtual ChromeViews::View* CreateContentsView() { |
124 return bb_view_; | 124 return bb_view_; |
125 } | 125 } |
126 | 126 |
127 virtual gfx::Size GetPreferredSize() { return bb_view_pref_; } | 127 virtual gfx::Size GetPreferredSize() { return bb_view_pref_; } |
128 | 128 |
129 // See comment above class description for what this does. | 129 // See comment above class description for what this does. |
130 virtual bool CreateBigMenu() { return false; } | 130 virtual bool CreateBigMenu() { return false; } |
131 | 131 |
132 BookmarkBarModel* model_; | 132 BookmarkModel* model_; |
133 BookmarkBarView* bb_view_; | 133 BookmarkBarView* bb_view_; |
134 TestingPageNavigator navigator_; | 134 TestingPageNavigator navigator_; |
135 | 135 |
136 private: | 136 private: |
137 void AddTestData(bool big_menu) { | 137 void AddTestData(bool big_menu) { |
138 std::string test_base = "file:///c:/tmp/"; | 138 std::string test_base = "file:///c:/tmp/"; |
139 | 139 |
140 BookmarkBarNode* f1 = | 140 BookmarkNode* f1 = model_->AddGroup(model_->GetBookmarkBarNode(), 0, L"F1"); |
141 model_->AddGroup(model_->GetBookmarkBarNode(), 0, L"F1"); | |
142 model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a")); | 141 model_->AddURL(f1, 0, L"f1a", GURL(test_base + "f1a")); |
143 BookmarkBarNode* f11 = model_->AddGroup(f1, 1, L"F11"); | 142 BookmarkNode* f11 = model_->AddGroup(f1, 1, L"F11"); |
144 model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a")); | 143 model_->AddURL(f11, 0, L"f11a", GURL(test_base + "f11a")); |
145 if (big_menu) { | 144 if (big_menu) { |
146 for (int i = 1; i <= 100; ++i) { | 145 for (int i = 1; i <= 100; ++i) { |
147 model_->AddURL(f1, i + 1, L"f" + IntToWString(i), | 146 model_->AddURL(f1, i + 1, L"f" + IntToWString(i), |
148 GURL(test_base + "f" + IntToString(i))); | 147 GURL(test_base + "f" + IntToString(i))); |
149 } | 148 } |
150 } | 149 } |
151 model_->AddURL(model_->GetBookmarkBarNode(), 1, L"a", | 150 model_->AddURL(model_->GetBookmarkBarNode(), 1, L"a", |
152 GURL(test_base + "a")); | 151 GURL(test_base + "a")); |
153 model_->AddURL(model_->GetBookmarkBarNode(), 2, L"b", | 152 model_->AddURL(model_->GetBookmarkBarNode(), 2, L"b", |
154 GURL(test_base + "b")); | 153 GURL(test_base + "b")); |
155 model_->AddURL(model_->GetBookmarkBarNode(), 3, L"c", | 154 model_->AddURL(model_->GetBookmarkBarNode(), 3, L"c", |
156 GURL(test_base + "c")); | 155 GURL(test_base + "c")); |
157 model_->AddURL(model_->GetBookmarkBarNode(), 4, L"d", | 156 model_->AddURL(model_->GetBookmarkBarNode(), 4, L"d", |
158 GURL(test_base + "d")); | 157 GURL(test_base + "d")); |
159 model_->AddURL(model_->other_node(), 0, L"oa", GURL(test_base + "oa")); | 158 model_->AddURL(model_->other_node(), 0, L"oa", GURL(test_base + "oa")); |
160 BookmarkBarNode* of = model_->AddGroup(model_->other_node(), 1, L"OF"); | 159 BookmarkNode* of = model_->AddGroup(model_->other_node(), 1, L"OF"); |
161 model_->AddURL(of, 0, L"ofa", GURL(test_base + "ofa")); | 160 model_->AddURL(of, 0, L"ofa", GURL(test_base + "ofa")); |
162 model_->AddURL(of, 1, L"ofb", GURL(test_base + "ofb")); | 161 model_->AddURL(of, 1, L"ofb", GURL(test_base + "ofb")); |
163 BookmarkBarNode* of2 = model_->AddGroup(model_->other_node(), 2, L"OF2"); | 162 BookmarkNode* of2 = model_->AddGroup(model_->other_node(), 2, L"OF2"); |
164 model_->AddURL(of2, 0, L"of2a", GURL(test_base + "of2a")); | 163 model_->AddURL(of2, 0, L"of2a", GURL(test_base + "of2a")); |
165 model_->AddURL(of2, 1, L"of2b", GURL(test_base + "of2b")); | 164 model_->AddURL(of2, 1, L"of2b", GURL(test_base + "of2b")); |
166 } | 165 } |
167 | 166 |
168 gfx::Size bb_view_pref_; | 167 gfx::Size bb_view_pref_; |
169 scoped_ptr<TestingProfile> profile_; | 168 scoped_ptr<TestingProfile> profile_; |
170 }; | 169 }; |
171 | 170 |
172 // Clicks on first menu, makes sure button is depressed. Moves mouse to first | 171 // Clicks on first menu, makes sure button is depressed. Moves mouse to first |
173 // child, clicks it and makes sure a navigation occurs. | 172 // child, clicks it and makes sure a navigation occurs. |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 | 819 |
821 void Step8() { | 820 void Step8() { |
822 ASSERT_TRUE( | 821 ASSERT_TRUE( |
823 model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->GetURL() == | 822 model_->GetBookmarkBarNode()->GetChild(0)->GetChild(0)->GetURL() == |
824 navigator_.url_); | 823 navigator_.url_); |
825 Done(); | 824 Done(); |
826 } | 825 } |
827 }; | 826 }; |
828 | 827 |
829 VIEW_TEST(BookmarkBarViewTest10, KeyEvents) | 828 VIEW_TEST(BookmarkBarViewTest10, KeyEvents) |
OLD | NEW |