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 container_->SizeToPreferredSize(); |
| 38 } |
| 39 |
| 40 private: |
| 41 BrowserActionsContainer* container_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(ContainerParent); |
| 44 }; |
| 45 |
25 // The views-specific implementation of the TestToolbarActionsBarHelper, which | 46 // The views-specific implementation of the TestToolbarActionsBarHelper, which |
26 // creates and owns a BrowserActionsContainer. | 47 // creates and owns a BrowserActionsContainer. |
27 class TestToolbarActionsBarHelperViews : public TestToolbarActionsBarHelper { | 48 class TestToolbarActionsBarHelperViews : public TestToolbarActionsBarHelper { |
28 public: | 49 public: |
29 TestToolbarActionsBarHelperViews(Browser* browser, | 50 TestToolbarActionsBarHelperViews(Browser* browser, |
30 BrowserActionsContainer* main_bar); | 51 BrowserActionsContainer* main_bar); |
31 ~TestToolbarActionsBarHelperViews() override; | 52 ~TestToolbarActionsBarHelperViews() override; |
32 | 53 |
33 BrowserActionsContainer* browser_actions_container() { | 54 BrowserActionsContainer* browser_actions_container() { |
34 return browser_actions_container_; | 55 return browser_actions_container_; |
35 } | 56 } |
36 | 57 |
37 private: | 58 private: |
| 59 // The created BrowserActionsContainer. Owned by |container_parent_|. |
| 60 BrowserActionsContainer* browser_actions_container_; |
| 61 |
38 // The parent of the BrowserActionsContainer, which directly owns the | 62 // The parent of the BrowserActionsContainer, which directly owns the |
39 // container as part of the views hierarchy. | 63 // container as part of the views hierarchy. |
40 views::View container_parent_; | 64 ContainerParent container_parent_; |
41 | |
42 // The created BrowserActionsContainer. Owned by |container_parent_|. | |
43 BrowserActionsContainer* browser_actions_container_; | |
44 | 65 |
45 DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelperViews); | 66 DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelperViews); |
46 }; | 67 }; |
47 | 68 |
48 TestToolbarActionsBarHelperViews::TestToolbarActionsBarHelperViews( | 69 TestToolbarActionsBarHelperViews::TestToolbarActionsBarHelperViews( |
49 Browser* browser, | 70 Browser* browser, |
50 BrowserActionsContainer* main_bar) | 71 BrowserActionsContainer* main_bar) |
51 : browser_actions_container_( | 72 : browser_actions_container_( |
52 new BrowserActionsContainer(browser, main_bar)) { | 73 new BrowserActionsContainer(browser, main_bar)), |
53 // The BrowserActionsContainer expects to have a parent (and be added to the | 74 container_parent_(browser_actions_container_) { |
54 // view hierarchy), so wrap it in a shell view. | |
55 container_parent_.set_owned_by_client(); | 75 container_parent_.set_owned_by_client(); |
56 container_parent_.AddChildView(browser_actions_container_); | 76 container_parent_.SetSize(gfx::Size(1000, 1000)); |
| 77 container_parent_.Layout(); |
57 } | 78 } |
58 | 79 |
59 TestToolbarActionsBarHelperViews::~TestToolbarActionsBarHelperViews() { | 80 TestToolbarActionsBarHelperViews::~TestToolbarActionsBarHelperViews() { |
60 } | 81 } |
61 | 82 |
62 BrowserActionsContainer* GetContainer(Browser* browser, | 83 BrowserActionsContainer* GetContainer(Browser* browser, |
63 TestToolbarActionsBarHelper* helper) { | 84 TestToolbarActionsBarHelper* helper) { |
64 if (helper) { | 85 if (helper) { |
65 return static_cast<TestToolbarActionsBarHelperViews*>(helper) | 86 return static_cast<TestToolbarActionsBarHelperViews*>(helper) |
66 ->browser_actions_container(); | 87 ->browser_actions_container(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 GetToolbarActionsBar()->HideActivePopup(); | 188 GetToolbarActionsBar()->HideActivePopup(); |
168 return !HasPopup(); | 189 return !HasPopup(); |
169 } | 190 } |
170 | 191 |
171 bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) { | 192 bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) { |
172 return GetContainer(browser_, test_helper_.get()) | 193 return GetContainer(browser_, test_helper_.get()) |
173 ->GetToolbarActionViewAt(index) | 194 ->GetToolbarActionViewAt(index) |
174 ->wants_to_run_for_testing(); | 195 ->wants_to_run_for_testing(); |
175 } | 196 } |
176 | 197 |
| 198 void BrowserActionTestUtil::SetWidth(int width) { |
| 199 BrowserActionsContainer* container = |
| 200 GetContainer(browser_, test_helper_.get()); |
| 201 container->SetSize(gfx::Size(width, container->height())); |
| 202 } |
| 203 |
177 ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() { | 204 ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() { |
178 return GetContainer(browser_, test_helper_.get())->toolbar_actions_bar(); | 205 return GetContainer(browser_, test_helper_.get())->toolbar_actions_bar(); |
179 } | 206 } |
180 | 207 |
181 scoped_ptr<BrowserActionTestUtil> BrowserActionTestUtil::CreateOverflowBar() { | 208 scoped_ptr<BrowserActionTestUtil> BrowserActionTestUtil::CreateOverflowBar() { |
182 CHECK(!GetToolbarActionsBar()->in_overflow_mode()) | 209 CHECK(!GetToolbarActionsBar()->in_overflow_mode()) |
183 << "Only a main bar can create an overflow bar!"; | 210 << "Only a main bar can create an overflow bar!"; |
184 return make_scoped_ptr(new BrowserActionTestUtil(browser_, this)); | 211 return make_scoped_ptr(new BrowserActionTestUtil(browser_, this)); |
185 } | 212 } |
186 | 213 |
187 // static | 214 // static |
188 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { | 215 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { |
189 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight); | 216 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight); |
190 } | 217 } |
191 | 218 |
192 // static | 219 // static |
193 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { | 220 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { |
194 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight); | 221 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight); |
195 } | 222 } |
196 | 223 |
197 BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser, | 224 BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser, |
198 BrowserActionTestUtil* main_bar) | 225 BrowserActionTestUtil* main_bar) |
199 : browser_(browser), | 226 : browser_(browser), |
200 test_helper_(new TestToolbarActionsBarHelperViews( | 227 test_helper_(new TestToolbarActionsBarHelperViews( |
201 browser_, | 228 browser_, |
202 GetContainer(browser_, main_bar->test_helper_.get()))) { | 229 GetContainer(browser_, main_bar->test_helper_.get()))) { |
203 } | 230 } |
OLD | NEW |