| Index: chrome/browser/extensions/browser_action_apitest.cc
|
| diff --git a/chrome/browser/extensions/browser_action_apitest.cc b/chrome/browser/extensions/browser_action_apitest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..89ca98474788ad453b9477e46a7bac61c13b0abe
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/browser_action_apitest.cc
|
| @@ -0,0 +1,86 @@
|
| +// Copyright (c) 2009 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/browser.h"
|
| +#include "chrome/browser/browser_window.h"
|
| +#include "chrome/browser/extensions/extension_apitest.h"
|
| +#include "chrome/browser/extensions/extension_browser_event_router.h"
|
| +#include "chrome/browser/extensions/extension_tabs_module.h"
|
| +#include "chrome/browser/extensions/extensions_service.h"
|
| +#include "chrome/browser/profile.h"
|
| +#include "chrome/browser/tab_contents/tab_contents.h"
|
| +#include "chrome/browser/views/browser_actions_container.h"
|
| +#include "chrome/browser/views/toolbar_view.h"
|
| +#include "chrome/common/extensions/extension_action.h"
|
| +#include "chrome/test/ui_test_utils.h"
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserAction) {
|
| + StartHTTPServer();
|
| + ASSERT_TRUE(RunExtensionTest("browser_action")) << message_;
|
| +
|
| + // Test that there is a browser action in the toolbar.
|
| + BrowserActionsContainer* browser_actions =
|
| + browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
|
| + browser_actions();
|
| + ASSERT_EQ(1, browser_actions->num_browser_actions());
|
| +
|
| + // Tell the extension to update the browser action state.
|
| + TestResultCatcher catcher;
|
| + ExtensionsService* service = browser()->profile()->GetExtensionsService();
|
| + Extension* extension = service->extensions()->at(0);
|
| + ui_test_utils::NavigateToURL(browser(),
|
| + GURL(extension->GetResourceURL("update.html")));
|
| + ASSERT_TRUE(catcher.GetNextResult());
|
| +
|
| + // Test that we received the changes.
|
| + ExtensionActionState* action_state = extension->browser_action_state();
|
| + ASSERT_EQ("Modified", action_state->title());
|
| + ASSERT_EQ(1, action_state->icon_index());
|
| + ASSERT_EQ("badge", action_state->badge_text());
|
| + ASSERT_EQ(SkColorSetARGB(255, 255, 255, 255),
|
| + action_state->badge_background_color());
|
| +
|
| + // Simulate the browser action being clicked.
|
| + ui_test_utils::NavigateToURL(browser(),
|
| + GURL("http://localhost:1337/files/extensions/test_file.txt"));
|
| +
|
| + ExtensionAction* browser_action = service->GetBrowserActions(false)[0];
|
| + int window_id = ExtensionTabUtil::GetWindowId(browser());
|
| + ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted(
|
| + browser()->profile(), browser_action->extension_id(), browser());
|
| +
|
| + // Verify the command worked.
|
| + TabContents* tab = browser()->GetSelectedTabContents();
|
| + bool result = false;
|
| + ui_test_utils::ExecuteJavaScriptAndExtractBool(
|
| + tab->render_view_host(), L"",
|
| + L"setInterval(function(){"
|
| + L" if(document.body.bgColor == 'red'){"
|
| + L" window.domAutomationController.send(true)}}, 100)",
|
| + &result);
|
| + ASSERT_TRUE(result);
|
| +}
|
| +
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DynamicBrowserAction) {
|
| + ASSERT_TRUE(RunExtensionTest("browser_action_no_icon")) << message_;
|
| +
|
| + // Test that there is a browser action in the toolbar.
|
| + BrowserActionsContainer* browser_actions =
|
| + browser()->window()->GetBrowserWindowTesting()->GetToolbarView()->
|
| + browser_actions();
|
| + ASSERT_EQ(1, browser_actions->num_browser_actions());
|
| +
|
| + // Tell the extension to update the browser action state.
|
| + TestResultCatcher catcher;
|
| + ExtensionsService* service = browser()->profile()->GetExtensionsService();
|
| + Extension* extension = service->extensions()->at(0);
|
| + ui_test_utils::NavigateToURL(browser(),
|
| + GURL(extension->GetResourceURL("update.html")));
|
| + ASSERT_TRUE(catcher.GetNextResult());
|
| +
|
| + // Test that we received the changes.
|
| + ExtensionActionState* action_state = extension->browser_action_state();
|
| + ASSERT_TRUE(action_state->icon());
|
| +}
|
|
|