This source file includes following definitions.
- SetUpOnMainThread
- browser_actions_bar
- EnsureExtensionHasIcon
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
#include "chrome/browser/extensions/browser_action_test_util.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_toolbar_model.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/views/toolbar/browser_action_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/common/extension.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/view.h"
class BrowserActionsContainerTest : public ExtensionBrowserTest {
public:
BrowserActionsContainerTest() {
}
virtual ~BrowserActionsContainerTest() {}
virtual void SetUpOnMainThread() OVERRIDE {
browser_actions_bar_.reset(new BrowserActionTestUtil(browser()));
}
BrowserActionTestUtil* browser_actions_bar() {
return browser_actions_bar_.get();
}
void EnsureExtensionHasIcon(int extension_index) {
if (!browser_actions_bar_->HasIcon(extension_index)) {
ExtensionAction* browser_action =
browser_actions_bar_->GetExtensionAction(extension_index);
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
content::Source<ExtensionAction>(browser_action));
observer.Wait();
}
EXPECT_TRUE(browser_actions_bar()->HasIcon(extension_index));
}
private:
scoped_ptr<BrowserActionTestUtil> browser_actions_bar_;
};
#if defined(OS_WIN)
IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DISABLED_Basic) {
#else
IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Basic) {
#endif
BrowserActionsContainer::disable_animations_during_testing_ = true;
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("none")));
EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("basics")));
EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
EnsureExtensionHasIcon(0);
std::string id = browser_actions_bar()->GetExtensionId(0);
UnloadExtension(id);
EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
}
IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Visibility) {
BrowserActionsContainer::disable_animations_during_testing_ = true;
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("basics")));
EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
EnsureExtensionHasIcon(0);
EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
std::string idA = browser_actions_bar()->GetExtensionId(0);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("add_popup")));
EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
EnsureExtensionHasIcon(0);
EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
std::string idB = browser_actions_bar()->GetExtensionId(1);
EXPECT_NE(idA, idB);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("remove_popup")));
EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
EnsureExtensionHasIcon(2);
EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
std::string idC = browser_actions_bar()->GetExtensionId(2);
browser_actions_bar()->SetIconVisibilityCount(1);
EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
DisableExtension(idA);
EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(0));
EnableExtension(idA);
EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0));
DisableExtension(idC);
EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0));
EnableExtension(idC);
EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0));
browser_actions_bar()->SetIconVisibilityCount(3);
EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
DisableExtension(idA);
EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(0));
DisableExtension(idB);
EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idC, browser_actions_bar()->GetExtensionId(0));
EnableExtension(idB);
EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(0));
EnableExtension(idA);
EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0));
}
IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, ForceHide) {
BrowserActionsContainer::disable_animations_during_testing_ = true;
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("basics")));
EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
EnsureExtensionHasIcon(0);
EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
std::string idA = browser_actions_bar()->GetExtensionId(0);
extensions::ExtensionActionAPI::SetBrowserActionVisibility(
extensions::ExtensionPrefs::Get(browser()->profile()), idA, false);
EXPECT_EQ(0, browser_actions_bar()->VisibleBrowserActions());
}
IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, HighlightMode) {
BrowserActionsContainer::disable_animations_during_testing_ = true;
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("basics")));
std::string id_a = browser_actions_bar()->GetExtensionId(0);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("add_popup")));
std::string id_b = browser_actions_bar()->GetExtensionId(1);
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("remove_popup")));
EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
BrowserActionsContainer* container = browser()
->window()
->GetBrowserWindowTesting()
->GetToolbarView()
->browser_actions();
BrowserActionView* action_view = container->GetBrowserActionViewAt(0);
ASSERT_TRUE(action_view);
gfx::Point point(action_view->x(), action_view->y());
EXPECT_TRUE(container->CanStartDragForView(action_view, point, point));
extensions::ExtensionToolbarModel* model =
extensions::ExtensionToolbarModel::Get(profile());
extensions::ExtensionIdList extension_ids;
extension_ids.push_back(id_a);
extension_ids.push_back(id_b);
model->HighlightExtensions(extension_ids);
EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
action_view = container->GetBrowserActionViewAt(0);
EXPECT_FALSE(container->CanStartDragForView(action_view, point, point));
model->StopHighlighting();
EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
action_view = container->GetBrowserActionViewAt(0);
EXPECT_TRUE(container->CanStartDragForView(action_view, point, point));
}