1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_UNITTEST_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_UNITTEST_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/extensions/browser_action_test_util.h"
11 #include "chrome/browser/extensions/extension_action_test_util.h"
12 #include "chrome/test/base/browser_with_test_window_test.h"
13 #include "extensions/common/feature_switch.h"
15 class ExtensionAction
;
16 class ToolbarActionsBar
;
22 namespace extensions
{
26 // A cross-platform unit test for the ToolbarActionsBar that uses the
27 // TestToolbarActionsBarHelper to create the platform-specific containers.
28 // TODO(devlin): Since this *does* use the real platform containers, in theory,
29 // we can move all the BrowserActionsBarBrowserTests to be unittests. See about
31 class ToolbarActionsBarUnitTest
: public BrowserWithTestWindowTest
{
33 ToolbarActionsBarUnitTest();
34 ~ToolbarActionsBarUnitTest() override
;
37 // A constructor to allow subclasses to override the redesign value.
38 explicit ToolbarActionsBarUnitTest(bool use_redesign
);
40 void SetUp() override
;
41 void TearDown() override
;
43 // Activates the tab at the given |index| in the tab strip model.
44 void ActivateTab(int index
);
46 // Set whether or not the given |action| wants to run on the |web_contents|.
47 void SetActionWantsToRunOnTab(ExtensionAction
* action
,
48 content::WebContents
* web_contents
,
51 // Creates an extension with the given |name| and |action_type|, adds it to
52 // the associated extension service, and returns the created extension. (It's
53 // safe to ignore the returned value.)
54 scoped_refptr
<const extensions::Extension
> CreateAndAddExtension(
55 const std::string
& name
,
56 extensions::extension_action_test_util::ActionType action_type
);
58 // Verifies that the toolbar is in order specified by |expected_names|, has
59 // the total action count of |total_size|, and has the same |visible_count|.
60 // This verifies that both the ToolbarActionsBar and the associated
61 // (platform-specific) view is correct.
62 // We use expected names (instead of ids) because they're much more readable
63 // in a debug message. These aren't enforced to be unique, so don't make
65 // If any of these is wrong, returns testing::AssertionFailure() with a
67 testing::AssertionResult
VerifyToolbarOrder(
68 const char* expected_names
[],
70 size_t visible_count
) WARN_UNUSED_RESULT
;
72 ToolbarActionsBar
* toolbar_actions_bar() {
73 return browser_action_test_util_
->GetToolbarActionsBar();
75 ToolbarActionsBar
* overflow_bar() {
76 return overflow_browser_action_test_util_
->GetToolbarActionsBar();
78 ToolbarActionsModel
* toolbar_model() { return toolbar_model_
; }
79 BrowserActionTestUtil
* browser_action_test_util() {
80 return browser_action_test_util_
.get();
82 BrowserActionTestUtil
* overflow_browser_action_test_util() {
83 return overflow_browser_action_test_util_
.get();
87 // The associated ToolbarActionsModel (owned by the keyed service setup).
88 ToolbarActionsModel
* toolbar_model_
;
90 // A BrowserActionTestUtil object constructed with the associated
92 scoped_ptr
<BrowserActionTestUtil
> browser_action_test_util_
;
94 // The overflow container's BrowserActionTestUtil (only non-null if
95 // |use_redesign| is true).
96 scoped_ptr
<BrowserActionTestUtil
> overflow_browser_action_test_util_
;
98 // True if the extension action redesign switch should be enabled.
101 scoped_ptr
<extensions::FeatureSwitch::ScopedOverride
> redesign_switch_
;
103 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarUnitTest
);
106 class ToolbarActionsBarRedesignUnitTest
: public ToolbarActionsBarUnitTest
{
108 ToolbarActionsBarRedesignUnitTest();
109 ~ToolbarActionsBarRedesignUnitTest() override
;
112 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarRedesignUnitTest
);
115 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_BAR_UNITTEST_H_