diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-06 17:52:19 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-06 17:52:19 +0000 |
commit | 790788ac7de91db6f349a0ecd1c98fd240b73ca2 (patch) | |
tree | 7fa4cb0c072c2e9d75b9654284273af55cf8586f /chrome/test/automation | |
parent | 86ba6fa82610b38aaf45e3a5497320ddcfb87d79 (diff) | |
download | chromium_src-790788ac7de91db6f349a0ecd1c98fd240b73ca2.zip chromium_src-790788ac7de91db6f349a0ecd1c98fd240b73ca2.tar.gz chromium_src-790788ac7de91db6f349a0ecd1c98fd240b73ca2.tar.bz2 |
Add support for basic extension automation through the Automation Proxy.
BUG=36171
TEST=none
Review URL: http://codereview.chromium.org/1048002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43730 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automation')
-rw-r--r-- | chrome/test/automation/automation_constants.h | 10 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages.h | 37 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 53 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.cc | 30 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.h | 13 | ||||
-rw-r--r-- | chrome/test/automation/extension_proxy.cc | 141 | ||||
-rw-r--r-- | chrome/test/automation/extension_proxy.h | 88 | ||||
-rw-r--r-- | chrome/test/automation/extension_proxy_uitest.cc | 178 |
8 files changed, 539 insertions, 11 deletions
diff --git a/chrome/test/automation/automation_constants.h b/chrome/test/automation/automation_constants.h index cf54a39..f5e3b6f 100644 --- a/chrome/test/automation/automation_constants.h +++ b/chrome/test/automation/automation_constants.h @@ -31,4 +31,14 @@ enum AutomationMsg_ExtensionResponseValues { AUTOMATION_MSG_EXTENSION_ALREADY_INSTALLED, }; +// Used in the AutomationMsg_GetExtensionProperty to identify which extension +// property should be retrieved, instead of having separate messages for each +// property. +enum AutomationMsg_ExtensionProperty { + AUTOMATION_MSG_EXTENSION_ID = 0, + AUTOMATION_MSG_EXTENSION_NAME, + AUTOMATION_MSG_EXTENSION_VERSION, + AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX, +}; + #endif // CHROME_TEST_AUTOMATION_AUTOMATION_CONSTANTS_H_ diff --git a/chrome/test/automation/automation_messages.h b/chrome/test/automation/automation_messages.h index 22ec4d6..ddd1c83 100644 --- a/chrome/test/automation/automation_messages.h +++ b/chrome/test/automation/automation_messages.h @@ -127,6 +127,43 @@ struct ParamTraits<AutomationMsg_ExtensionResponseValues> { }; template <> +struct ParamTraits<AutomationMsg_ExtensionProperty> { + typedef AutomationMsg_ExtensionProperty param_type; + static void Write(Message* m, const param_type& p) { + m->WriteInt(p); + } + static bool Read(const Message* m, void** iter, param_type* p) { + int type; + if (!m->ReadInt(iter, &type)) + return false; + *p = static_cast<AutomationMsg_ExtensionProperty>(type); + return true; + } + static void Log(const param_type& p, std::wstring* l) { + std::wstring control; + switch (p) { + case AUTOMATION_MSG_EXTENSION_ID: + control = L"AUTOMATION_MSG_EXTENSION_ID"; + break; + case AUTOMATION_MSG_EXTENSION_NAME: + control = L"AUTOMATION_MSG_EXTENSION_NAME"; + break; + case AUTOMATION_MSG_EXTENSION_VERSION: + control = L"AUTOMATION_MSG_EXTENSION_VERSION"; + break; + case AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX: + control = L"AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX"; + break; + default: + control = L"UNKNOWN"; + break; + } + + LogParam(control, l); + } +}; + +template <> struct ParamTraits<SecurityStyle> { typedef SecurityStyle param_type; static void Write(Message* m, const param_type& p) { diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index 74dabad..8430172 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -13,6 +13,7 @@ #include "base/basictypes.h" #include "base/string16.h" +#include "base/values.h" #include "chrome/common/content_settings.h" #include "chrome/common/navigation_types.h" #include "chrome/test/automation/autocomplete_edit_proxy.h" @@ -1321,4 +1322,56 @@ IPC_BEGIN_MESSAGES(Automation) std::string /* JSON response */, bool /* success */) + // Installs an extension from the crx file and returns its id. + // On error, |extension handle| will be 0. + IPC_SYNC_MESSAGE_ROUTED1_1(AutomationMsg_InstallExtensionAndGetHandle, + FilePath /* full path to crx file */, + int /* extension handle */) + + // Waits for the next extension test result. Sets |test result| as the + // received result and |message| as any accompanying message with the + // result, which could be the empty string. + IPC_SYNC_MESSAGE_ROUTED0_2(AutomationMsg_WaitForExtensionTestResult, + bool /* test result */, + std::string /* message */) + + // Uninstalls an extension. On success |success| is true. + IPC_SYNC_MESSAGE_ROUTED1_1(AutomationMsg_UninstallExtension, + int /* extension handle */, + bool /* success */) + + // Enables an extension. On success |success| is true. + IPC_SYNC_MESSAGE_ROUTED1_1(AutomationMsg_EnableExtension, + int /* extension handle */, + bool /* success */) + + // Disables an extension. On success |success| is true. + IPC_SYNC_MESSAGE_ROUTED1_1(AutomationMsg_DisableExtension, + int /* extension handle */, + bool /* success */) + + // Executes the action associated with the given extension. This executes + // the extension's page or browser action in the given browser, but does + // not open popups. On success |success| is true. + IPC_SYNC_MESSAGE_ROUTED2_1( + AutomationMsg_ExecuteExtensionActionInActiveTabAsync, + int /* extension handle */, + int /* browser handle */, + bool /* success */) + + // Moves the browser action to the given index in the browser action toolbar. + // On success |success| is true. + IPC_SYNC_MESSAGE_ROUTED2_1(AutomationMsg_MoveExtensionBrowserAction, + int /* extension handle */, + int /* index */, + bool /* success */) + + // Gets an extension property |property type|. On success |success| is true, + // and |property value| is set. + IPC_SYNC_MESSAGE_ROUTED2_2(AutomationMsg_GetExtensionProperty, + int /* extension handle */, + AutomationMsg_ExtensionProperty /* property type */, + bool /* success */, + std::string /* property value */) + IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index 46fcc3b..04bc7ea 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <sstream> - #include "chrome/test/automation/automation_proxy.h" +#include <sstream> + #include "base/basictypes.h" #include "base/file_version_info.h" #include "base/logging.h" @@ -16,8 +16,10 @@ #include "chrome/test/automation/automation_constants.h" #include "chrome/test/automation/automation_messages.h" #include "chrome/test/automation/browser_proxy.h" +#include "chrome/test/automation/extension_proxy.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/window_proxy.h" +#include <gtest/gtest.h> #include "ipc/ipc_descriptors.h" #if defined(OS_WIN) // TODO(port): Enable when dialog_delegate is ported. @@ -230,11 +232,25 @@ bool AutomationProxy::SavePackageShouldPromptUser(bool should_prompt) { return Send(new AutomationMsg_SavePackageShouldPromptUser(0, should_prompt)); } -bool AutomationProxy::InstallExtension(const FilePath& crx_file) { - AutomationMsg_ExtensionResponseValues response; - if (!Send(new AutomationMsg_InstallExtension(0, crx_file, &response))) - return false; - return response == AUTOMATION_MSG_EXTENSION_INSTALL_SUCCEEDED; +scoped_refptr<ExtensionProxy> AutomationProxy::InstallExtension( + const FilePath& crx_file) { + int handle = 0; + if (!Send(new AutomationMsg_InstallExtensionAndGetHandle(0, crx_file, + &handle))) + return NULL; + + return ProxyObjectFromHandle<ExtensionProxy>(handle); +} + +void AutomationProxy::EnsureExtensionTestResult() { + bool result; + std::string message; + if (!Send(new AutomationMsg_WaitForExtensionTestResult(0, &result, + &message))) { + FAIL() << "Could not send WaitForExtensionTestResult message"; + return; + } + ASSERT_TRUE(result) << "Extension test message: " << message; } bool AutomationProxy::GetEnabledExtensions( diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h index 7809ec1..f0a6cd8 100644 --- a/chrome/test/automation/automation_proxy.h +++ b/chrome/test/automation/automation_proxy.h @@ -26,6 +26,7 @@ #include "ipc/ipc_sync_channel.h" class BrowserProxy; +class ExtensionProxy; class TabProxy; class WindowProxy; @@ -181,10 +182,13 @@ class AutomationProxy : public IPC::Channel::Listener, // sent. bool SavePackageShouldPromptUser(bool should_prompt) WARN_UNUSED_RESULT; - // Installs the extension crx. Returns true only if extension was installed - // and loaded successfully. - // Note: Overinstalls will fail. - bool InstallExtension(const FilePath& crx_file) WARN_UNUSED_RESULT; + // Installs the extension crx. Returns the ExtensionProxy for the + // installed extension, or NULL on failure. + // Note: Overinstalls and downgrades will return NULL. + scoped_refptr<ExtensionProxy> InstallExtension(const FilePath& crx_file); + + // Asserts that the next extension test result is true. + void EnsureExtensionTestResult(); // Gets a list of all enabled extensions' base directories. // Returns true on success. @@ -196,6 +200,7 @@ class AutomationProxy : public IPC::Channel::Listener, bool LoginWithUserAndPass(const std::string& username, const std::string& password) WARN_UNUSED_RESULT; #endif + // Returns the ID of the automation IPC channel, so that it can be // passed to the app as a launch parameter. const std::string& channel_id() const { return channel_id_; } diff --git a/chrome/test/automation/extension_proxy.cc b/chrome/test/automation/extension_proxy.cc new file mode 100644 index 0000000..66aa8e8 --- /dev/null +++ b/chrome/test/automation/extension_proxy.cc @@ -0,0 +1,141 @@ +// Copyright (c) 2010 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/test/automation/extension_proxy.h" + +#include "chrome/test/automation/automation_messages.h" +#include "chrome/test/automation/automation_proxy.h" +#include "chrome/test/automation/browser_proxy.h" +#include "testing/gtest/include/gtest/gtest.h" + +ExtensionProxy::ExtensionProxy(AutomationMessageSender* sender, + AutomationHandleTracker* tracker, + int handle) + : AutomationResourceProxy(tracker, sender, handle) { +} + +bool ExtensionProxy::Uninstall() { + if (!is_valid()) + return false; + + bool success = false; + if (!sender_->Send(new AutomationMsg_UninstallExtension(0, handle_, + &success))) + return false; + return success; +} + +bool ExtensionProxy::Enable() { + if (!is_valid()) + return false; + + bool success = false; + if (!sender_->Send(new AutomationMsg_EnableExtension(0, handle_, + &success))) + return false; + return success; +} + +bool ExtensionProxy::Disable() { + if (!is_valid()) + return false; + + bool success = false; + if (!sender_->Send(new AutomationMsg_DisableExtension(0, handle_, + &success))) + return false; + return success; +} + +bool ExtensionProxy::ExecuteActionInActiveTabAsync(BrowserProxy* browser) { + if (!is_valid()) + return false; + + bool success = false; + if (!sender_->Send(new AutomationMsg_ExecuteExtensionActionInActiveTabAsync( + 0, handle_, browser->handle(), &success))) + return false; + return success; +} + +bool ExtensionProxy::MoveBrowserAction(int index) { + if (!is_valid()) + return false; + bool success = false; + if (!sender_->Send( + new AutomationMsg_MoveExtensionBrowserAction(0, handle_, index, + &success))) + return false; + return success; +} + +bool ExtensionProxy::GetId(std::string* id) { + DCHECK(id); + return GetProperty(AUTOMATION_MSG_EXTENSION_ID, id); +} + +bool ExtensionProxy::GetName(std::string* name) { + DCHECK(name); + return GetProperty(AUTOMATION_MSG_EXTENSION_NAME, name); +} + +bool ExtensionProxy::GetVersion(std::string* version) { + DCHECK(version); + return GetProperty(AUTOMATION_MSG_EXTENSION_VERSION, version); +} + +bool ExtensionProxy::GetBrowserActionIndex(int* index) { + DCHECK(index); + std::string index_string; + if (!GetProperty(AUTOMATION_MSG_EXTENSION_BROWSER_ACTION_INDEX, + &index_string)) + return false; + // Do not modify |index| until we are sure we can get the value, just to be + // nice to the caller. + int converted_index; + if (!StringToInt(index_string, &converted_index)) { + LOG(ERROR) << "Received index string could not be converted to int: " + << index_string; + return false; + } + *index = converted_index; + return true; +} + +void ExtensionProxy::EnsureIdMatches(const std::string& expected_id) { + std::string id; + ASSERT_TRUE(GetId(&id)); + ASSERT_EQ(expected_id, id); +} + +void ExtensionProxy::EnsureNameMatches(const std::string& expected_name) { + std::string name; + ASSERT_TRUE(GetName(&name)); + ASSERT_EQ(expected_name, name); +} + +void ExtensionProxy::EnsureVersionMatches(const std::string& expected_version) { + std::string version; + ASSERT_TRUE(GetVersion(&version)); + ASSERT_EQ(expected_version, version); +} + +void ExtensionProxy::EnsureBrowserActionIndexMatches(int expected_index) { + int index; + ASSERT_TRUE(GetBrowserActionIndex(&index)); + ASSERT_EQ(expected_index, index); +} + +bool ExtensionProxy::GetProperty(AutomationMsg_ExtensionProperty type, + std::string* value) { + DCHECK(value); + if (!is_valid()) + return false; + + bool success = false; + if (!sender_->Send(new AutomationMsg_GetExtensionProperty(0, handle_, type, + &success, value))) + return false; + return success; +} diff --git a/chrome/test/automation/extension_proxy.h b/chrome/test/automation/extension_proxy.h new file mode 100644 index 0000000..c6ae6dda --- /dev/null +++ b/chrome/test/automation/extension_proxy.h @@ -0,0 +1,88 @@ +// Copyright (c) 2010 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_TEST_AUTOMATION_EXTENSION_PROXY_H_ +#define CHROME_TEST_AUTOMATION_EXTENSION_PROXY_H_ + +#include <string> + +#include "base/compiler_specific.h" +#include "base/weak_ptr.h" +#include "chrome/test/automation/automation_constants.h" +#include "chrome/test/automation/automation_handle_tracker.h" + +class AutomationMessageSender; +class BrowserProxy; + +// This class presents the interface to actions that can be performed on +// a given extension. This refers to a particular version of that extension. +// For example, it refers to Google Translate 1.0. If the extension is +// updated to a newer version, this proxy is invalidated. +class ExtensionProxy : public AutomationResourceProxy { + public: + // Creates an extension proxy referring to an extension id. + ExtensionProxy(AutomationMessageSender* sender, + AutomationHandleTracker* tracker, + int handle); + + // Uninstalls this extension. Returns true on success. + bool Uninstall() WARN_UNUSED_RESULT; + + // Enables this extension. Returns true on success. The extension + // should be disabled when this is called. + bool Enable() WARN_UNUSED_RESULT; + + // Disables this extension. Returns true on success. The extension + // should be enabled when this is called. + bool Disable() WARN_UNUSED_RESULT; + + // Executes the action associated with this extension. This may be a page + // action or a browser action. This is similar to clicking, but does not + // work with popups. Also, for page actions, this will execute the action + // even if the page action is not shown for the active tab. Returns true on + // success. + // TODO(kkania): Add support for popups. + bool ExecuteActionInActiveTabAsync(BrowserProxy* browser) + WARN_UNUSED_RESULT; + + // Moves the browser action from its current location in the browser action + // toolbar to a new |index|. Index should be less than the number of browser + // actions in the toolbar. Returns true on success. + bool MoveBrowserAction(int index) WARN_UNUSED_RESULT; + + // Gets the id of this extension. Returns true on success. + bool GetId(std::string* id) WARN_UNUSED_RESULT; + + // Gets the name of this extension. Returns true on success. + bool GetName(std::string* name) WARN_UNUSED_RESULT; + + // Gets the version string of this extension. Returns true on success. + bool GetVersion(std::string* version) WARN_UNUSED_RESULT; + + // Gets the index (zero-based) of this extension's browser action in + // the browser action toolbar. |index| will be set to -1 if the extension + // does not have a browser action in the toolbar. Returns true on success. + bool GetBrowserActionIndex(int* index) WARN_UNUSED_RESULT; + + // Asserts that |expected_id| matches this extension's id. + void EnsureIdMatches(const std::string& expected_id); + + // Asserts that |expected_name| matches this extension's name. + void EnsureNameMatches(const std::string& expected_name); + + // Asserts that |expected_version| matches this extension's name. + void EnsureVersionMatches(const std::string& expected_version); + + // Asserts that |expected_index| matches the index (zero-based) of this + // extension's browser action in the browser action toolbar. + void EnsureBrowserActionIndexMatches(int expected_index); + + private: + // Gets the string value of the property of type |type|. Returns true on + // success. + bool GetProperty(AutomationMsg_ExtensionProperty type, std::string* value) + WARN_UNUSED_RESULT; +}; + +#endif // CHROME_TEST_AUTOMATION_EXTENSION_PROXY_H_ diff --git a/chrome/test/automation/extension_proxy_uitest.cc b/chrome/test/automation/extension_proxy_uitest.cc new file mode 100644 index 0000000..18d385c --- /dev/null +++ b/chrome/test/automation/extension_proxy_uitest.cc @@ -0,0 +1,178 @@ +// Copyright (c) 2010 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 "base/path_service.h" +#include "base/ref_counted.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/test/automation/automation_proxy.h" +#include "chrome/test/automation/browser_proxy.h" +#include "chrome/test/automation/extension_proxy.h" +#include "chrome/test/automation/tab_proxy.h" +#include "chrome/test/ui/ui_test.h" + +namespace { + +// These tests are not meant to test the extension system itself, but to verify +// the correctness of ExtensionProxy and the AutomationProvider implementation +// behind it. +class ExtensionProxyUITest : public UITest { + public: + ExtensionProxyUITest() {} + + virtual void SetUp() { + UITest::SetUp(); + simple_extension_= InstallSimpleBrowserActionExtension(); + ASSERT_TRUE(simple_extension_.get()); + } + + protected: + // Installs a simple browser action extension from the sample_extensions + // folder. Returns an ExtensionProxy, which could be NULL. + scoped_refptr<ExtensionProxy> InstallSimpleBrowserActionExtension() { + return automation()->InstallExtension( + test_data_directory_.AppendASCII("extensions").AppendASCII("uitest"). + AppendASCII("simple_browser_action.crx")); + } + + // Installs a extension which, when clicking the browser action, renames + // the current tab to the tab's index. Returns an ExtensionProxy, + // which could be NULL. + scoped_refptr<ExtensionProxy> InstallRenameTabExtension() { + return automation()->InstallExtension( + test_data_directory_.AppendASCII("extensions").AppendASCII("uitest"). + AppendASCII("rename_tab.crx")); + } + + // The google translate extension, which is installed on test setup. + scoped_refptr<ExtensionProxy> simple_extension_; + + private: + DISALLOW_COPY_AND_ASSIGN(ExtensionProxyUITest); +}; + +TEST_F(ExtensionProxyUITest, NoSuchExtension) { + ASSERT_TRUE(simple_extension_->Uninstall()); + + // A proxy referring to an uninstalled extension should return false for all + // calls without actually invoking the extension system. + ASSERT_FALSE(simple_extension_->Uninstall()); + ASSERT_FALSE(simple_extension_->Enable()); + ASSERT_FALSE(simple_extension_->Disable()); + scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0); + ASSERT_TRUE(browser.get()); + ASSERT_FALSE(simple_extension_-> + ExecuteActionInActiveTabAsync(browser.get())); + ASSERT_FALSE(simple_extension_->MoveBrowserAction(0)); + std::string name, version; + int index; + ASSERT_FALSE(simple_extension_->GetName(&name)); + ASSERT_FALSE(simple_extension_->GetVersion(&version)); + ASSERT_FALSE(simple_extension_->GetBrowserActionIndex(&index)); +} + +TEST_F(ExtensionProxyUITest, EnableDisable) { + ASSERT_TRUE(simple_extension_->Disable()); + ASSERT_TRUE(simple_extension_->Enable()); + ASSERT_TRUE(simple_extension_->Disable()); +} + +TEST_F(ExtensionProxyUITest, Uninstall) { + ASSERT_TRUE(simple_extension_->Uninstall()); + + // Uninstall a disabled extension. + simple_extension_ = InstallSimpleBrowserActionExtension(); + ASSERT_TRUE(simple_extension_.get()); + ASSERT_TRUE(simple_extension_->Disable()); + ASSERT_TRUE(simple_extension_->Uninstall()); + + // Uninstall a just enabled extension. + simple_extension_ = InstallSimpleBrowserActionExtension(); + ASSERT_TRUE(simple_extension_.get()); + ASSERT_TRUE(simple_extension_->Disable()); + ASSERT_TRUE(simple_extension_->Enable()); + ASSERT_TRUE(simple_extension_->Uninstall()); +} + +TEST_F(ExtensionProxyUITest, ExecuteBrowserActionInActiveTabAsync) { + scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0); + ASSERT_TRUE(browser.get()); + scoped_refptr<ExtensionProxy> rename_tab_extension = + InstallRenameTabExtension(); + ASSERT_TRUE(rename_tab_extension.get()); + + // Need to use http in order for the extension to be able to inject + // javascript into the page. Extensions do not have permissions for + // chrome://* urls. + FilePath path; + // The root directory for the http server does not matter in this case, + // but we have to pick something. + PathService::Get(chrome::DIR_TEST_DATA, &path); + StartHttpServerWithPort(path, L"1365"); + GURL localhost = GURL("http://localhost:1365"); + NavigateToURL(localhost); + + // Click the browser action, which should rename the tab title to + // the tab's index. + ASSERT_TRUE(rename_tab_extension-> + ExecuteActionInActiveTabAsync(browser.get())); + ASSERT_NO_FATAL_FAILURE(automation()->EnsureExtensionTestResult()); + + scoped_refptr<TabProxy> display_tab = browser->GetTab(0); + ASSERT_TRUE(display_tab); + std::wstring title_wstring; + ASSERT_TRUE(display_tab->GetTabTitle(&title_wstring)); + ASSERT_STREQ(L"0", title_wstring.c_str()); + + // Click the action again right after navigating to a new page. + ASSERT_TRUE(browser->AppendTab(localhost)); + display_tab = browser->GetTab(1); + ASSERT_TRUE(display_tab); + ASSERT_TRUE(rename_tab_extension-> + ExecuteActionInActiveTabAsync(browser.get())); + ASSERT_NO_FATAL_FAILURE(automation()->EnsureExtensionTestResult()); + ASSERT_TRUE(display_tab->GetTabTitle(&title_wstring)); + ASSERT_STREQ(L"1", title_wstring.c_str()); + + // Do not forget to stop the server. + StopHttpServer(); +} + +TEST_F(ExtensionProxyUITest, MoveBrowserAction) { + scoped_refptr<ExtensionProxy> rename_tab_extension = + InstallRenameTabExtension(); + ASSERT_TRUE(rename_tab_extension.get()); + ASSERT_NO_FATAL_FAILURE(simple_extension_-> + EnsureBrowserActionIndexMatches(0)); + ASSERT_NO_FATAL_FAILURE(rename_tab_extension-> + EnsureBrowserActionIndexMatches(1)); + + // Move google translate to the end, then beginning, and verify. + ASSERT_TRUE(simple_extension_->MoveBrowserAction(1)); + ASSERT_NO_FATAL_FAILURE(simple_extension_-> + EnsureBrowserActionIndexMatches(1)); + ASSERT_NO_FATAL_FAILURE(rename_tab_extension-> + EnsureBrowserActionIndexMatches(0)); + ASSERT_TRUE(simple_extension_->MoveBrowserAction(0)); + ASSERT_NO_FATAL_FAILURE(simple_extension_-> + EnsureBrowserActionIndexMatches(0)); + ASSERT_NO_FATAL_FAILURE(rename_tab_extension-> + EnsureBrowserActionIndexMatches(1)); + + // Try moving browser action to invalid index. + ASSERT_FALSE(simple_extension_->MoveBrowserAction(-1)); + ASSERT_FALSE(simple_extension_->MoveBrowserAction(2)); +} + +TEST_F(ExtensionProxyUITest, GetProperty) { + ASSERT_NO_FATAL_FAILURE(simple_extension_-> + EnsureIdMatches("aiglobglfckejlcpcbdokbkbjeemfhno")); + ASSERT_NO_FATAL_FAILURE(simple_extension_-> + EnsureNameMatches("Browser Action")); + ASSERT_NO_FATAL_FAILURE(simple_extension_-> + EnsureVersionMatches("0.1.1")); + ASSERT_NO_FATAL_FAILURE(simple_extension_-> + EnsureBrowserActionIndexMatches(0)); +} + +} // namespace |