Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc |
| diff --git a/chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc b/chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc |
| index 2540c7c50225dc47042e21fd2687311196558f6f..1d7fb076f226b6a5668bfebb5e4c3a104a4c9171 100644 |
| --- a/chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc |
| +++ b/chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc |
| @@ -22,6 +22,27 @@ |
| namespace { |
| +// The BrowserActionsContainer expects to have a parent (and be added to the |
| +// view hierarchy), so wrap it in a shell view that will set the container's |
| +// bounds to be its preferred bounds. |
| +class ContainerParent : public views::View { |
| + public: |
| + explicit ContainerParent(BrowserActionsContainer* container) |
| + : container_(container) { |
| + AddChildView(container_); |
| + } |
| + ~ContainerParent() override {} |
| + |
| + void Layout() override { |
| + container_->SizeToPreferredSize(); |
| + } |
| + |
| + private: |
| + BrowserActionsContainer* container_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ContainerParent); |
| +}; |
| + |
| // The views-specific implementation of the TestToolbarActionsBarHelper, which |
| // creates and owns a BrowserActionsContainer. |
| class TestToolbarActionsBarHelperViews : public TestToolbarActionsBarHelper { |
| @@ -35,13 +56,13 @@ class TestToolbarActionsBarHelperViews : public TestToolbarActionsBarHelper { |
| } |
| private: |
| - // The parent of the BrowserActionsContainer, which directly owns the |
| - // container as part of the views hierarchy. |
| - views::View container_parent_; |
| - |
| // The created BrowserActionsContainer. Owned by |container_parent_|. |
| BrowserActionsContainer* browser_actions_container_; |
| + // The parent of the BrowserActionsContainer, which directly owns the |
| + // container as part of the views hierarchy. |
| + ContainerParent container_parent_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelperViews); |
| }; |
| @@ -49,11 +70,12 @@ TestToolbarActionsBarHelperViews::TestToolbarActionsBarHelperViews( |
| Browser* browser, |
| BrowserActionsContainer* main_bar) |
| : browser_actions_container_( |
| - new BrowserActionsContainer(browser, main_bar)) { |
| - // The BrowserActionsContainer expects to have a parent (and be added to the |
| - // view hierarchy), so wrap it in a shell view. |
| + new BrowserActionsContainer(browser, main_bar)), |
| + container_parent_(browser_actions_container_) { |
| container_parent_.set_owned_by_client(); |
| - container_parent_.AddChildView(browser_actions_container_); |
| + // Give the container plenty of room to play. |
|
Peter Kasting
2015/09/17 00:18:04
Nit: Prefer a comment that's a bit more specific a
Devlin
2015/09/17 17:00:27
Dropped.
|
| + container_parent_.SetSize(gfx::Size(1000, 1000)); |
| + container_parent_.Layout(); |
| } |
| TestToolbarActionsBarHelperViews::~TestToolbarActionsBarHelperViews() { |
| @@ -174,6 +196,12 @@ bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) { |
| ->wants_to_run_for_testing(); |
| } |
| +void BrowserActionTestUtil::SetWidth(int width) { |
| + BrowserActionsContainer* container = |
| + GetContainer(browser_, test_helper_.get()); |
| + container->SetSize(gfx::Size(width, container->height())); |
| +} |
| + |
| ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() { |
| return GetContainer(browser_, test_helper_.get())->toolbar_actions_bar(); |
| } |