Commit 88a5d47e authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

Create a cross-platform browsertest for the browser actions bar

Move the setup from BrowserActionsContainerTest into a
platform-independent test, so that we also start to get
test coverage on Mac.  In this first patch, move the
infrastructure and the basic test.  More to follow.

BUG=422381

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

Cr-Commit-Position: refs/heads/master@{#299313}
parent 69b99efe
......@@ -66,6 +66,12 @@ class BrowserActionTestUtil {
// Set how many icons should be visible.
void SetIconVisibilityCount(size_t icons);
// Disables animation.
static void DisableAnimations();
// Enables animation.
static void EnableAnimations();
// Returns the minimum allowed size of an extension popup.
static gfx::Size GetMinPopupSize();
......
......@@ -9,6 +9,7 @@
#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/extensions/browser_action_button.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
#import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
#import "chrome/browser/ui/cocoa/info_bubble_window.h"
......@@ -26,7 +27,7 @@ BrowserActionsController* GetController(Browser* browser) {
browserActionsController];
}
NSButton* GetButton(Browser* browser, int index) {
BrowserActionButton* GetButton(Browser* browser, int index) {
return [GetController(browser) buttonWithIndex:index];
}
......@@ -36,6 +37,10 @@ int BrowserActionTestUtil::NumberOfBrowserActions() {
return [GetController(browser_) buttonCount];
}
int BrowserActionTestUtil::VisibleBrowserActions() {
return [GetController(browser_) visibleButtonCount];
}
ExtensionAction* BrowserActionTestUtil::GetExtensionAction(int index) {
NOTREACHED();
return NULL;
......@@ -63,6 +68,10 @@ void BrowserActionTestUtil::Press(int index) {
[button performClick:nil];
}
std::string BrowserActionTestUtil::GetExtensionId(int index) {
return [GetButton(browser_, index) extension]->id();
}
std::string BrowserActionTestUtil::GetTooltip(int index) {
NSString* tooltip = [GetButton(browser_, index) toolTip];
return base::SysNSStringToUTF8(tooltip);
......@@ -90,10 +99,20 @@ bool BrowserActionTestUtil::HidePopup() {
return !HasPopup();
}
// static
void BrowserActionTestUtil::DisableAnimations() {
}
// static
void BrowserActionTestUtil::EnableAnimations() {
}
// static
gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
return gfx::Size(NSSizeToCGSize([ExtensionPopupController minPopupSize]));
}
// static
gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
return gfx::Size(NSSizeToCGSize([ExtensionPopupController maxPopupSize]));
}
......@@ -110,7 +110,7 @@ extern NSString* const kBrowserActionVisibilityChangedNotification;
@end // @interface BrowserActionsController
@interface BrowserActionsController(TestingAPI)
- (NSButton*)buttonWithIndex:(NSUInteger)index;
- (BrowserActionButton*)buttonWithIndex:(NSUInteger)index;
@end
#endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTROLLER_H_
......@@ -852,7 +852,7 @@ class ExtensionServiceObserverBridge
#pragma mark -
#pragma mark Testing Methods
- (NSButton*)buttonWithIndex:(NSUInteger)index {
- (BrowserActionButton*)buttonWithIndex:(NSUInteger)index {
const extensions::ExtensionList& toolbar_items =
toolbarModel_->toolbar_items();
if (index < toolbar_items.size()) {
......
// 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/browser_actions_bar_browsertest.h"
#include "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "components/crx_file/id_util.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
namespace {
scoped_refptr<const extensions::Extension> CreateExtension(
const std::string& name,
bool has_browser_action) {
extensions::DictionaryBuilder manifest;
manifest.Set("name", name).
Set("description", "an extension").
Set("manifest_version", 2).
Set("version", "1.0");
if (has_browser_action)
manifest.Set("browser_action", extensions::DictionaryBuilder().Pass());
return extensions::ExtensionBuilder().
SetManifest(manifest.Pass()).
SetID(crx_file::id_util::GenerateId(name)).
Build();
}
} // namespace
BrowserActionsBarBrowserTest::BrowserActionsBarBrowserTest() {
}
BrowserActionsBarBrowserTest::~BrowserActionsBarBrowserTest() {
}
void BrowserActionsBarBrowserTest::SetUpCommandLine(
base::CommandLine* command_line) {
BrowserActionTestUtil::DisableAnimations();
ExtensionBrowserTest::SetUpCommandLine(command_line);
}
void BrowserActionsBarBrowserTest::SetUpOnMainThread() {
ExtensionBrowserTest::SetUpOnMainThread();
browser_actions_bar_.reset(new BrowserActionTestUtil(browser()));
}
void BrowserActionsBarBrowserTest::TearDownOnMainThread() {
BrowserActionTestUtil::EnableAnimations();
ExtensionBrowserTest::TearDownOnMainThread();
}
void BrowserActionsBarBrowserTest::LoadExtensions() {
// Create three extensions with browser actions.
extension_a_ = CreateExtension("alpha", true);
extension_b_ = CreateExtension("beta", true);
extension_c_ = CreateExtension("gamma", true);
const extensions::Extension* extensions[] =
{ extension_a(), extension_b(), extension_c() };
extensions::ExtensionRegistry* registry =
extensions::ExtensionRegistry::Get(profile());
// Add each, and verify that it is both correctly added to the extension
// registry and to the browser actions container.
for (size_t i = 0; i < arraysize(extensions); ++i) {
extension_service()->AddExtension(extensions[i]);
EXPECT_TRUE(registry->enabled_extensions().GetByID(extensions[i]->id())) <<
extensions[i]->name();
EXPECT_EQ(static_cast<int>(i + 1),
browser_actions_bar_->NumberOfBrowserActions());
EXPECT_TRUE(browser_actions_bar_->HasIcon(i));
EXPECT_EQ(static_cast<int>(i + 1),
browser_actions_bar()->VisibleBrowserActions());
}
}
// Test the basic functionality.
IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, Basic) {
// Load an extension with no browser action.
extension_service()->AddExtension(CreateExtension("alpha", false).get());
// This extension should not be in the model (has no browser action).
EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
// Load an extension with a browser action.
extension_service()->AddExtension(CreateExtension("beta", true).get());
EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_TRUE(browser_actions_bar()->HasIcon(0));
// Unload the extension.
std::string id = browser_actions_bar()->GetExtensionId(0);
UnloadExtension(id);
EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
}
// 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_BROWSER_ACTIONS_BAR_BROWSERTEST_H_
#define CHROME_BROWSER_UI_TOOLBAR_BROWSER_ACTIONS_BAR_BROWSERTEST_H_
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/extension_browsertest.h"
namespace extensions {
class Extension;
}
class BrowserActionTestUtil;
// A platform-independent browser test class for the browser actions bar.
class BrowserActionsBarBrowserTest : public ExtensionBrowserTest {
protected:
BrowserActionsBarBrowserTest();
virtual ~BrowserActionsBarBrowserTest();
virtual void SetUpCommandLine(base::CommandLine* command_line) override;
virtual void SetUpOnMainThread() override;
virtual void TearDownOnMainThread() override;
BrowserActionTestUtil* browser_actions_bar() {
return browser_actions_bar_.get();
}
// Creates three different extensions, each with a browser action, and adds
// them to associated ExtensionService. These can then be accessed via
// extension_[a|b|c]().
void LoadExtensions();
const extensions::Extension* extension_a() const {
return extension_a_.get();
}
const extensions::Extension* extension_b() const {
return extension_b_.get();
}
const extensions::Extension* extension_c() const {
return extension_c_.get();
}
private:
scoped_ptr<BrowserActionTestUtil> browser_actions_bar_;
// Extensions with browser actions used for testing.
scoped_refptr<const extensions::Extension> extension_a_;
scoped_refptr<const extensions::Extension> extension_b_;
scoped_refptr<const extensions::Extension> extension_c_;
DISALLOW_COPY_AND_ASSIGN(BrowserActionsBarBrowserTest);
};
#endif // CHROME_BROWSER_UI_TOOLBAR_BROWSER_ACTIONS_BAR_BROWSERTEST_H_
......@@ -96,10 +96,22 @@ void BrowserActionTestUtil::SetIconVisibilityCount(size_t icons) {
SetVisibleIconCount(icons);
}
// static
void BrowserActionTestUtil::DisableAnimations() {
BrowserActionsContainer::disable_animations_during_testing_ = true;
}
// static
void BrowserActionTestUtil::EnableAnimations() {
BrowserActionsContainer::disable_animations_during_testing_ = false;
}
// static
gfx::Size BrowserActionTestUtil::GetMinPopupSize() {
return gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight);
}
// static
gfx::Size BrowserActionTestUtil::GetMaxPopupSize() {
return gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight);
}
......@@ -627,6 +627,8 @@
'browser/ui/sync/profile_signin_confirmation_helper_browsertest.cc',
'browser/ui/tab_modal_confirm_dialog_browsertest.cc',
'browser/ui/tab_modal_confirm_dialog_browsertest.h',
'browser/ui/toolbar/browser_actions_bar_browsertest.cc',
'browser/ui/toolbar/browser_actions_bar_browsertest.h',
'browser/ui/toolbar/test_toolbar_model.cc',
'browser/ui/toolbar/test_toolbar_model.h',
'browser/ui/views/autofill/autofill_dialog_view_tester_views.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