| 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_unittest.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 11 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 12 #include "chrome/browser/extensions/extension_action.h" | 12 #include "chrome/browser/extensions/extension_action.h" |
| 13 #include "chrome/browser/extensions/extension_action_manager.h" | 13 #include "chrome/browser/extensions/extension_action_manager.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/test_extension_system.h" | 15 #include "chrome/browser/extensions/test_extension_system.h" |
| 16 #include "chrome/browser/sessions/session_tab_helper.h" | 16 #include "chrome/browser/sessions/session_tab_helper.h" |
| 17 #include "chrome/browser/ui/layout_constants.h" | 17 #include "chrome/browser/ui/layout_constants.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 19 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 20 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 20 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 21 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 21 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/test/base/scoped_testing_local_state.h" | 23 #include "chrome/test/base/scoped_testing_local_state.h" |
| 24 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
| 26 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 27 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 28 #include "extensions/common/feature_switch.h" | |
| 29 #include "ui/base/test/material_design_controller_test_api.h" | 28 #include "ui/base/test/material_design_controller_test_api.h" |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 // Verifies that the toolbar order matches for the given |actions_bar|. If the | 32 // Verifies that the toolbar order matches for the given |actions_bar|. If the |
| 34 // order matches, the return value is empty; otherwise, it contains the error. | 33 // order matches, the return value is empty; otherwise, it contains the error. |
| 35 std::string VerifyToolbarOrderForBar( | 34 std::string VerifyToolbarOrderForBar( |
| 36 const ToolbarActionsBar* actions_bar, | 35 const ToolbarActionsBar* actions_bar, |
| 37 BrowserActionTestUtil* browser_action_test_util, | 36 BrowserActionTestUtil* browser_action_test_util, |
| 38 const char* expected_names[], | 37 const char* expected_names[], |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 false); | 107 false); |
| 109 toolbar_model_ = | 108 toolbar_model_ = |
| 110 extensions::extension_action_test_util::CreateToolbarModelForProfile( | 109 extensions::extension_action_test_util::CreateToolbarModelForProfile( |
| 111 profile()); | 110 profile()); |
| 112 | 111 |
| 113 material_design_state_.reset( | 112 material_design_state_.reset( |
| 114 new ui::test::MaterialDesignControllerTestAPI(GetParam())); | 113 new ui::test::MaterialDesignControllerTestAPI(GetParam())); |
| 115 ToolbarActionsBar::disable_animations_for_testing_ = true; | 114 ToolbarActionsBar::disable_animations_for_testing_ = true; |
| 116 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), false)); | 115 browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), false)); |
| 117 | 116 |
| 118 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { | 117 overflow_browser_action_test_util_ = |
| 119 overflow_browser_action_test_util_ = | 118 browser_action_test_util_->CreateOverflowBar(); |
| 120 browser_action_test_util_->CreateOverflowBar(); | |
| 121 } | |
| 122 } | 119 } |
| 123 | 120 |
| 124 void ToolbarActionsBarUnitTest::TearDown() { | 121 void ToolbarActionsBarUnitTest::TearDown() { |
| 125 // Since the profile gets destroyed in BrowserWithTestWindowTest::TearDown(), | 122 // Since the profile gets destroyed in BrowserWithTestWindowTest::TearDown(), |
| 126 // we need to delete this now. | 123 // we need to delete this now. |
| 127 browser_action_test_util_.reset(); | 124 browser_action_test_util_.reset(); |
| 128 overflow_browser_action_test_util_.reset(); | 125 overflow_browser_action_test_util_.reset(); |
| 129 ToolbarActionsBar::disable_animations_for_testing_ = false; | 126 ToolbarActionsBar::disable_animations_for_testing_ = false; |
| 130 material_design_state_.reset(); | 127 material_design_state_.reset(); |
| 131 local_state_.reset(); | 128 local_state_.reset(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 162 const char* expected_names[], | 159 const char* expected_names[], |
| 163 size_t total_size, | 160 size_t total_size, |
| 164 size_t visible_count) { | 161 size_t visible_count) { |
| 165 std::string main_bar_error = | 162 std::string main_bar_error = |
| 166 VerifyToolbarOrderForBar(toolbar_actions_bar(), | 163 VerifyToolbarOrderForBar(toolbar_actions_bar(), |
| 167 browser_action_test_util(), | 164 browser_action_test_util(), |
| 168 expected_names, | 165 expected_names, |
| 169 total_size, | 166 total_size, |
| 170 visible_count); | 167 visible_count); |
| 171 std::string overflow_bar_error; | 168 std::string overflow_bar_error; |
| 172 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { | 169 overflow_bar_error = VerifyToolbarOrderForBar( |
| 173 overflow_bar_error = | 170 overflow_bar(), overflow_browser_action_test_util(), expected_names, |
| 174 VerifyToolbarOrderForBar(overflow_bar(), | 171 total_size, total_size - visible_count); |
| 175 overflow_browser_action_test_util(), | |
| 176 expected_names, | |
| 177 total_size, | |
| 178 total_size - visible_count); | |
| 179 | |
| 180 } | |
| 181 | 172 |
| 182 return main_bar_error.empty() && overflow_bar_error.empty() ? | 173 return main_bar_error.empty() && overflow_bar_error.empty() ? |
| 183 testing::AssertionSuccess() : | 174 testing::AssertionSuccess() : |
| 184 testing::AssertionFailure() << "main bar error:\n" << main_bar_error << | 175 testing::AssertionFailure() << "main bar error:\n" << main_bar_error << |
| 185 "overflow bar error:\n" << overflow_bar_error; | 176 "overflow bar error:\n" << overflow_bar_error; |
| 186 } | 177 } |
| 187 | 178 |
| 188 // Note: First argument is optional and intentionally left blank. | 179 // Note: First argument is optional and intentionally left blank. |
| 189 // (it's a prefix for the generated test cases) | 180 // (it's a prefix for the generated test cases) |
| 190 INSTANTIATE_TEST_CASE_P( | 181 INSTANTIATE_TEST_CASE_P( |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 extensions::extension_action_test_util::BROWSER_ACTION); | 565 extensions::extension_action_test_util::BROWSER_ACTION); |
| 575 toolbar_model()->SetVisibleIconCount(0u); | 566 toolbar_model()->SetVisibleIconCount(0u); |
| 576 { | 567 { |
| 577 base::RunLoop run_loop; | 568 base::RunLoop run_loop; |
| 578 toolbar_actions_bar()->PopOutAction(action, true, run_loop.QuitClosure()); | 569 toolbar_actions_bar()->PopOutAction(action, true, run_loop.QuitClosure()); |
| 579 run_loop.Run(); | 570 run_loop.Run(); |
| 580 } | 571 } |
| 581 EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); | 572 EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| 582 EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); | 573 EXPECT_TRUE(toolbar_actions_bar()->NeedsOverflow()); |
| 583 } | 574 } |
| OLD | NEW |