summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorrolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-09 04:33:11 +0000
committerrolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-09 04:33:11 +0000
commit7e6ecaaf0315c518b6223607d1684255c3d8c7a8 (patch)
tree33ecb333c979e74d7160abcb446781c1f0c7782d /chrome
parent72019a142cb65deac06491e779383e3f28118a8e (diff)
downloadchromium_src-7e6ecaaf0315c518b6223607d1684255c3d8c7a8.zip
chromium_src-7e6ecaaf0315c518b6223607d1684255c3d8c7a8.tar.gz
chromium_src-7e6ecaaf0315c518b6223607d1684255c3d8c7a8.tar.bz2
Commit Issue 255057: Unit Test for Toggling of Encoding Auto-Detect
BUG=23617 TEST=BrowserEncodingTest.TestToggleAutoDetect git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31419 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/automation_provider.cc31
-rw-r--r--chrome/browser/automation/automation_provider.h8
-rw-r--r--chrome/browser/browser_encoding_uitest.cc91
-rw-r--r--chrome/test/automation/automation_messages_internal.h9
-rw-r--r--chrome/test/automation/tab_proxy.cc11
-rw-r--r--chrome/test/automation/tab_proxy.h9
6 files changed, 147 insertions, 12 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 8df4ae4..e7984bc 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -417,6 +417,8 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) {
SetBooleanPreference)
IPC_MESSAGE_HANDLER(AutomationMsg_GetPageCurrentEncoding,
GetPageCurrentEncoding)
+ IPC_MESSAGE_HANDLER(AutomationMsg_ToggleEncodingAutoDetect,
+ ToggleEncodingAutoDetect)
IPC_MESSAGE_HANDLER(AutomationMsg_OverrideEncoding, OverrideEncoding)
IPC_MESSAGE_HANDLER(AutomationMsg_SavePackageShouldPromptUser,
SavePackageShouldPromptUser)
@@ -1890,8 +1892,8 @@ void AutomationProvider::SetStringPreference(int handle,
void AutomationProvider::GetBooleanPreference(int handle,
const std::wstring& name,
- bool* success,
- bool* value) {
+ bool* value,
+ bool* success) {
*success = false;
*value = false;
if (browser_tracker_->ContainsHandle(handle)) {
@@ -1926,7 +1928,30 @@ void AutomationProvider::GetPageCurrentEncoding(
}
}
-// Gets the current used encoding name of the page in the specified tab.
+// Toggles the encoding auto-detect setting.
+// While the setting is global, the tab needs to be specified as it may need
+// to be reloaded.
+void AutomationProvider::ToggleEncodingAutoDetect(int tab_handle,
+ bool* success) {
+ *success = false;
+#if defined(OS_WIN)
+ if (tab_tracker_->ContainsHandle(tab_handle)) {
+ NavigationController* nav = tab_tracker_->GetResource(tab_handle);
+ Browser* browser = FindAndActivateTab(nav);
+ DCHECK(browser);
+
+ if (browser->command_updater()->IsCommandEnabled(IDC_ENCODING_MENU)) {
+ browser->ToggleEncodingAutoDetect();
+ *success = true;
+ }
+ }
+#else
+ // TODO(port): Enable when encoding-related parts of Browser are ported.
+ NOTIMPLEMENTED();
+#endif
+}
+
+// Sets the override encoding for the page in the specified tab.
void AutomationProvider::OverrideEncoding(int tab_handle,
const std::string& encoding_name,
bool* success) {
diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h
index 66e7de8..6a66bd7 100644
--- a/chrome/browser/automation/automation_provider.h
+++ b/chrome/browser/automation/automation_provider.h
@@ -447,8 +447,8 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
// Gets the bool value for preference with name |name|.
void GetBooleanPreference(int handle,
const std::wstring& name,
- bool* success,
- bool* value);
+ bool* value,
+ bool* success);
// Sets the bool value for preference with name |name|.
void SetBooleanPreference(int handle,
@@ -459,6 +459,10 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>,
// Gets the current used encoding name of the page in the specified tab.
void GetPageCurrentEncoding(int tab_handle, std::string* current_encoding);
+ // Toggles the encoding auto-detect setting on the given tab
+ void ToggleEncodingAutoDetect(int tab_handle,
+ bool* success);
+
// Uses the specified encoding to override the encoding of the page in the
// specified tab.
void OverrideEncoding(int tab_handle,
diff --git a/chrome/browser/browser_encoding_uitest.cc b/chrome/browser/browser_encoding_uitest.cc
index 8d68314..41b7ba8 100644
--- a/chrome/browser/browser_encoding_uitest.cc
+++ b/chrome/browser/browser_encoding_uitest.cc
@@ -112,8 +112,9 @@ TEST_F(BrowserEncodingTest, TestEncodingAliasMapping) {
}
#if defined(OS_WIN)
-// We are disabling this test on MacOS and Linux because on those platforms
-// AutomationProvider::OverrideEncoding is not implemented yet.
+// We are disabling these tests on MacOS and Linux because on those platforms
+// AutomationProvider::OverrideEncoding and ToggleEncodingAutoDetect are not
+// implemented yet.
// TODO(port): Enable when encoding-related parts of Browser are ported.
TEST_F(BrowserEncodingTest, TestOverrideEncoding) {
const char* const kTestFileName = "gb18030_with_iso88591_meta.html";
@@ -159,6 +160,92 @@ TEST_F(BrowserEncodingTest, TestOverrideEncoding) {
expected_file_name = expected_file_name.AppendASCII(kExpectedFileName);
CheckFile(full_file_name, expected_file_name, true);
}
+
+// Test for fix to issue 2932 (http://crbug.com/2932)
+// as described in http://codereview.chromium.org/173265
+TEST_F(BrowserEncodingTest, TestToggleAutoDetect) {
+ const char* const kTestFileName = "gb18030_with_no_encoding_specified.html";
+ const char* const kToggleTestDir = "auto_detect";
+
+ scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+
+ browser->SetStringPreference(prefs::kDefaultCharset, L"ISO-8859-1");
+
+ // Turn off auto-detect before loading the file.
+ EXPECT_TRUE(
+ browser->SetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
+ false));
+
+ FilePath test_dir_path = FilePath(kTestDir).AppendASCII(kToggleTestDir);
+ test_dir_path = test_dir_path.AppendASCII(kTestFileName);
+ GURL url = URLRequestMockHTTPJob::GetMockUrl(test_dir_path);
+ scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
+ ASSERT_TRUE(tab_proxy.get());
+ ASSERT_TRUE(tab_proxy->NavigateToURL(url));
+ WaitUntilTabCount(1);
+
+ // Verify that file got default encoding.
+ std::string encoding;
+ EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
+ EXPECT_EQ(encoding, "ISO-8859-1");
+
+ // Turn on auto-detect and verify that encoding changed.
+ int64 prev_nav_time = 0;
+ bool encoding_auto_detect = false;
+ EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&prev_nav_time));
+ EXPECT_TRUE(tab_proxy->ToggleEncodingAutoDetect());
+ EXPECT_TRUE(tab_proxy->WaitForNavigation(prev_nav_time));
+ EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
+ EXPECT_EQ(encoding, "gb18030");
+ EXPECT_TRUE(
+ browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
+ &encoding_auto_detect));
+ EXPECT_TRUE(encoding_auto_detect);
+
+ // Turn off auto-detect and verify that no navigation occurs.
+ // The encoding shouldn't change as well.
+ int64 last_nav_time = 0;
+ EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&prev_nav_time));
+ EXPECT_TRUE(tab_proxy->ToggleEncodingAutoDetect());
+ // TODO(rolandsteiner): HACK! this assumes the navigation (if any) will be
+ // completed in 500ms. Need a better way to ascertain that NO navigation
+ // was triggered.
+ EXPECT_TRUE(CrashAwareSleep(500));
+ EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&last_nav_time));
+ EXPECT_EQ(prev_nav_time, last_nav_time);
+ EXPECT_TRUE(
+ browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
+ &encoding_auto_detect));
+ EXPECT_FALSE(encoding_auto_detect);
+
+ // Choose another encoding and verify that page is reloaded and the new
+ // encoding set. Auto-detect encoding should still be off.
+ EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&prev_nav_time));
+ EXPECT_TRUE(tab_proxy->OverrideEncoding("ISO-8859-13"));
+ EXPECT_TRUE(tab_proxy->WaitForNavigation(prev_nav_time));
+ EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
+ EXPECT_EQ(encoding, "ISO-8859-13");
+ EXPECT_TRUE(
+ browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
+ &encoding_auto_detect));
+ EXPECT_FALSE(encoding_auto_detect);
+
+ // Turn on auto-detect again and verify that encoding changed back
+ // to Chinese.
+ EXPECT_TRUE(tab_proxy->GetLastNavigationTime(&prev_nav_time));
+ EXPECT_TRUE(tab_proxy->ToggleEncodingAutoDetect());
+ EXPECT_TRUE(tab_proxy->WaitForNavigation(prev_nav_time));
+ EXPECT_TRUE(tab_proxy->GetPageCurrentEncoding(&encoding));
+ EXPECT_EQ(encoding, "gb18030");
+ EXPECT_TRUE(
+ browser->GetBooleanPreference(prefs::kWebKitUsesUniversalDetector,
+ &encoding_auto_detect));
+ EXPECT_TRUE(encoding_auto_detect);
+
+ // Close the tab explicitely (avoids spurious "leak" crash on exit)
+ EXPECT_TRUE(tab_proxy->Close(true));
+}
#endif // defined(OS_WIN)
// The following encodings are excluded from the auto-detection test because
diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h
index d2f7458..db102a7 100644
--- a/chrome/test/automation/automation_messages_internal.h
+++ b/chrome/test/automation/automation_messages_internal.h
@@ -797,7 +797,7 @@ IPC_BEGIN_MESSAGES(Automation)
int64 /* last navigation time */)
// This messages is used to block until a new navigation occurs (if there is
- // none more recent then the time specified).
+ // none more recent than the time specified).
IPC_SYNC_MESSAGE_ROUTED2_1(AutomationMsg_WaitForNavigation,
int /* tab_handle */,
int64 /* last navigation time */,
@@ -1184,4 +1184,11 @@ IPC_BEGIN_MESSAGES(Automation)
int /* tab_handle */,
int /* request_id */)
+ // Toggles the auto-detect encoding setting.
+ // While the setting is global, the tab needs to be specified as it may need
+ // to be reloaded.
+ IPC_SYNC_MESSAGE_ROUTED1_1(AutomationMsg_ToggleEncodingAutoDetect,
+ int /* tab handle */,
+ bool /* success */)
+
IPC_END_MESSAGES(Automation)
diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc
index 43246ea..875bc3a 100644
--- a/chrome/test/automation/tab_proxy.cc
+++ b/chrome/test/automation/tab_proxy.cc
@@ -664,6 +664,16 @@ bool TabProxy::GetPageCurrentEncoding(std::string* encoding) {
return succeeded;
}
+bool TabProxy::ToggleEncodingAutoDetect() {
+ if (!is_valid())
+ return false;
+
+ bool succeeded = false;
+ sender_->Send(new AutomationMsg_ToggleEncodingAutoDetect(0, handle_,
+ &succeeded));
+ return succeeded;
+}
+
bool TabProxy::OverrideEncoding(const std::string& encoding) {
if (!is_valid())
return false;
@@ -678,7 +688,6 @@ bool TabProxy::OverrideEncoding(const std::string& encoding) {
void TabProxy::Reposition(HWND window, HWND window_insert_after, int left,
int top, int width, int height, int flags,
HWND parent_window) {
-
IPC::Reposition_Params params = {0};
params.window = window;
params.window_insert_after = window_insert_after;
diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h
index 7693e60..0cc3f26 100644
--- a/chrome/test/automation/tab_proxy.h
+++ b/chrome/test/automation/tab_proxy.h
@@ -327,9 +327,9 @@ class TabProxy : public AutomationResourceProxy {
// to be used with WaitForNavigation (see below).
bool GetLastNavigationTime(int64* last_navigation_time);
- // Waits for a new navigation if none as occurred since |last_navigation_time|
- // The purpose of this function is for operations that causes asynchronous
- // navigation to happen.
+ // Waits for a new navigation if none has occurred since
+ // |last_navigation_time|. The purpose of this function is for operations
+ // that causes asynchronous navigation to happen.
// It is supposed to be used as follow:
// int64 last_nav_time;
// tab_proxy->GetLastNavigationTime(&last_nav_time);
@@ -340,6 +340,9 @@ class TabProxy : public AutomationResourceProxy {
// Gets the current used encoding of the page in the tab.
bool GetPageCurrentEncoding(std::string* encoding);
+ // Toggles encoding auto-detect of the page in the tab
+ bool ToggleEncodingAutoDetect();
+
// Uses the specified encoding to override encoding of the page in the tab.
bool OverrideEncoding(const std::string& encoding);