| Index: chrome/browser/ui/cocoa/extensions/browser_action_test_util_mac.mm
|
| diff --git a/chrome/browser/ui/cocoa/extensions/browser_action_test_util_mac.mm b/chrome/browser/ui/cocoa/extensions/browser_action_test_util_mac.mm
|
| index da052fad73ed473a63614dd9dad106ef7f0b2cb9..51e9f0fe7d03ee1525c9a646d7b64ff0b462a866 100644
|
| --- a/chrome/browser/ui/cocoa/extensions/browser_action_test_util_mac.mm
|
| +++ b/chrome/browser/ui/cocoa/extensions/browser_action_test_util_mac.mm
|
| @@ -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()))) {
|
| +}
|
|
|