| 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 8b3b3e8a09167c3910c65f1e962f4e55e1732fc9..48edbf0d7d1fcc8cdfb2bb7383221fa9c52d6fd4 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,26 +22,80 @@
|
|
|
| namespace {
|
|
|
| +// The views-specific implementation of the TestToolbarActionsBarHelper, which
|
| +// creates and owns a BrowserActionsContainer.
|
| +class TestToolbarActionsBarHelperViews : public TestToolbarActionsBarHelper {
|
| + public:
|
| + TestToolbarActionsBarHelperViews(Browser* browser,
|
| + BrowserActionsContainer* main_bar);
|
| + ~TestToolbarActionsBarHelperViews() override;
|
| +
|
| + BrowserActionsContainer* browser_actions_container() {
|
| + return browser_actions_container_;
|
| + }
|
| +
|
| + 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_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelperViews);
|
| +};
|
| +
|
| +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.
|
| + container_parent_.set_owned_by_client();
|
| + container_parent_.AddChildView(browser_actions_container_);
|
| +}
|
| +
|
| +TestToolbarActionsBarHelperViews::~TestToolbarActionsBarHelperViews() {
|
| +}
|
| +
|
| BrowserActionsContainer* GetContainer(Browser* browser,
|
| - ToolbarActionsBarDelegate* bar_delegate) {
|
| - if (bar_delegate)
|
| - return static_cast<BrowserActionsContainer*>(bar_delegate);
|
| + TestToolbarActionsBarHelper* helper) {
|
| + if (helper) {
|
| + return static_cast<TestToolbarActionsBarHelperViews*>(helper)
|
| + ->browser_actions_container();
|
| + }
|
| return BrowserView::GetBrowserViewForBrowser(browser)->toolbar()->
|
| browser_actions();
|
| }
|
|
|
| } // namespace
|
|
|
| +BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser)
|
| + : BrowserActionTestUtil(browser, true) {
|
| +}
|
| +
|
| +BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser,
|
| + bool is_real_window)
|
| + : browser_(browser) {
|
| + if (!is_real_window)
|
| + test_helper_.reset(new TestToolbarActionsBarHelperViews(browser, nullptr));
|
| +}
|
| +
|
| +BrowserActionTestUtil::~BrowserActionTestUtil() {
|
| +}
|
| +
|
| int BrowserActionTestUtil::NumberOfBrowserActions() {
|
| - return GetContainer(browser_, bar_delegate_)->num_toolbar_actions();
|
| + return GetContainer(browser_, test_helper_.get())->num_toolbar_actions();
|
| }
|
|
|
| int BrowserActionTestUtil::VisibleBrowserActions() {
|
| - return GetContainer(browser_, bar_delegate_)->VisibleBrowserActions();
|
| + return GetContainer(browser_, test_helper_.get())->VisibleBrowserActions();
|
| }
|
|
|
| bool BrowserActionTestUtil::IsChevronShowing() {
|
| - BrowserActionsContainer* container = GetContainer(browser_, bar_delegate_);
|
| + BrowserActionsContainer* container =
|
| + GetContainer(browser_, test_helper_.get());
|
| gfx::Size visible_size = container->GetVisibleBounds().size();
|
| return container->chevron() &&
|
| container->chevron()->visible() &&
|
| @@ -52,37 +106,44 @@ bool BrowserActionTestUtil::IsChevronShowing() {
|
|
|
| void BrowserActionTestUtil::InspectPopup(int index) {
|
| ToolbarActionView* view =
|
| - GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index);
|
| + GetContainer(browser_, test_helper_.get())->GetToolbarActionViewAt(index);
|
| static_cast<ExtensionActionViewController*>(view->view_controller())->
|
| InspectPopup();
|
| }
|
|
|
| bool BrowserActionTestUtil::HasIcon(int index) {
|
| - return !GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
|
| - GetImage(views::Button::STATE_NORMAL).isNull();
|
| + return !GetContainer(browser_, test_helper_.get())
|
| + ->GetToolbarActionViewAt(index)
|
| + ->GetImage(views::Button::STATE_NORMAL)
|
| + .isNull();
|
| }
|
|
|
| gfx::Image BrowserActionTestUtil::GetIcon(int index) {
|
| - gfx::ImageSkia icon =
|
| - GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
|
| - GetIconForTest();
|
| + gfx::ImageSkia icon = GetContainer(browser_, test_helper_.get())
|
| + ->GetToolbarActionViewAt(index)
|
| + ->GetIconForTest();
|
| return gfx::Image(icon);
|
| }
|
|
|
| void BrowserActionTestUtil::Press(int index) {
|
| - GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
|
| - view_controller()->ExecuteAction(true);
|
| + GetContainer(browser_, test_helper_.get())
|
| + ->GetToolbarActionViewAt(index)
|
| + ->view_controller()
|
| + ->ExecuteAction(true);
|
| }
|
|
|
| std::string BrowserActionTestUtil::GetExtensionId(int index) {
|
| - return GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
|
| - view_controller()->GetId();
|
| + return GetContainer(browser_, test_helper_.get())
|
| + ->GetToolbarActionViewAt(index)
|
| + ->view_controller()
|
| + ->GetId();
|
| }
|
|
|
| std::string BrowserActionTestUtil::GetTooltip(int index) {
|
| base::string16 text;
|
| - GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
|
| - GetTooltipText(gfx::Point(), &text);
|
| + GetContainer(browser_, test_helper_.get())
|
| + ->GetToolbarActionViewAt(index)
|
| + ->GetTooltipText(gfx::Point(), &text);
|
| return base::UTF16ToUTF8(text);
|
| }
|
|
|
| @@ -108,8 +169,9 @@ bool BrowserActionTestUtil::HidePopup() {
|
| }
|
|
|
| bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) {
|
| - return GetContainer(browser_, bar_delegate_)->GetToolbarActionViewAt(index)->
|
| - wants_to_run_for_testing();
|
| + return GetContainer(browser_, test_helper_.get())
|
| + ->GetToolbarActionViewAt(index)
|
| + ->wants_to_run_for_testing();
|
| }
|
|
|
| bool BrowserActionTestUtil::OverflowedActionButtonWantsToRun() {
|
| @@ -118,7 +180,13 @@ bool BrowserActionTestUtil::OverflowedActionButtonWantsToRun() {
|
| }
|
|
|
| ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() {
|
| - return GetContainer(browser_, bar_delegate_)->toolbar_actions_bar();
|
| + return GetContainer(browser_, test_helper_.get())->toolbar_actions_bar();
|
| +}
|
| +
|
| +scoped_ptr<BrowserActionTestUtil> BrowserActionTestUtil::CreateOverflowBar() {
|
| + CHECK(!GetToolbarActionsBar()->in_overflow_mode())
|
| + << "Only a main bar can create an overflow bar!";
|
| + return make_scoped_ptr(new BrowserActionTestUtil(browser_, this));
|
| }
|
|
|
| // static
|
| @@ -130,3 +198,11 @@ gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
|
| gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
|
| return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight);
|
| }
|
| +
|
| +BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser,
|
| + BrowserActionTestUtil* main_bar)
|
| + : browser_(browser),
|
| + test_helper_(new TestToolbarActionsBarHelperViews(
|
| + browser_,
|
| + GetContainer(browser_, main_bar->test_helper_.get()))) {
|
| +}
|
|
|