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 // 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.
| |
77 container_parent_.SetSize(gfx::Size(1000, 1000)); | |
78 container_parent_.Layout(); | |
57 } | 79 } |
58 | 80 |
59 TestToolbarActionsBarHelperViews::~TestToolbarActionsBarHelperViews() { | 81 TestToolbarActionsBarHelperViews::~TestToolbarActionsBarHelperViews() { |
60 } | 82 } |
61 | 83 |
62 BrowserActionsContainer* GetContainer(Browser* browser, | 84 BrowserActionsContainer* GetContainer(Browser* browser, |
63 TestToolbarActionsBarHelper* helper) { | 85 TestToolbarActionsBarHelper* helper) { |
64 if (helper) { | 86 if (helper) { |
65 return static_cast<TestToolbarActionsBarHelperViews*>(helper) | 87 return static_cast<TestToolbarActionsBarHelperViews*>(helper) |
66 ->browser_actions_container(); | 88 ->browser_actions_container(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 GetToolbarActionsBar()->HideActivePopup(); | 189 GetToolbarActionsBar()->HideActivePopup(); |
168 return !HasPopup(); | 190 return !HasPopup(); |
169 } | 191 } |
170 | 192 |
171 bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) { | 193 bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) { |
172 return GetContainer(browser_, test_helper_.get()) | 194 return GetContainer(browser_, test_helper_.get()) |
173 ->GetToolbarActionViewAt(index) | 195 ->GetToolbarActionViewAt(index) |
174 ->wants_to_run_for_testing(); | 196 ->wants_to_run_for_testing(); |
175 } | 197 } |
176 | 198 |
199 void BrowserActionTestUtil::SetWidth(int width) { | |
200 BrowserActionsContainer* container = | |
201 GetContainer(browser_, test_helper_.get()); | |
202 container->SetSize(gfx::Size(width, container->height())); | |
203 } | |
204 | |
177 ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() { | 205 ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() { |
178 return GetContainer(browser_, test_helper_.get())->toolbar_actions_bar(); | 206 return GetContainer(browser_, test_helper_.get())->toolbar_actions_bar(); |
179 } | 207 } |
180 | 208 |
181 scoped_ptr<BrowserActionTestUtil> BrowserActionTestUtil::CreateOverflowBar() { | 209 scoped_ptr<BrowserActionTestUtil> BrowserActionTestUtil::CreateOverflowBar() { |
182 CHECK(!GetToolbarActionsBar()->in_overflow_mode()) | 210 CHECK(!GetToolbarActionsBar()->in_overflow_mode()) |
183 << "Only a main bar can create an overflow bar!"; | 211 << "Only a main bar can create an overflow bar!"; |
184 return make_scoped_ptr(new BrowserActionTestUtil(browser_, this)); | 212 return make_scoped_ptr(new BrowserActionTestUtil(browser_, this)); |
185 } | 213 } |
186 | 214 |
187 // static | 215 // static |
188 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { | 216 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { |
189 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight); | 217 return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight); |
190 } | 218 } |
191 | 219 |
192 // static | 220 // static |
193 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { | 221 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { |
194 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight); | 222 return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight); |
195 } | 223 } |
196 | 224 |
197 BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser, | 225 BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser, |
198 BrowserActionTestUtil* main_bar) | 226 BrowserActionTestUtil* main_bar) |
199 : browser_(browser), | 227 : browser_(browser), |
200 test_helper_(new TestToolbarActionsBarHelperViews( | 228 test_helper_(new TestToolbarActionsBarHelperViews( |
201 browser_, | 229 browser_, |
202 GetContainer(browser_, main_bar->test_helper_.get()))) { | 230 GetContainer(browser_, main_bar->test_helper_.get()))) { |
203 } | 231 } |
OLD | NEW |