| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/browser_action_test_util.h" | 5 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 10 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 11 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 11 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 12 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 13 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 13 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 14 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | 14 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
| 15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 16 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" | 16 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" |
| 17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/size.h" | 19 #include "ui/gfx/geometry/size.h" |
| 20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // The BrowserActionsContainer expects to have a parent (and be added to the |
| 26 // view hierarchy), so wrap it in a shell view that will set the container's |
| 27 // bounds to be its preferred bounds. |
| 28 class ContainerParent : public views::View { |
| 29 public: |
| 30 explicit ContainerParent(BrowserActionsContainer* container) |
| 31 : container_(container) { |
| 32 AddChildView(container_); |
| 33 } |
| 34 ~ContainerParent() override {} |
| 35 |
| 36 void Layout() override { |
| 37 gfx::Size s = container_->GetPreferredSize(); |
| 38 container_->SetBounds(0, 0, s.width(), s.height()); |
| 39 } |
| 40 |
| 41 private: |
| 42 BrowserActionsContainer* container_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(ContainerParent); |
| 45 }; |
| 46 |
| 25 // The views-specific implementation of the TestToolbarActionsBarHelper, which | 47 // The views-specific implementation of the TestToolbarActionsBarHelper, which |
| 26 // creates and owns a BrowserActionsContainer. | 48 // creates and owns a BrowserActionsContainer. |
| 27 class TestToolbarActionsBarHelperViews : public TestToolbarActionsBarHelper { | 49 class TestToolbarActionsBarHelperViews : public TestToolbarActionsBarHelper { |
| 28 public: | 50 public: |
| 29 TestToolbarActionsBarHelperViews(Browser* browser, | 51 TestToolbarActionsBarHelperViews(Browser* browser, |
| 30 BrowserActionsContainer* main_bar); | 52 BrowserActionsContainer* main_bar); |
| 31 ~TestToolbarActionsBarHelperViews() override; | 53 ~TestToolbarActionsBarHelperViews() override; |
| 32 | 54 |
| 33 BrowserActionsContainer* browser_actions_container() { | 55 BrowserActionsContainer* browser_actions_container() { |
| 34 return browser_actions_container_; | 56 return browser_actions_container_; |
| 35 } | 57 } |
| 36 | 58 |
| 37 private: | 59 private: |
| 60 // The created BrowserActionsContainer. Owned by |container_parent_|. |
| 61 BrowserActionsContainer* browser_actions_container_; |
| 62 |
| 38 // The parent of the BrowserActionsContainer, which directly owns the | 63 // The parent of the BrowserActionsContainer, which directly owns the |
| 39 // container as part of the views hierarchy. | 64 // container as part of the views hierarchy. |
| 40 views::View container_parent_; | 65 ContainerParent container_parent_; |
| 41 | |
| 42 // The created BrowserActionsContainer. Owned by |container_parent_|. | |
| 43 BrowserActionsContainer* browser_actions_container_; | |
| 44 | 66 |
| 45 DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelperViews); | 67 DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelperViews); |
| 46 }; | 68 }; |
| 47 | 69 |
| 48 TestToolbarActionsBarHelperViews::TestToolbarActionsBarHelperViews( | 70 TestToolbarActionsBarHelperViews::TestToolbarActionsBarHelperViews( |
| 49 Browser* browser, | 71 Browser* browser, |
| 50 BrowserActionsContainer* main_bar) | 72 BrowserActionsContainer* main_bar) |
| 51 : browser_actions_container_( | 73 : browser_actions_container_( |
| 52 new BrowserActionsContainer(browser, main_bar)) { | 74 new BrowserActionsContainer(browser, main_bar)), |
| 53 // The BrowserActionsContainer expects to have a parent (and be added to the | 75 container_parent_(browser_actions_container_) { |
| 54 // view hierarchy), so wrap it in a shell view. | |
| 55 container_parent_.set_owned_by_client(); | 76 container_parent_.set_owned_by_client(); |
| 56 container_parent_.AddChildView(browser_actions_container_); | 77 // Give the container plenty of room to play. |
| 78 container_parent_.SetSize(gfx::Size(1000, 1000)); |
| 79 container_parent_.Layout(); |
| 57 } | 80 } |
| 58 | 81 |
| 59 TestToolbarActionsBarHelperViews::~TestToolbarActionsBarHelperViews() { | 82 TestToolbarActionsBarHelperViews::~TestToolbarActionsBarHelperViews() { |
| 60 } | 83 } |
| 61 | 84 |
| 62 BrowserActionsContainer* GetContainer(Browser* browser, | 85 BrowserActionsContainer* GetContainer(Browser* browser, |
| 63 TestToolbarActionsBarHelper* helper) { | 86 TestToolbarActionsBarHelper* helper) { |
| 64 if (helper) { | 87 if (helper) { |
| 65 return static_cast<TestToolbarActionsBarHelperViews*>(helper) | 88 return static_cast<TestToolbarActionsBarHelperViews*>(helper) |
| 66 ->browser_actions_container(); | 89 ->browser_actions_container(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 GetToolbarActionsBar()->HideActivePopup(); | 190 GetToolbarActionsBar()->HideActivePopup(); |
| 168 return !HasPopup(); | 191 return !HasPopup(); |
| 169 } | 192 } |
| 170 | 193 |
| 171 bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) { | 194 bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) { |
| 172 return GetContainer(browser_, test_helper_.get()) | 195 return GetContainer(browser_, test_helper_.get()) |
| 173 ->GetToolbarActionViewAt(index) | 196 ->GetToolbarActionViewAt(index) |
| 174 ->wants_to_run_for_testing(); | 197 ->wants_to_run_for_testing(); |
| 175 } | 198 } |
| 176 | 199 |
| 200 void BrowserActionTestUtil::SetWidth(int width) { |
| 201 BrowserActionsContainer* container = |
| 202 GetContainer(browser_, test_helper_.get()); |
| 203 container->SetSize(gfx::Size(width, container->size().height())); |
| 204 } |
| 205 |
| 177 ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() { | 206 ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() { |
| 178 return GetContainer(browser_, test_helper_.get())->toolbar_actions_bar(); | 207 return GetContainer(browser_, test_helper_.get())->toolbar_actions_bar(); |
| 179 } | 208 } |
| 180 | 209 |
| 181 scoped_ptr<BrowserActionTestUtil> BrowserActionTestUtil::CreateOverflowBar() { | 210 scoped_ptr<BrowserActionTestUtil> BrowserActionTestUtil::CreateOverflowBar() { |
| 182 CHECK(!GetToolbarActionsBar()->in_overflow_mode()) | 211 CHECK(!GetToolbarActionsBar()->in_overflow_mode()) |
| 183 << "Only a main bar can create an overflow bar!"; | 212 << "Only a main bar can create an overflow bar!"; |
| 184 return make_scoped_ptr(new BrowserActionTestUtil(browser_, this)); | 213 return make_scoped_ptr(new BrowserActionTestUtil(browser_, this)); |
| 185 } | 214 } |
| 186 | 215 |
| 187 // static | 216 // static |
| 188 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { | 217 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { |
| 189 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight); | 218 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight); |
| 190 } | 219 } |
| 191 | 220 |
| 192 // static | 221 // static |
| 193 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { | 222 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { |
| 194 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight); | 223 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight); |
| 195 } | 224 } |
| 196 | 225 |
| 197 BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser, | 226 BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser, |
| 198 BrowserActionTestUtil* main_bar) | 227 BrowserActionTestUtil* main_bar) |
| 199 : browser_(browser), | 228 : browser_(browser), |
| 200 test_helper_(new TestToolbarActionsBarHelperViews( | 229 test_helper_(new TestToolbarActionsBarHelperViews( |
| 201 browser_, | 230 browser_, |
| 202 GetContainer(browser_, main_bar->test_helper_.get()))) { | 231 GetContainer(browser_, main_bar->test_helper_.get()))) { |
| 203 } | 232 } |
| OLD | NEW |