OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/toolbar/toolbar_actions_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 12 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
13 #include "chrome/browser/extensions/browser_action_test_util.h" | 13 #include "chrome/browser/extensions/browser_action_test_util.h" |
14 #include "chrome/browser/extensions/extension_action.h" | 14 #include "chrome/browser/extensions/extension_action.h" |
15 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
16 #include "chrome/browser/extensions/extension_action_test_util.h" | 16 #include "chrome/browser/extensions/extension_action_test_util.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/test_extension_system.h" | 18 #include "chrome/browser/extensions/test_extension_system.h" |
19 #include "chrome/browser/sessions/session_tab_helper.h" | 19 #include "chrome/browser/sessions/session_tab_helper.h" |
20 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d
elegate.h" | 20 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d
elegate.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_helper.h" | |
23 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 22 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
24 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 23 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
25 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
26 #include "chrome/test/base/browser_with_test_window_test.h" | 25 #include "chrome/test/base/browser_with_test_window_test.h" |
27 #include "extensions/browser/extension_prefs.h" | 26 #include "extensions/browser/extension_prefs.h" |
28 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
29 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
30 #include "extensions/common/feature_switch.h" | 29 #include "extensions/common/feature_switch.h" |
31 | 30 |
32 namespace { | 31 namespace { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // in a debug message. These aren't enforced to be unique, so don't make | 130 // in a debug message. These aren't enforced to be unique, so don't make |
132 // duplicates. | 131 // duplicates. |
133 // If any of these is wrong, returns testing::AssertionFailure() with a | 132 // If any of these is wrong, returns testing::AssertionFailure() with a |
134 // message. | 133 // message. |
135 testing::AssertionResult VerifyToolbarOrder( | 134 testing::AssertionResult VerifyToolbarOrder( |
136 const char* expected_names[], | 135 const char* expected_names[], |
137 size_t total_size, | 136 size_t total_size, |
138 size_t visible_count) WARN_UNUSED_RESULT; | 137 size_t visible_count) WARN_UNUSED_RESULT; |
139 | 138 |
140 ToolbarActionsBar* toolbar_actions_bar() { | 139 ToolbarActionsBar* toolbar_actions_bar() { |
141 return main_bar_helper_->GetToolbarActionsBar(); | 140 return browser_action_test_util_->GetToolbarActionsBar(); |
142 } | 141 } |
143 ToolbarActionsBar* overflow_bar() { | 142 ToolbarActionsBar* overflow_bar() { |
144 return overflow_bar_helper_->GetToolbarActionsBar(); | 143 return overflow_browser_action_test_util_->GetToolbarActionsBar(); |
145 } | 144 } |
146 extensions::ExtensionToolbarModel* toolbar_model() { | 145 extensions::ExtensionToolbarModel* toolbar_model() { |
147 return toolbar_model_; | 146 return toolbar_model_; |
148 } | 147 } |
149 BrowserActionTestUtil* browser_action_test_util() { | 148 BrowserActionTestUtil* browser_action_test_util() { |
150 return browser_action_test_util_.get(); | 149 return browser_action_test_util_.get(); |
151 } | 150 } |
152 BrowserActionTestUtil* overflow_browser_action_test_util() { | 151 BrowserActionTestUtil* overflow_browser_action_test_util() { |
153 return overflow_browser_action_test_util_.get(); | 152 return overflow_browser_action_test_util_.get(); |
154 } | 153 } |
155 | 154 |
156 private: | 155 private: |
157 // The test helper that owns the ToolbarActionsBar and the platform-specific | |
158 // view for it. | |
159 scoped_ptr<TestToolbarActionsBarHelper> main_bar_helper_; | |
160 | |
161 // The test helper for the overflow bar; only non-null if |use_redesign| is | |
162 // true. | |
163 scoped_ptr<TestToolbarActionsBarHelper> overflow_bar_helper_; | |
164 | |
165 // The associated ExtensionToolbarModel (owned by the keyed service setup). | 156 // The associated ExtensionToolbarModel (owned by the keyed service setup). |
166 extensions::ExtensionToolbarModel* toolbar_model_; | 157 extensions::ExtensionToolbarModel* toolbar_model_; |
167 | 158 |
168 // A BrowserActionTestUtil object constructed with the associated | 159 // A BrowserActionTestUtil object constructed with the associated |
169 // ToolbarActionsBar. | 160 // ToolbarActionsBar. |
170 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; | 161 scoped_ptr<BrowserActionTestUtil> browser_action_test_util_; |
171 | 162 |
172 // The overflow container's BrowserActionTestUtil (only non-null if | 163 // The overflow container's BrowserActionTestUtil (only non-null if |
173 // |use_redesign| is true). | 164 // |use_redesign| is true). |
174 scoped_ptr<BrowserActionTestUtil> overflow_browser_action_test_util_; | 165 scoped_ptr<BrowserActionTestUtil> overflow_browser_action_test_util_; |
(...skipping 19 matching lines...) Expand all Loading... |
194 static_cast<extensions::TestExtensionSystem*>( | 185 static_cast<extensions::TestExtensionSystem*>( |
195 extensions::ExtensionSystem::Get(profile())); | 186 extensions::ExtensionSystem::Get(profile())); |
196 extension_system->CreateExtensionService( | 187 extension_system->CreateExtensionService( |
197 base::CommandLine::ForCurrentProcess(), | 188 base::CommandLine::ForCurrentProcess(), |
198 base::FilePath(), | 189 base::FilePath(), |
199 false); | 190 false); |
200 toolbar_model_ = | 191 toolbar_model_ = |
201 extensions::extension_action_test_util::CreateToolbarModelForProfile( | 192 extensions::extension_action_test_util::CreateToolbarModelForProfile( |
202 profile()); | 193 profile()); |
203 | 194 |
204 main_bar_helper_ = TestToolbarActionsBarHelper::Create(browser(), nullptr); | |
205 | |
206 ToolbarActionsBar::disable_animations_for_testing_ = true; | 195 ToolbarActionsBar::disable_animations_for_testing_ = true; |
207 ToolbarActionsBar::set_send_overflowed_action_changes_for_testing(false); | 196 ToolbarActionsBar::set_send_overflowed_action_changes_for_testing(false); |
208 browser_action_test_util_.reset( | 197 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), false)); |
209 new BrowserActionTestUtil(browser(), | |
210 toolbar_actions_bar()->delegate_for_test())); | |
211 | 198 |
212 if (use_redesign_) { | 199 if (use_redesign_) { |
213 overflow_bar_helper_ = | 200 overflow_browser_action_test_util_ = |
214 TestToolbarActionsBarHelper::Create(browser(), main_bar_helper_.get()); | 201 browser_action_test_util_->CreateOverflowBar(); |
215 overflow_browser_action_test_util_.reset( | |
216 new BrowserActionTestUtil(browser(), | |
217 overflow_bar()->delegate_for_test())); | |
218 } | 202 } |
219 } | 203 } |
220 | 204 |
221 void ToolbarActionsBarUnitTest::TearDown() { | 205 void ToolbarActionsBarUnitTest::TearDown() { |
222 // Since the profile gets destroyed in BrowserWithTestWindowTest::TearDown(), | 206 // Since the profile gets destroyed in BrowserWithTestWindowTest::TearDown(), |
223 // we need to delete this now. | 207 // we need to delete this now. |
224 overflow_bar_helper_.reset(); | 208 browser_action_test_util_.reset(); |
225 main_bar_helper_.reset(); | 209 overflow_browser_action_test_util_.reset(); |
226 ToolbarActionsBar::disable_animations_for_testing_ = false; | 210 ToolbarActionsBar::disable_animations_for_testing_ = false; |
227 redesign_switch_.reset(); | 211 redesign_switch_.reset(); |
228 BrowserWithTestWindowTest::TearDown(); | 212 BrowserWithTestWindowTest::TearDown(); |
229 } | 213 } |
230 | 214 |
231 void ToolbarActionsBarUnitTest::ActivateTab(int index) { | 215 void ToolbarActionsBarUnitTest::ActivateTab(int index) { |
232 ASSERT_NE(nullptr, browser()->tab_strip_model()->GetWebContentsAt(index)); | 216 ASSERT_NE(nullptr, browser()->tab_strip_model()->GetWebContentsAt(index)); |
233 browser()->tab_strip_model()->ActivateTabAt(index, true); | 217 browser()->tab_strip_model()->ActivateTabAt(index, true); |
234 } | 218 } |
235 | 219 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); | 457 ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); |
474 EXPECT_FALSE( | 458 EXPECT_FALSE( |
475 ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( | 459 ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( |
476 profile())); | 460 profile())); |
477 base::Time one_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7); | 461 base::Time one_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7); |
478 prefs->SetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime, | 462 prefs->SetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime, |
479 one_week_ago.ToInternalValue()); | 463 one_week_ago.ToInternalValue()); |
480 EXPECT_TRUE( | 464 EXPECT_TRUE( |
481 prefs->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged)); | 465 prefs->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged)); |
482 } | 466 } |
OLD | NEW |