Commit 0c1c08b2 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions Toolbar] Refactor a few test classes

Pull the implementation of TestToolbarActionsBarHelper into
BrowserActionTestUtil. The former is really only ever used
with the latter, and this allows:
- Tests to only worry about one test object.
- For one top-level fewer platform-specific test class.

TBR=sky@chromium.org (something wonky in our OWNERs check isn't counting Finnur/me as owners for toolbar actions stuff...)

Review URL: https://codereview.chromium.org/1104813005

Cr-Commit-Position: refs/heads/master@{#327134}
parent 102fd46d
......@@ -80,7 +80,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) {
if (!ShouldRunPopupTest())
return;
BrowserActionTestUtil browserActionBar = BrowserActionTestUtil(browser());
BrowserActionTestUtil browserActionBar(browser());
// Setup extension message listener to wait for javascript to finish running.
ExtensionTestMessageListener listener("ready", true);
{
......
......@@ -7,6 +7,7 @@
#include <string>
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/native_widget_types.h"
class Browser;
......@@ -19,18 +20,25 @@ class Rect;
class Size;
} // namespace gfx
// A class that creates and owns the platform-specific views for the browser
// actions container. Specific implementations are in the .cc/.mm files.
class TestToolbarActionsBarHelper {
public:
virtual ~TestToolbarActionsBarHelper() {}
};
class BrowserActionTestUtil {
public:
// Constructs a BrowserActionTestUtil that uses the |browser|'s default
// browser action container.
explicit BrowserActionTestUtil(Browser* browser)
: browser_(browser), bar_delegate_(nullptr) {}
explicit BrowserActionTestUtil(Browser* browser);
// Constructs a BrowserActionTestUtil which, if |is_real_window| is false,
// will create its own browser actions container. This is useful in unit
// tests, when the |browser|'s window doesn't create platform-specific views.
BrowserActionTestUtil(Browser* browser, bool is_real_window);
// Constructs a BrowserActionTestUtil that will use the |bar_delegate| as the
// browser action container to test.
BrowserActionTestUtil(Browser* browser,
ToolbarActionsBarDelegate* bar_delegate)
: browser_(browser), bar_delegate_(bar_delegate) {}
~BrowserActionTestUtil();
// Returns the number of browser action buttons in the window toolbar.
int NumberOfBrowserActions();
......@@ -85,6 +93,10 @@ class BrowserActionTestUtil {
// Returns the ToolbarActionsBar.
ToolbarActionsBar* GetToolbarActionsBar();
// Creates and returns a BrowserActionTestUtil with an "overflow" container,
// with this object's container as the main bar.
scoped_ptr<BrowserActionTestUtil> CreateOverflowBar();
// Returns the minimum allowed size of an extension popup.
static gfx::Size GetMinPopupSize();
......@@ -92,11 +104,16 @@ class BrowserActionTestUtil {
static gfx::Size GetMaxPopupSize();
private:
// A private constructor to create an overflow version.
BrowserActionTestUtil(Browser* browser, BrowserActionTestUtil* main_bar);
Browser* browser_; // weak
// If non-null, this is a set view to test with, rather than using the
// |browser|'s default container.
ToolbarActionsBarDelegate* bar_delegate_; // weak
// Our test helper, which constructs and owns the views if we don't have a
// real browser window, or if this is an overflow version.
scoped_ptr<TestToolbarActionsBarHelper> test_helper_;
DISALLOW_COPY_AND_ASSIGN(BrowserActionTestUtil);
};
#endif // CHROME_BROWSER_EXTENSIONS_BROWSER_ACTION_TEST_UTIL_H_
......@@ -133,10 +133,6 @@ class CommandsApiTest : public ExtensionApiTest {
~CommandsApiTest() override {}
protected:
BrowserActionTestUtil GetBrowserActionsBar() {
return BrowserActionTestUtil(browser());
}
bool IsGrantedForTab(const Extension* extension,
const content::WebContents* web_contents) {
return extension->permissions_data()->HasAPIPermissionForTab(
......@@ -187,8 +183,9 @@ IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) {
// immaterial to this test).
ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_;
BrowserActionTestUtil browser_actions_bar(browser());
// Test that there are two browser actions in the toolbar.
ASSERT_EQ(2, GetBrowserActionsBar().NumberOfBrowserActions());
ASSERT_EQ(2, browser_actions_bar.NumberOfBrowserActions());
ui_test_utils::NavigateToURL(
browser(), test_server()->GetURL("files/extensions/test_file.txt"));
......
......@@ -4,11 +4,14 @@
#include "chrome/browser/extensions/browser_action_test_util.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/path_service.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/browser.h"
#import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
......@@ -19,6 +22,8 @@
#import "chrome/browser/ui/cocoa/themed_window.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
#include "chrome/common/chrome_constants.h"
#include "grit/theme_resources.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/geometry/rect.h"
......@@ -26,11 +31,54 @@
namespace {
BrowserActionsController* GetController(
// The Cocoa implementation of the TestToolbarActionsBarHelper, which creates
// (and owns) a BrowserActionsController and BrowserActionsContainerView for
// testing purposes.
class TestToolbarActionsBarHelperCocoa : public TestToolbarActionsBarHelper {
public:
TestToolbarActionsBarHelperCocoa(Browser* browser,
BrowserActionsController* mainController);
~TestToolbarActionsBarHelperCocoa() override;
BrowserActionsController* controller() { return controller_.get(); }
private:
// The owned BrowserActionsContainerView and BrowserActionsController; the
// mac implementation of the ToolbarActionsBar delegate and view.
base::scoped_nsobject<BrowserActionsContainerView> containerView_;
base::scoped_nsobject<BrowserActionsController> controller_;
DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelperCocoa);
};
TestToolbarActionsBarHelperCocoa::TestToolbarActionsBarHelperCocoa(
Browser* browser,
ToolbarActionsBarDelegate* barDelegate) {
if (barDelegate)
return [BrowserActionsController fromToolbarActionsBarDelegate:barDelegate];
BrowserActionsController* mainController) {
// Make sure that Cocoa has been bootstrapped.
if (!base::mac::FrameworkBundle()) {
// Look in the framework bundle for resources.
base::FilePath path;
PathService::Get(base::DIR_EXE, &path);
path = path.Append(chrome::kFrameworkName);
base::mac::SetOverrideFrameworkBundlePath(path);
}
containerView_.reset([[BrowserActionsContainerView alloc]
initWithFrame:NSMakeRect(0, 0, 0, 15)]);
controller_.reset(
[[BrowserActionsController alloc] initWithBrowser:browser
containerView:containerView_.get()
mainController:mainController]);
}
TestToolbarActionsBarHelperCocoa::~TestToolbarActionsBarHelperCocoa() {
}
BrowserActionsController* GetController(Browser* browser,
TestToolbarActionsBarHelper* helper) {
if (helper) {
return static_cast<TestToolbarActionsBarHelperCocoa*>(helper)->controller();
}
BrowserWindowCocoa* window =
static_cast<BrowserWindowCocoa*>(browser->window());
......@@ -40,23 +88,37 @@ BrowserActionsController* GetController(
BrowserActionButton* GetButton(
Browser* browser,
ToolbarActionsBarDelegate* barDelegate,
TestToolbarActionsBarHelper* helper,
int index) {
return [GetController(browser, barDelegate) buttonWithIndex:index];
return [GetController(browser, helper) buttonWithIndex:index];
}
} // 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 TestToolbarActionsBarHelperCocoa(browser, nullptr));
}
BrowserActionTestUtil::~BrowserActionTestUtil() {}
int BrowserActionTestUtil::NumberOfBrowserActions() {
return [GetController(browser_, bar_delegate_) buttonCount];
return [GetController(browser_, test_helper_.get()) buttonCount];
}
int BrowserActionTestUtil::VisibleBrowserActions() {
return [GetController(browser_, bar_delegate_) visibleButtonCount];
return [GetController(browser_, test_helper_.get()) visibleButtonCount];
}
bool BrowserActionTestUtil::IsChevronShowing() {
BrowserActionsController* controller = GetController(browser_, bar_delegate_);
BrowserActionsController* controller =
GetController(browser_, test_helper_.get());
// The magic "18" comes from kChevronWidth in browser_actions_controller.mm.
return ![controller chevronIsHidden] &&
NSWidth([[controller containerView] animationEndFrame]) >= 18;
......@@ -67,11 +129,11 @@ void BrowserActionTestUtil::InspectPopup(int index) {
}
bool BrowserActionTestUtil::HasIcon(int index) {
return [GetButton(browser_, bar_delegate_, index) image] != nil;
return [GetButton(browser_, test_helper_.get(), index) image] != nil;
}
gfx::Image BrowserActionTestUtil::GetIcon(int index) {
NSImage* ns_image = [GetButton(browser_, bar_delegate_, index) image];
NSImage* ns_image = [GetButton(browser_, test_helper_.get(), index) image];
// gfx::Image takes ownership of the |ns_image| reference. We have to increase
// the ref count so |ns_image| stays around when the image object is
// destroyed.
......@@ -80,16 +142,17 @@ gfx::Image BrowserActionTestUtil::GetIcon(int index) {
}
void BrowserActionTestUtil::Press(int index) {
NSButton* button = GetButton(browser_, bar_delegate_, index);
NSButton* button = GetButton(browser_, test_helper_.get(), index);
[button performClick:nil];
}
std::string BrowserActionTestUtil::GetExtensionId(int index) {
return [GetButton(browser_, bar_delegate_, index) viewController]->GetId();
return
[GetButton(browser_, test_helper_.get(), index) viewController]->GetId();
}
std::string BrowserActionTestUtil::GetTooltip(int index) {
NSString* tooltip = [GetButton(browser_, bar_delegate_, index) toolTip];
NSString* tooltip = [GetButton(browser_, test_helper_.get(), index) toolTip];
return base::SysNSStringToUTF8(tooltip);
}
......@@ -116,7 +179,8 @@ bool BrowserActionTestUtil::HidePopup() {
}
bool BrowserActionTestUtil::ActionButtonWantsToRun(size_t index) {
BrowserActionsController* controller = GetController(browser_, bar_delegate_);
BrowserActionsController* controller =
GetController(browser_, test_helper_.get());
ui::ThemeProvider* themeProvider =
[[[controller containerView] window] themeProvider];
DCHECK(themeProvider);
......@@ -141,7 +205,13 @@ bool BrowserActionTestUtil::OverflowedActionButtonWantsToRun() {
}
ToolbarActionsBar* BrowserActionTestUtil::GetToolbarActionsBar() {
return [GetController(browser_, bar_delegate_) toolbarActionsBar];
return [GetController(browser_, test_helper_.get()) toolbarActionsBar];
}
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
......@@ -153,3 +223,10 @@ gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
return gfx::Size(NSSizeToCGSize([ExtensionPopupController maxPopupSize]));
}
BrowserActionTestUtil::BrowserActionTestUtil(Browser* browser,
BrowserActionTestUtil* main_bar)
: browser_(browser),
test_helper_(new TestToolbarActionsBarHelperCocoa(
browser_, GetController(browser_, main_bar->test_helper_.get()))) {
}
......@@ -115,8 +115,6 @@ extern NSString* const kBrowserActionVisibilityChangedNotification;
@interface BrowserActionsController(TestingAPI)
- (BrowserActionButton*)buttonWithIndex:(NSUInteger)index;
- (ToolbarActionsBar*)toolbarActionsBar;
+ (BrowserActionsController*)fromToolbarActionsBarDelegate:
(ToolbarActionsBarDelegate*)delegate;
@end
#endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_
......@@ -945,9 +945,4 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
return toolbarActionsBar_.get();
}
+ (BrowserActionsController*)fromToolbarActionsBarDelegate:
(ToolbarActionsBarDelegate*)delegate {
return static_cast<ToolbarActionsBarBridge*>(delegate)->controller_for_test();
}
@end
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_helper.h"
#import "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
namespace {
// The Cocoa implementation of the TestToolbarActionsBarHelper, which creates
// (and owns) a BrowserActionsController and BrowserActionsContainerView for
// testing purposes.
class TestToolbarActionsBarHelperCocoa : public TestToolbarActionsBarHelper {
public:
TestToolbarActionsBarHelperCocoa(Browser* browser,
TestToolbarActionsBarHelperCocoa* mainBar);
~TestToolbarActionsBarHelperCocoa() override;
private:
// TestToolbarActionsBarHelper:
ToolbarActionsBar* GetToolbarActionsBar() override;
// The owned BrowserActionsContainerView and BrowserActionsController; the
// mac implementation of the ToolbarActionsBar delegate and view.
base::scoped_nsobject<BrowserActionsContainerView> containerView_;
base::scoped_nsobject<BrowserActionsController> controller_;
DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelperCocoa);
};
TestToolbarActionsBarHelperCocoa::TestToolbarActionsBarHelperCocoa(
Browser* browser,
TestToolbarActionsBarHelperCocoa* mainBar) {
// Make sure that Cocoa has been bootstrapped.
CocoaTest::BootstrapCocoa();
containerView_.reset([[BrowserActionsContainerView alloc]
initWithFrame:NSMakeRect(0, 0, 0, 15)]);
BrowserActionsController* mainController =
mainBar ? mainBar->controller_.get() : nil;
controller_.reset([[BrowserActionsController alloc]
initWithBrowser:browser
containerView:containerView_.get()
mainController:mainController]);
}
TestToolbarActionsBarHelperCocoa::~TestToolbarActionsBarHelperCocoa() {}
ToolbarActionsBar* TestToolbarActionsBarHelperCocoa::GetToolbarActionsBar() {
return [controller_ toolbarActionsBar];
}
} // namespace
scoped_ptr<TestToolbarActionsBarHelper> TestToolbarActionsBarHelper::Create(
Browser* browser,
TestToolbarActionsBarHelper* main_bar) {
return make_scoped_ptr(new TestToolbarActionsBarHelperCocoa(
browser,
static_cast<TestToolbarActionsBarHelperCocoa*>(main_bar)));
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_ACTIONS_BAR_HELPER_H_
#define CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_ACTIONS_BAR_HELPER_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
class Browser;
class ToolbarActionsBar;
// A cross-platform container that creates and owns a ToolbarActionsBar and the
// corresponding view.
class TestToolbarActionsBarHelper {
public:
TestToolbarActionsBarHelper() {}
virtual ~TestToolbarActionsBarHelper() {}
// Creates and returns a TestToolbarActionsBarHelper. If |main_bar| is
// non-null, the created actions bar will be in overflow mode.
static scoped_ptr<TestToolbarActionsBarHelper> Create(
Browser* browser,
TestToolbarActionsBarHelper* main_bar);
virtual ToolbarActionsBar* GetToolbarActionsBar() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(TestToolbarActionsBarHelper);
};
#endif // CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_ACTIONS_BAR_HELPER_H_
......@@ -19,7 +19,6 @@
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_helper.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h"
#include "chrome/common/pref_names.h"
......@@ -138,10 +137,10 @@ class ToolbarActionsBarUnitTest : public BrowserWithTestWindowTest {
size_t visible_count) WARN_UNUSED_RESULT;
ToolbarActionsBar* toolbar_actions_bar() {
return main_bar_helper_->GetToolbarActionsBar();
return browser_action_test_util_->GetToolbarActionsBar();
}
ToolbarActionsBar* overflow_bar() {
return overflow_bar_helper_->GetToolbarActionsBar();
return overflow_browser_action_test_util_->GetToolbarActionsBar();
}
extensions::ExtensionToolbarModel* toolbar_model() {
return toolbar_model_;
......@@ -154,14 +153,6 @@ class ToolbarActionsBarUnitTest : public BrowserWithTestWindowTest {
}
private:
// The test helper that owns the ToolbarActionsBar and the platform-specific
// view for it.
scoped_ptr<TestToolbarActionsBarHelper> main_bar_helper_;
// The test helper for the overflow bar; only non-null if |use_redesign| is
// true.
scoped_ptr<TestToolbarActionsBarHelper> overflow_bar_helper_;
// The associated ExtensionToolbarModel (owned by the keyed service setup).
extensions::ExtensionToolbarModel* toolbar_model_;
......@@ -201,28 +192,21 @@ void ToolbarActionsBarUnitTest::SetUp() {
extensions::extension_action_test_util::CreateToolbarModelForProfile(
profile());
main_bar_helper_ = TestToolbarActionsBarHelper::Create(browser(), nullptr);
ToolbarActionsBar::disable_animations_for_testing_ = true;
ToolbarActionsBar::set_send_overflowed_action_changes_for_testing(false);
browser_action_test_util_.reset(
new BrowserActionTestUtil(browser(),
toolbar_actions_bar()->delegate_for_test()));
browser_action_test_util_.reset(new BrowserActionTestUtil(browser(), false));
if (use_redesign_) {
overflow_bar_helper_ =
TestToolbarActionsBarHelper::Create(browser(), main_bar_helper_.get());
overflow_browser_action_test_util_.reset(
new BrowserActionTestUtil(browser(),
overflow_bar()->delegate_for_test()));
overflow_browser_action_test_util_ =
browser_action_test_util_->CreateOverflowBar();
}
}
void ToolbarActionsBarUnitTest::TearDown() {
// Since the profile gets destroyed in BrowserWithTestWindowTest::TearDown(),
// we need to delete this now.
overflow_bar_helper_.reset();
main_bar_helper_.reset();
browser_action_test_util_.reset();
overflow_browser_action_test_util_.reset();
ToolbarActionsBar::disable_animations_for_testing_ = false;
redesign_switch_.reset();
BrowserWithTestWindowTest::TearDown();
......
......@@ -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()))) {
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_helper.h"
#include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
#include "ui/views/view.h"
namespace {
// The views-specific implementation of the TestToolbarActionsBarHelper, which
// creates and owns a BrowserActionsContainer.
class TestToolbarActionsBarHelperViews : public TestToolbarActionsBarHelper {
public:
TestToolbarActionsBarHelperViews(Browser* browser,
TestToolbarActionsBarHelperViews* main_bar);
~TestToolbarActionsBarHelperViews() override;
private:
// TestToolbarActionsBarHelper:
ToolbarActionsBar* GetToolbarActionsBar() override;
// 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,
TestToolbarActionsBarHelperViews* main_bar)
: browser_actions_container_(
new BrowserActionsContainer(
browser,
main_bar ? main_bar->browser_actions_container_ : nullptr)) {
// 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() {}
ToolbarActionsBar* TestToolbarActionsBarHelperViews::GetToolbarActionsBar() {
return browser_actions_container_->toolbar_actions_bar();
}
} // namespace
// static
scoped_ptr<TestToolbarActionsBarHelper>
TestToolbarActionsBarHelper::Create(Browser* browser,
TestToolbarActionsBarHelper* main_bar) {
return make_scoped_ptr(new TestToolbarActionsBarHelperViews(
browser,
static_cast<TestToolbarActionsBarHelperViews*>(main_bar)));
}
......@@ -416,7 +416,6 @@
'browser/ui/cocoa/extensions/extension_install_view_controller_unittest.mm',
'browser/ui/cocoa/extensions/extension_installed_bubble_controller_unittest.mm',
'browser/ui/cocoa/extensions/media_galleries_dialog_cocoa_unittest.mm',
'browser/ui/cocoa/extensions/test_toolbar_actions_bar_helper_cocoa.mm',
'browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac_unittest.mm',
'browser/ui/cocoa/find_bar/find_bar_bridge_unittest.mm',
'browser/ui/cocoa/find_bar/find_bar_cocoa_controller_unittest.mm',
......@@ -1371,7 +1370,6 @@
'browser/ui/views/tabs/tab_strip_unittest.cc',
'browser/ui/views/tabs/tab_unittest.cc',
'browser/ui/views/toolbar/reload_button_unittest.cc',
'browser/ui/views/toolbar/test_toolbar_actions_bar_helper_views.cc',
'browser/ui/views/toolbar/toolbar_action_view_unittest.cc',
'browser/ui/views/translate/translate_bubble_view_unittest.cc',
'browser/ui/views/validation_message_bubble_delegate_unittest.cc',
......@@ -1513,7 +1511,6 @@
'browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc',
'browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.cc',
'browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.h',
'browser/ui/toolbar/test_toolbar_actions_bar_helper.h',
'browser/ui/toolbar/test_toolbar_model.cc',
'browser/ui/toolbar/test_toolbar_model.h',
'browser/ui/toolbar/toolbar_actions_bar_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment