summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjnd@google.com <jnd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-19 01:48:16 +0000
committerjnd@google.com <jnd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-19 01:48:16 +0000
commit97fa6ce336fe635fc0ac06ebefe925d1bc235897 (patch)
treee8797c5e25c209305a8d864a9f17744486626cce /chrome
parent0844615584c64925c47141d519942655b04b52eb (diff)
downloadchromium_src-97fa6ce336fe635fc0ac06ebefe925d1bc235897.zip
chromium_src-97fa6ce336fe635fc0ac06ebefe925d1bc235897.tar.gz
chromium_src-97fa6ce336fe635fc0ac06ebefe925d1bc235897.tar.bz2
We need to add UI test for "Encoding" menu to avoid regression.
For this purpose, I have created several methods in automation API. They can be used for the above UI tests. 1 get the current used encoding name of the page in the specified tab. 2 get value of the encoding auto detection option. 3 enables and disable the encoding auto detection. 4 use the specified encoding to override the encoding of the page in the specified tab. BUG=5515 The corresponding UI test is coming soon Review URL: http://codereview.chromium.org/14162 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7286 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_provider.cc99
-rw-r--r--chrome/browser/automation/automation_provider.h28
-rw-r--r--chrome/browser/character_encoding.cc35
-rw-r--r--chrome/browser/character_encoding.h5
-rw-r--r--chrome/test/automation/automation_messages_internal.h50
-rw-r--r--chrome/test/automation/browser_proxy.cc66
-rw-r--r--chrome/test/automation/browser_proxy.h9
-rw-r--r--chrome/test/automation/tab_proxy.cc41
-rw-r--r--chrome/test/automation/tab_proxy.h6
9 files changed, 312 insertions, 27 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 3a36b52..ff96f55f0 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/automation/url_request_mock_http_job.h"
#include "chrome/browser/automation/url_request_slow_download_job.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/character_encoding.h"
#include "chrome/browser/dom_operation_notification_details.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/save_package.h"
@@ -815,6 +816,16 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
GetShowingAppModalDialog)
IPC_MESSAGE_HANDLER(AutomationMsg_ClickAppModalDialogButtonRequest,
ClickAppModalDialogButton)
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetStringPreferenceRequest,
+ SetStringPreference)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetBooleanPreferenceRequest,
+ GetBooleanPreference)
+ IPC_MESSAGE_HANDLER(AutomationMsg_SetBooleanPreferenceRequest,
+ SetBooleanPreference)
+ IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncodingRequest,
+ GetPageCurrentEncoding)
+ IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncodingRequest,
+ OverrideEncoding)
IPC_END_MESSAGE_MAP()
}
@@ -2476,7 +2487,7 @@ void AutomationProvider::WaitForNavigation(const IPC::Message& message,
void AutomationProvider::SetIntPreference(const IPC::Message& message,
int handle,
- std::wstring name,
+ const std::wstring& name,
int value) {
bool success = false;
if (browser_tracker_->ContainsHandle(handle)) {
@@ -2487,3 +2498,89 @@ void AutomationProvider::SetIntPreference(const IPC::Message& message,
Send(new AutomationMsg_SetIntPreferenceResponse(message.routing_id(),
success));
}
+
+void AutomationProvider::SetStringPreference(const IPC::Message& message,
+ int handle,
+ const std::wstring& name,
+ const std::wstring& value) {
+ bool success = false;
+ if (browser_tracker_->ContainsHandle(handle)) {
+ Browser* browser = browser_tracker_->GetResource(handle);
+ browser->profile()->GetPrefs()->SetString(name.c_str(), value);
+ success = true;
+ }
+ Send(new AutomationMsg_SetStringPreferenceResponse(message.routing_id(),
+ success));
+}
+
+void AutomationProvider::GetBooleanPreference(const IPC::Message& message,
+ int handle,
+ const std::wstring& name) {
+ bool success = false;
+ bool value = false;
+ if (browser_tracker_->ContainsHandle(handle)) {
+ Browser* browser = browser_tracker_->GetResource(handle);
+ value = browser->profile()->GetPrefs()->GetBoolean(name.c_str());
+ success = true;
+ }
+ Send(new AutomationMsg_GetBooleanPreferenceResponse(message.routing_id(),
+ success, value));
+}
+
+void AutomationProvider::SetBooleanPreference(const IPC::Message& message,
+ int handle,
+ const std::wstring& name,
+ bool value) {
+ bool success = false;
+ if (browser_tracker_->ContainsHandle(handle)) {
+ Browser* browser = browser_tracker_->GetResource(handle);
+ browser->profile()->GetPrefs()->SetBoolean(name.c_str(), value);
+ success = true;
+ }
+ Send(new AutomationMsg_SetBooleanPreferenceResponse(message.routing_id(),
+ success));
+}
+
+// Gets the current used encoding name of the page in the specified tab.
+void AutomationProvider::GetPageCurrentEncoding(const IPC::Message& message,
+ int tab_handle) {
+ std::wstring current_encoding;
+ if (tab_tracker_->ContainsHandle(tab_handle)) {
+ NavigationController* nav = tab_tracker_->GetResource(tab_handle);
+ Browser* browser = FindAndActivateTab(nav);
+ DCHECK(browser);
+
+ if (browser->IsCommandEnabled(IDC_ENCODING_MENU)) {
+ TabContents* tab_contents = nav->active_contents();
+ DCHECK(tab_contents->type() == TAB_CONTENTS_WEB);
+ current_encoding = tab_contents->AsWebContents()->encoding();
+ }
+ }
+ Send(new AutomationMsg_GetPageCurrentEncodingResponse(message.routing_id(),
+ current_encoding));
+}
+
+// Gets the current used encoding name of the page in the specified tab.
+void AutomationProvider::OverrideEncoding(const IPC::Message& message,
+ int tab_handle,
+ const std::wstring& encoding_name) {
+ bool succeed = false;
+ if (tab_tracker_->ContainsHandle(tab_handle)) {
+ NavigationController* nav = tab_tracker_->GetResource(tab_handle);
+ Browser* browser = FindAndActivateTab(nav);
+ DCHECK(browser);
+
+ if (browser->IsCommandEnabled(IDC_ENCODING_MENU)) {
+ TabContents* tab_contents = nav->active_contents();
+ DCHECK(tab_contents->type() == TAB_CONTENTS_WEB);
+ int selected_encoding_id =
+ CharacterEncoding::GetCommandIdByCanonicalEncodingName(encoding_name);
+ if (selected_encoding_id) {
+ browser->OverrideEncoding(selected_encoding_id);
+ succeed = true;
+ }
+ }
+ }
+ Send(new AutomationMsg_OverrideEncodingResponse(message.routing_id(),
+ succeed));
+}
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index b0e21d3..f539841 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -330,9 +330,35 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
// Sets the int value for preference with name |name|.
void SetIntPreference(const IPC::Message& message,
int handle,
- std::wstring name,
+ const std::wstring& name,
int value);
+ // Sets the string value for preference with name |name|.
+ void SetStringPreference(const IPC::Message& message,
+ int handle,
+ const std::wstring& name,
+ const std::wstring& value);
+
+ // Gets the bool value for preference with name |name|.
+ void GetBooleanPreference(const IPC::Message& message,
+ int handle,
+ const std::wstring& name);
+
+ // Sets the bool value for preference with name |name|.
+ void SetBooleanPreference(const IPC::Message& message,
+ int handle,
+ const std::wstring& name,
+ bool value);
+
+ // Gets the current used encoding name of the page in the specified tab.
+ void GetPageCurrentEncoding(const IPC::Message& message, int tab_handle);
+
+ // Uses the specified encoding to override the encoding of the page in the
+ // specified tab.
+ void OverrideEncoding(const IPC::Message& message,
+ int tab_handle,
+ const std::wstring& encoding_name);
+
// Convert a tab handle into a WebContents. If |tab| is non-NULL a pointer
// to the tab is also returned. Returns NULL in case of failure or if the tab
// is not of the WebContents type.
diff --git a/chrome/browser/character_encoding.cc b/chrome/browser/character_encoding.cc
index 4bb9575..7144ca0 100644
--- a/chrome/browser/character_encoding.cc
+++ b/chrome/browser/character_encoding.cc
@@ -129,23 +129,6 @@ const CanonicalEncodingNameToIdMapType* CanonicalEncodingMap::GetCanonicalEncodi
// encoding names.
static CanonicalEncodingMap canonical_encoding_name_map_singleton;
-// Static.
-// Get encoding command id according to input encoding name. If the name is
-// valid, return corresponding encoding command id. Otherwise return 0;
-static int GetCommandIdByCanonicalEncodingName(
- const std::wstring& encoding_name) {
- const CanonicalEncodingNameToIdMapType* map =
- canonical_encoding_name_map_singleton.
- GetCanonicalEncodingNameToIdMapData();
- DCHECK(map);
-
- CanonicalEncodingNameToIdMapType::const_iterator found_id =
- map->find(encoding_name);
- if (found_id != map->end())
- return found_id->second;
- return 0;
-}
-
const int default_encoding_menus[] = {
IDC_ENCODING_UTF16LE,
0,
@@ -204,7 +187,8 @@ static void ParseEncodingListSeparatedWithComma(
size_t maximum_size) {
WStringTokenizer tokenizer(encoding_list, L",");
while (tokenizer.GetNext()) {
- int id = GetCommandIdByCanonicalEncodingName(tokenizer.token());
+ int id = CharacterEncoding::GetCommandIdByCanonicalEncodingName(
+ tokenizer.token());
// Ignore invalid encoding.
if (!id)
continue;
@@ -230,6 +214,21 @@ std::wstring GetEncodingDisplayName(std::wstring encoding_name,
} // namespace
// Static.
+int CharacterEncoding::GetCommandIdByCanonicalEncodingName(
+ const std::wstring& encoding_name) {
+ const CanonicalEncodingNameToIdMapType* map =
+ canonical_encoding_name_map_singleton.
+ GetCanonicalEncodingNameToIdMapData();
+ DCHECK(map);
+
+ CanonicalEncodingNameToIdMapType::const_iterator found_id =
+ map->find(encoding_name);
+ if (found_id != map->end())
+ return found_id->second;
+ return 0;
+}
+
+// Static.
std::wstring CharacterEncoding::GetCanonicalEncodingNameByCommandId(int id) {
const IdToCanonicalEncodingNameMapType* map =
canonical_encoding_name_map_singleton.
diff --git a/chrome/browser/character_encoding.h b/chrome/browser/character_encoding.h
index 1830edc..6ef1b05 100644
--- a/chrome/browser/character_encoding.h
+++ b/chrome/browser/character_encoding.h
@@ -70,6 +70,11 @@ class CharacterEncoding {
int new_selected_encoding_id,
std::wstring* selected_encodings);
+ // Get encoding command id according to input encoding name. If the name is
+ // valid, return corresponding encoding command id. Otherwise return 0;
+ static int GetCommandIdByCanonicalEncodingName(
+ const std::wstring& encoding_name);
+
private:
// Disallow instantiating it since this class only contains static methods.
DISALLOW_IMPLICIT_CONSTRUCTORS(CharacterEncoding);
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h
index 165b606..47bb11a 100644
--- a/chrome/test/automation/automation_messages_internal.h
+++ b/chrome/test/automation/automation_messages_internal.h
@@ -600,7 +600,8 @@ IPC_BEGIN_MESSAGES(Automation, 0)
IPC_MESSAGE_ROUTED2(AutomationMsg_ActionOnSSLBlockingPage, int, bool)
IPC_MESSAGE_ROUTED1(AutomationMsg_ActionOnSSLBlockingPageResponse, bool)
- // Message to request that a browser window is brought to the front and activated.
+ // Message to request that a browser window is brought to the front and
+ // activated.
// Request:
// - int: handle of the browser window.
// Response:
@@ -608,8 +609,8 @@ IPC_BEGIN_MESSAGES(Automation, 0)
IPC_MESSAGE_ROUTED1(AutomationMsg_BringBrowserToFront, int)
IPC_MESSAGE_ROUTED1(AutomationMsg_BringBrowserToFrontResponse, bool)
- // Message to request whether a certain item is enabled of disabled in the "Page"
- // menu in the browser window
+ // Message to request whether a certain item is enabled of disabled in the
+ // "Page" menu in the browser window
//
// Request:
// - int: handle of the browser window.
@@ -641,8 +642,8 @@ IPC_BEGIN_MESSAGES(Automation, 0)
IPC_MESSAGE_ROUTED1(AutomationMsg_LastActiveBrowserWindowResponse, int)
// This message requests the bounds of a constrained window (relative to its
- // containing TabContents). On an internal error, the boolean in the result will
- // be set to false.
+ // containing TabContents). On an internal error, the boolean in the result
+ // will be set to false.
IPC_MESSAGE_ROUTED1(AutomationMsg_ConstrainedWindowBoundsRequest,
int /* tab_handle */)
IPC_MESSAGE_ROUTED2(AutomationMsg_ConstrainedWindowBoundsResponse,
@@ -821,4 +822,43 @@ IPC_BEGIN_MESSAGES(Automation, 0)
IPC_MESSAGE_ROUTED1(AutomationMsg_ClickAppModalDialogButtonResponse,
bool /* success */)
+ // This messages sets a string-value preference.
+ IPC_MESSAGE_ROUTED3(AutomationMsg_SetStringPreferenceRequest,
+ int /* browser handle */,
+ std::wstring /* pref name */,
+ std::wstring /* pref value */)
+ IPC_MESSAGE_ROUTED1(AutomationMsg_SetStringPreferenceResponse,
+ bool /* success */)
+
+ // This messages gets a boolean-value preference.
+ IPC_MESSAGE_ROUTED2(AutomationMsg_GetBooleanPreferenceRequest,
+ int /* browser handle */,
+ std::wstring /* pref name */)
+ IPC_MESSAGE_ROUTED2(AutomationMsg_GetBooleanPreferenceResponse,
+ bool /* success */,
+ bool /* pref value */)
+
+ // This messages sets a boolean-value preference.
+ IPC_MESSAGE_ROUTED3(AutomationMsg_SetBooleanPreferenceRequest,
+ int /* browser handle */,
+ std::wstring /* pref name */,
+ bool /* pref value */)
+ IPC_MESSAGE_ROUTED1(AutomationMsg_SetBooleanPreferenceResponse,
+ bool /* success */)
+
+ // Queries the current used encoding name of the page in the specified
+ // web content tab.
+ IPC_MESSAGE_ROUTED1(AutomationMsg_GetPageCurrentEncodingRequest,
+ int /* tab handle */)
+ IPC_MESSAGE_ROUTED1(AutomationMsg_GetPageCurrentEncodingResponse,
+ std::wstring /* current used encoding name */)
+
+ // Uses the specified encoding to override the encoding of the page in the
+ // specified web content tab.
+ IPC_MESSAGE_ROUTED2(AutomationMsg_OverrideEncodingRequest,
+ int /* tab handle */,
+ std::wstring /* overrided encoding name */)
+ IPC_MESSAGE_ROUTED1(AutomationMsg_OverrideEncodingResponse,
+ bool /* success */)
+
IPC_END_MESSAGES(Automation)
diff --git a/chrome/test/automation/browser_proxy.cc b/chrome/test/automation/browser_proxy.cc
index faead8f..cab64bf 100644
--- a/chrome/test/automation/browser_proxy.cc
+++ b/chrome/test/automation/browser_proxy.cc
@@ -412,4 +412,68 @@ bool BrowserProxy::SetIntPreference(const std::wstring& name, int value) {
// We failed to deserialize the returned value.
return false;
-} \ No newline at end of file
+}
+
+bool BrowserProxy::SetStringPreference(const std::wstring& name,
+ const std::wstring& value) {
+ if (!is_valid())
+ return false;
+
+ IPC::Message* response = NULL;
+ bool success = sender_->SendAndWaitForResponse(
+ new AutomationMsg_SetStringPreferenceRequest(0, handle_, name , value),
+ &response, AutomationMsg_SetStringPreferenceResponse::ID);
+
+ scoped_ptr<IPC::Message> response_deleter(response); // Delete on return.
+ if (!success)
+ return false;
+
+ if (AutomationMsg_SetStringPreferenceResponse::Read(response, &success))
+ return success;
+
+ return false;
+}
+
+bool BrowserProxy::GetBooleanPreference(const std::wstring& name,
+ bool* value) {
+ if (!is_valid())
+ return false;
+
+ IPC::Message* response = NULL;
+ bool success = sender_->SendAndWaitForResponse(
+ new AutomationMsg_GetBooleanPreferenceRequest(0, handle_, name),
+ &response, AutomationMsg_GetBooleanPreferenceResponse::ID);
+
+ scoped_ptr<IPC::Message> response_deleter(response); // Delete on return.
+ if (!success)
+ return false;
+
+ void* iter = NULL;
+ bool successed_get_value;
+ success = response->ReadBool(&iter, &successed_get_value);
+ if (!success || !successed_get_value)
+ return false;
+ DCHECK(iter);
+ success = response->ReadBool(&iter, value);
+ return success;
+}
+
+bool BrowserProxy::SetBooleanPreference(const std::wstring& name,
+ bool value) {
+ if (!is_valid())
+ return false;
+
+ IPC::Message* response = NULL;
+ bool success = sender_->SendAndWaitForResponse(
+ new AutomationMsg_SetBooleanPreferenceRequest(0, handle_, name , value),
+ &response, AutomationMsg_SetBooleanPreferenceResponse::ID);
+
+ scoped_ptr<IPC::Message> response_deleter(response); // Delete on return.
+ if (!success)
+ return false;
+
+ if (AutomationMsg_SetBooleanPreferenceResponse::Read(response, &success))
+ return success;
+
+ return false;
+}
diff --git a/chrome/test/automation/browser_proxy.h b/chrome/test/automation/browser_proxy.h
index 3cc681e..c67dd33 100644
--- a/chrome/test/automation/browser_proxy.h
+++ b/chrome/test/automation/browser_proxy.h
@@ -149,6 +149,15 @@ class BrowserProxy : public AutomationResourceProxy {
// Sets the int value of the specified preference.
bool SetIntPreference(const std::wstring& name, int value);
+ // Sets the string value of the specified preference.
+ bool SetStringPreference(const std::wstring& name, const std::wstring& value);
+
+ // Gets the boolean value of the specified preference.
+ bool GetBooleanPreference(const std::wstring& name, bool* value);
+
+ // Sets the boolean value of the specified preference.
+ bool SetBooleanPreference(const std::wstring& name, bool value);
+
private:
DISALLOW_COPY_AND_ASSIGN(BrowserProxy);
};
diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc
index a63e08a..f17a35de 100644
--- a/chrome/test/automation/tab_proxy.cc
+++ b/chrome/test/automation/tab_proxy.cc
@@ -1046,4 +1046,43 @@ bool TabProxy::WaitForNavigation(int64 last_navigation_time) {
void* iter = NULL;
response->ReadBool(&iter, &success);
return success;
-} \ No newline at end of file
+}
+
+bool TabProxy::GetPageCurrentEncoding(std::wstring* encoding) {
+ if (!is_valid())
+ return false;
+
+ IPC::Message* response;
+ bool succeeded = sender_->SendAndWaitForResponse(
+ new AutomationMsg_GetPageCurrentEncodingRequest(0, handle_),
+ &response,
+ AutomationMsg_GetPageCurrentEncodingResponse::ID);
+
+ scoped_ptr<IPC::Message> response_deleter(response); // Delete on return.
+ if (!succeeded)
+ return false;
+
+ void* iter = NULL;
+ succeeded = response->ReadWString(&iter, encoding);
+ return succeeded;
+}
+
+bool TabProxy::OverrideEncoding(const std::wstring& encoding) {
+ if (!is_valid())
+ return false;
+
+ IPC::Message* response;
+ bool succeeded = sender_->SendAndWaitForResponse(
+ new AutomationMsg_OverrideEncodingRequest(0, handle_, encoding),
+ &response,
+ AutomationMsg_OverrideEncodingResponse::ID);
+
+ scoped_ptr<IPC::Message> response_deleter(response); // Delete on return.
+ if (!succeeded)
+ return false;
+
+ void* iter = NULL;
+ bool successed_set_value = false;
+ succeeded = response->ReadBool(&iter, &successed_set_value);
+ return succeeded && successed_set_value;
+}
diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h
index 15d72c2..eec9119 100644
--- a/chrome/test/automation/tab_proxy.h
+++ b/chrome/test/automation/tab_proxy.h
@@ -277,6 +277,12 @@ class TabProxy : public AutomationResourceProxy {
// tab_proxy->WaitForNavigation(last_nav_time);
bool WaitForNavigation(int64 last_navigation_time);
+ // Gets the current used encoding of the page in the tab.
+ bool GetPageCurrentEncoding(std::wstring* encoding);
+
+ // Uses the specified encoding to override encoding of the page in the tab.
+ bool OverrideEncoding(const std::wstring& encoding);
+
private:
DISALLOW_COPY_AND_ASSIGN(TabProxy);
};