summaryrefslogtreecommitdiffstats
path: root/chrome/browser
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/browser
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/browser')
-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
4 files changed, 147 insertions, 20 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);