Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Unified Diff: chrome/browser/browser_encoding_uitest.cc

Issue 18417: Add a UI test for "Encoding" menu Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/download/save_page_uitest.cc » ('j') | chrome/test/ui/ui_test.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/browser_encoding_uitest.cc
===================================================================
--- chrome/browser/browser_encoding_uitest.cc (revision 0)
+++ chrome/browser/browser_encoding_uitest.cc (revision 0)
@@ -0,0 +1,306 @@
+// Copyright (c) 2006-2008 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/file_util.h"
+#include "base/path_service.h"
+#include "base/string_util.h"
+#include "chrome/browser/automation/url_request_mock_http_job.h"
+#include "chrome/browser/download/save_package.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/test/automation/automation_messages.h"
+#include "chrome/test/automation/automation_proxy.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/ui/ui_test.h"
+#include "net/url_request/url_request_unittest.h"
+#include "chrome/common/pref_names.h"
+
+const std::wstring kTestDir = L"encoding_tests";
+
+class BrowserEncodingTest : public UITest {
+ protected:
+ BrowserEncodingTest() : UITest() {}
+
+ // Make sure the content of the page are expected
+ // after override or auto-detect
+ void CheckFile(const std::wstring& generated_file,
Johnny(Jianning) Ding 2009/03/09 12:31:46 would please move this function to UITest with add
+ const std::wstring& expect_result_file,
+ bool check_equal) {
+ std::wstring expect_result_filepath =
+ UITest::GetTestFilePath(kTestDir, expect_result_file);
+
+ ASSERT_TRUE(file_util::PathExists(expect_result_filepath));
+ WaitForGeneratedFileAndCheck(generated_file,
+ expect_result_filepath,
+ check_equal, true);
+ }
+
+ virtual void SetUp() {
+ UITest::SetUp();
+ EXPECT_TRUE(file_util::CreateNewTempDirectory(L"", &save_dir_));
+ save_dir_ += FilePath::kSeparators[0];
+ }
+
+ std::wstring save_dir_;
+ std::wstring encoding_;
+ GURL url;
+};
+
+// Below encodings are ignored because I don't have an editor to
+// create corresponding encoded test file for now :
+// GBK
+// Big5-HKSCS
+// ISO-2022-JP
+// ISO-8859-2
+// ISO-8859-3
+// ISO-8859-10
+// ISO-8859-14
+// ISO-8859-16
Johnny(Jianning) Ding 2009/03/09 12:31:46 would you please file a bug for those encoding, th
+TEST_F(BrowserEncodingTest, TestEncodingAliasMapping) {
+ struct EncodingTestData {
Johnny(Jianning) Ding 2009/03/09 12:31:46 you can move the definition to class BrowserEncodi
+ const wchar_t* file_name;
+ const wchar_t* encoding_name;
+ };
+
+ EncodingTestData encoding_test_data[] = {
+ { L"encoding-UTF-8.htm", L"UTF-8" },
+ { L"encoding-UTF-16LE.htm", L"UTF-16LE" },
+ { L"encoding-iso-8859-1.htm", L"ISO-8859-1" },
+ { L"encoding-windows-1252.htm", L"windows-1252" },
+ { L"encoding-gb18030.htm", L"gb18030" },
+ { L"encoding-Big5.htm", L"Big5" },
+ { L"encoding-windows-949.htm", L"windows-949" },
+ { L"encoding-Shift-JIS.htm", L"Shift_JIS" },
+ { L"encoding-EUC-JP.htm", L"EUC-JP" },
+ { L"encoding-windows-874.htm", L"windows-874" },
+ { L"encoding-ISO-8859-15.htm", L"ISO-8859-15" },
+ { L"encoding-macintosh.htm", L"macintosh" },
+ { L"encoding-ISO-8859-2.htm", L"ISO-8859-2" },
+ { L"encoding-windows-1250.htm", L"windows-1250" },
+ { L"encoding-ISO-8859-5.htm", L"ISO-8859-5" },
+ { L"encoding-windows-1251.htm", L"windows-1251" },
+ { L"encoding-KOI8-R.htm", L"KOI8-R" },
+ { L"encoding-KOI8-U.htm", L"KOI8-U" },
+ { L"encoding-ISO-8859-7.htm", L"ISO-8859-7" },
+ { L"encoding-windows-1253.htm", L"windows-1253" },
+ { L"encoding-windows-1254.htm", L"windows-1254" },
+ { L"encoding-ISO-8859-6.htm", L"ISO-8859-6" },
+ { L"encoding-windows-1256.htm", L"windows-1256" },
+ { L"encoding-ISO-8859-8.htm", L"ISO-8859-8" },
+ { L"encoding-windows-1255.htm", L"windows-1255" },
+ { L"encoding-windows-1258.htm", L"windows-1258" },
+ { L"encoding-ISO-8859-4.htm", L"ISO-8859-4" },
+ { L"encoding-ISO-8859-13.htm", L"ISO-8859-13" },
+ { L"encoding-windows-1257.htm", L"windows-1257" },
+ };
+
+ for (int i = 0;i < arraysize (encoding_test_data); i++) {
+ url = URLRequestMockHTTPJob::GetMockUrl(
+ kTestDir + L"/encoding_alias_mapping/" + encoding_test_data[i].file_name);
Johnny(Jianning) Ding 2009/03/09 12:31:46 needs 4 spaces indent, you can write it like url =
+
+ scoped_ptr<TabProxy> tab(GetActiveTab());
+ ASSERT_TRUE(tab->NavigateToURL(url));
+ WaitUntilTabCount(1);
+
+ EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
+ EXPECT_EQ(encoding_, encoding_test_data[i].encoding_name);
+ }
+}
+
+TEST_F(BrowserEncodingTest, TestOverrideEncoding) {
+ std::wstring file_name = L"gb18030_content_with_encoding_iso88591.htm";
+ std::wstring expect_file_name =
+ L"encoding_user_override\\expect_gb18030_content_save_from_iso88591.htm";
+
+ url = URLRequestMockHTTPJob::GetMockUrl(
+ kTestDir + L"/encoding_user_override/" + file_name);
Johnny(Jianning) Ding 2009/03/09 12:31:46 4 spaces indent
+ scoped_ptr<TabProxy> tab(GetActiveTab());
+ ASSERT_TRUE(tab->NavigateToURL(url));
+ WaitUntilTabCount(1);
+
+ // Get the original defined encoding in the page
+ // std::wstring encoding;
+ EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
+ EXPECT_EQ(encoding_, L"ISO-8859-1");
+
+ // Override the encoding to "gb18030".
+ int64 last_nav_time = 0;
+ EXPECT_TRUE(tab->GetLastNavigationTime(&last_nav_time));
+ EXPECT_TRUE(tab->OverrideEncoding(L"gb18030"));
+ EXPECT_TRUE(tab->WaitForNavigation(last_nav_time));
+
+ // Re-get the encoding of page. It should be gb18030.
+ EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
+ EXPECT_EQ(encoding_, L"gb18030");
+
+ // Dump the page, the content of dump page should be equal with our expect
+ // result file gb18030_content_with_encoding_gb18030.htm.
+ std::wstring full_file_name = save_dir_ + file_name;
+ std::wstring dir = save_dir_ +
+ L"gb18030_content_with_encoding_iso88591_files";
+ EXPECT_TRUE(tab->SavePage(full_file_name, dir,
+ SavePackage::SAVE_AS_COMPLETE_HTML));
+ EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get()));
+ CheckFile(full_file_name, expect_file_name, true);
+}
+
+// Below encoding are disabled because it is known issue that
+// auto detect doesn't return right value for them
+// ISO-8859-4
+// ISO-8859-13
+// windows-1257
+// KOI8-U
+// macintosh
+// windows-1252
+
Johnny(Jianning) Ding 2009/03/09 12:31:46 please remove this empty line.
+// Also disabled Thai and Vietnamese because auto detect doesn't work for them
+// windows-874
+// windows-1258
+// windows-1253
+
Johnny(Jianning) Ding 2009/03/09 12:31:46 please remove this empty line.
+// For Hebrew, I made the expecting encoding value as ISO-8859-8-I because of
+// bug crbug.com/2927
+
+TEST_F(BrowserEncodingTest, TestEncodingAutoDetect) {
+ // Test file name
+ const wchar_t* file_name[] = {
Johnny(Jianning) Ding 2009/03/09 12:31:46 please use the previous defined "EncodingTestData"
+ L"Big5_content_without_encoding_declaration.htm",
+ L"gb18030_content_without_encoding_declaration.htm",
+ L"iso-8859-1_content_without_encoding_declaration.htm",
+ L"ISO-8859-5_content_without_encoding_declaration.htm",
+ L"ISO-8859-6_content_without_encoding_declaration.htm",
+ L"ISO-8859-7_content_without_encoding_declaration.htm",
+ L"ISO-8859-8_content_without_encoding_declaration.htm",
+ L"KOI8-R_content_without_encoding_declaration.htm",
+ L"Shift-JIS_content_without_encoding_declaration.htm",
+ L"UTF-8_content_without_encoding_declaration.htm",
+ L"windows-949_content_without_encoding_declaration.htm",
+ L"windows-1251_content_without_encoding_declaration.htm",
+ L"windows-1254_content_without_encoding_declaration.htm",
+ L"windows-1255_content_without_encoding_declaration.htm",
+ L"windows-1256_content_without_encoding_declaration.htm",
+ };
+
+ // Expect file directory and file name
+ std::wstring expect_folder_name = L"encoding_auto_detect\\expect_results\\";
+ const wchar_t* expect_file_name[] = {
+ L"expect_Big5_content_save_from_without_encoding_declaration.htm",
+ L"expect_gb18030_content_save_from_without_encoding_declaration.htm",
+ L"expect_iso-8859-1_content_save_from_without_encoding_declaration.htm",
+ L"expect_ISO-8859-5_content_save_from_without_encoding_declaration.htm",
+ L"expect_ISO-8859-6_content_save_from_without_encoding_declaration.htm",
+ L"expect_ISO-8859-7_content_save_from_without_encoding_declaration.htm",
+ L"expect_ISO-8859-8_content_save_from_without_encoding_declaration.htm",
+ L"expect_KOI8-R_content_save_from_without_encoding_declaration.htm",
+ L"expect_Shift-JIS_content_save_from_without_encoding_declaration.htm",
+ L"expect_UTF-8_content_save_from_without_encoding_declaration.htm",
+ L"expect_windows-949_content_save_from_without_encoding_declaration.htm",
+ L"expect_windows-1251_content_save_from_without_encoding_declaration.htm",
+ L"expect_windows-1254_content_save_from_without_encoding_declaration.htm",
+ L"expect_windows-1255_content_save_from_without_encoding_declaration.htm",
+ L"expect_windows-1256_content_save_from_without_encoding_declaration.htm",
+ };
+
+ // Real expect file name
+ std::wstring full_expect_file_name;
+
+ // Expected encoding
+ const wchar_t* expect_encoding[] = {L"Big5",
+ L"gb18030",
+ L"ISO-8859-1",
+ L"ISO-8859-5",
+ L"ISO-8859-6",
+ L"ISO-8859-7",
+ L"ISO-8859-8-I",
+ L"KOI8-R",
+ L"Shift_JIS",
+ L"UTF-8",
+ L"windows-949",
+ L"windows-1251",
+ L"windows-1254",
+ L"windows-1255",
+ L"windows-1256",
+ };
+
+ // Save as file directory
+ const wchar_t* save_dir_sub[] = {
+ L"Big5_content_without_encoding_declaration_files",
Johnny(Jianning) Ding 2009/03/09 12:31:46 you can define the prefix name like EncodingTestDa
+ L"gb18030_content_without_encoding_declaration_files",
+ L"iso-8859-1_content_without_encoding_declaration_files",
+ L"ISO-8859-5_content_without_encoding_declaration_files",
+ L"ISO-8859-6_content_without_encoding_declaration_files",
+ L"ISO-8859-7_content_without_encoding_declaration_files",
+ L"ISO-8859-8_content_without_encoding_declaration_files",
+ L"KOI8-R_content_without_encoding_declaration_files",
+ L"Shift-JIS_content_without_encoding_declaration_files",
+ L"UTF-8_content_without_encoding_declaration_files",
+ L"windows-949_content_without_encoding_declaration_files",
+ L"windows-1251_content_without_encoding_declaration_files",
+ L"windows-1254_content_without_encoding_declaration_files",
+ L"windows-1255_content_without_encoding_declaration_files",
+ L"windows-1256_content_without_encoding_declaration_files",
+ };
+
+ // Real save as location: dir = save_dir_ + save_dir_sub[i];
+ std::wstring dir;
+
+ // Real save as file name: full_file_name = save_dir_ + file_name[i];
+ std::wstring full_file_name;
+
+ int64 last_nav_time;
+ bool encoding_auto_detect = false;
+ bool new_encoding_auto_detect = false;
+
+ for(int i = 0;i < arraysize (file_name);i++) {
+ scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ ASSERT_TRUE(browser.get());
+
+ // Set the default charset to non-GB related encoding to make sure we
+ // incorrectly decode the page.
+ browser->SetStringPreference(prefs::kDefaultCharset, L"ISO-8859-1");
+
+ url = URLRequestMockHTTPJob::GetMockUrl(
+ kTestDir + L"/encoding_auto_detect/" + file_name[i]);
Johnny(Jianning) Ding 2009/03/09 12:31:46 4 spaces indent
+ scoped_ptr<TabProxy> tab(GetActiveTab());
+ ASSERT_TRUE(tab->NavigateToURL(url));
+ WaitUntilTabCount(1);
+
+ // Disable auto detect if it is on
+ last_nav_time = 0;
+ EXPECT_TRUE(browser->SetBooleanPreference(
+ prefs::kWebKitUsesUniversalDetector, encoding_auto_detect));
+ EXPECT_TRUE(tab->Reload());
+
+ // Get the encoding used for the page, it must be the default charset we
+ // just set
+ // std::wstring encoding;
+ EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
+ EXPECT_EQ(encoding_, L"ISO-8859-1");
+
+ // Enable the encoding auto detection.
+ last_nav_time = 0;
+ EXPECT_TRUE(browser->SetBooleanPreference(
+ prefs::kWebKitUsesUniversalDetector, !encoding_auto_detect));
+ EXPECT_TRUE(tab->Reload());
+
+ // Re-get the encoding of page. It should return the real encoding now.
+ EXPECT_TRUE(browser->GetBooleanPreference(
+ prefs::kWebKitUsesUniversalDetector, &new_encoding_auto_detect));
+ EXPECT_EQ(new_encoding_auto_detect, !encoding_auto_detect);
+ EXPECT_TRUE(tab->GetPageCurrentEncoding(&encoding_));
+ EXPECT_EQ(encoding_, expect_encoding[i]);
+
+ // Dump the page, the content of dump page should be equal with our expect
+ // result file gb18030_content_with_encoding_gb18030.htm.
+ full_file_name = save_dir_ + file_name[i];
+ dir = save_dir_ + save_dir_sub[i];
+ full_expect_file_name = expect_folder_name + expect_file_name[i];
+
+ EXPECT_TRUE(tab->SavePage(full_file_name, dir,
+ SavePackage::SAVE_AS_COMPLETE_HTML));
+ EXPECT_TRUE(WaitForDownloadShelfVisible(tab.get()));
+
+ CheckFile(full_file_name, full_expect_file_name, true);
+ }
+}
« no previous file with comments | « no previous file | chrome/browser/download/save_page_uitest.cc » ('j') | chrome/test/ui/ui_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698