From 94f957fcf2bd0d102c35ab6c897332c72b74fc4e Mon Sep 17 00:00:00 2001 From: "evan@chromium.org" <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Fri, 3 Dec 2010 20:38:18 +0000 Subject: [PATCH] glue: use string16 in place of wstring for Unicode text BUG=23581 TEST=compiles Review URL: http://codereview.chromium.org/5591004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68208 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/bookmarklet_unittest.cc | 18 +++++++++--------- webkit/glue/cpp_bound_class_unittest.cc | 6 ++++-- webkit/glue/mimetype_unittest.cc | 12 ++++++------ webkit/glue/webkit_glue.cc | 22 +++++++++++----------- webkit/glue/webkit_glue.h | 6 +++--- webkit/tools/test_shell/test_shell.cc | 10 +++++----- webkit/tools/test_shell/test_shell.h | 2 +- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/webkit/glue/bookmarklet_unittest.cc b/webkit/glue/bookmarklet_unittest.cc index 5d8a364926369..d7fada519c193 100644 --- a/webkit/glue/bookmarklet_unittest.cc +++ b/webkit/glue/bookmarklet_unittest.cc @@ -26,8 +26,8 @@ TEST_F(BookmarkletTest, Redirect) { test_shell_->LoadURL( GURL("javascript:location.href='data:text/plain,SUCCESS'")); test_shell_->WaitTestFinished(); - std::wstring text = test_shell_->GetDocumentText(); - EXPECT_EQ(L"SUCCESS", text); + string16 text = test_shell_->GetDocumentText(); + EXPECT_EQ("SUCCESS", UTF16ToASCII(text)); } TEST_F(BookmarkletTest, RedirectVoided) { @@ -38,12 +38,12 @@ TEST_F(BookmarkletTest, RedirectVoided) { test_shell_->LoadURL( GURL("javascript:void(location.href='data:text/plain,SUCCESS')")); test_shell_->WaitTestFinished(); - std::wstring text = test_shell_->GetDocumentText(); - EXPECT_EQ(L"SUCCESS", text); + string16 text = test_shell_->GetDocumentText(); + EXPECT_EQ("SUCCESS", UTF16ToASCII(text)); } TEST_F(BookmarkletTest, NonEmptyResult) { - std::wstring text; + string16 text; // TODO(darin): This test fails in a JSC build. WebCore+JSC does not really // need to support this usage until WebCore supports javascript: URLs that @@ -54,13 +54,13 @@ TEST_F(BookmarkletTest, NonEmptyResult) { test_shell_->LoadURL(L"javascript:false"); MessageLoop::current()->RunAllPending(); text = test_shell_->GetDocumentText(); - EXPECT_EQ(L"false", text); + EXPECT_EQ("false", UTF16ToASCII(text)); #endif test_shell_->LoadURL(GURL("javascript:'hello world'")); MessageLoop::current()->RunAllPending(); text = test_shell_->GetDocumentText(); - EXPECT_EQ(L"hello world", text); + EXPECT_EQ("hello world", UTF16ToASCII(text)); } TEST_F(BookmarkletTest, DocumentWrite) { @@ -69,8 +69,8 @@ TEST_F(BookmarkletTest, DocumentWrite) { "document.write('hello world');" "document.close()")); MessageLoop::current()->RunAllPending(); - std::wstring text = test_shell_->GetDocumentText(); - EXPECT_EQ(L"hello world", text); + string16 text = test_shell_->GetDocumentText(); + EXPECT_EQ("hello world", UTF16ToASCII(text)); } } // namespace diff --git a/webkit/glue/cpp_bound_class_unittest.cc b/webkit/glue/cpp_bound_class_unittest.cc index 2f53c47f8dc6a..54581ad65be0e 100644 --- a/webkit/glue/cpp_bound_class_unittest.cc +++ b/webkit/glue/cpp_bound_class_unittest.cc @@ -9,6 +9,7 @@ #include <vector> #include "base/message_loop.h" +#include "base/string_util.h" #include "third_party/WebKit/WebKit/chromium/public/WebData.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" @@ -113,14 +114,15 @@ class CppBoundClassTest : public TestShellTest { // document text is exactly "SUCCESS". void CheckJavaScriptSuccess(const std::string& javascript) { ExecuteJavaScript(javascript); - EXPECT_EQ(L"SUCCESS", webkit_glue::DumpDocumentText(webframe_)); + EXPECT_EQ("SUCCESS", + UTF16ToASCII(webkit_glue::DumpDocumentText(webframe_))); } // Executes the specified JavaScript and checks that the resulting document // text is empty. void CheckJavaScriptFailure(const std::string& javascript) { ExecuteJavaScript(javascript); - EXPECT_EQ(L"", webkit_glue::DumpDocumentText(webframe_)); + EXPECT_EQ("", UTF16ToASCII(webkit_glue::DumpDocumentText(webframe_))); } // Constructs a JavaScript snippet that evaluates and compares the left and diff --git a/webkit/glue/mimetype_unittest.cc b/webkit/glue/mimetype_unittest.cc index 1c2e5f4a3d7b6..3f17e79c2cdbb 100644 --- a/webkit/glue/mimetype_unittest.cc +++ b/webkit/glue/mimetype_unittest.cc @@ -23,12 +23,12 @@ class MimeTypeTests : public TestShellTest { test_shell_->WaitTestFinished(); } - void CheckMimeType(const char* mimetype, const std::wstring& expected) { + void CheckMimeType(const char* mimetype, const std::string& expected) { std::string path("contenttype?"); GURL url(test_server_.GetURL(path + mimetype)); LoadURL(url); WebFrame* frame = test_shell_->webView()->mainFrame(); - EXPECT_EQ(expected, webkit_glue::DumpDocumentText(frame)); + EXPECT_EQ(expected, UTF16ToASCII(webkit_glue::DumpDocumentText(frame))); } UnittestTestServer test_server_; @@ -37,8 +37,8 @@ class MimeTypeTests : public TestShellTest { TEST_F(MimeTypeTests, MimeTypeTests) { ASSERT_TRUE(test_server_.Start()); - std::wstring expected_src(L"<html>\n<body>\n" - L"<p>HTML text</p>\n</body>\n</html>\n"); + std::string expected_src("<html>\n<body>\n" + "<p>HTML text</p>\n</body>\n</html>\n"); // These files should all be displayed as plain text. const char* plain_text[] = { @@ -66,7 +66,7 @@ TEST_F(MimeTypeTests, MimeTypeTests) { "application/xhtml+xml", }; for (size_t i = 0; i < arraysize(html_src); ++i) { - CheckMimeType(html_src[i], L"HTML text"); + CheckMimeType(html_src[i], "HTML text"); } // These shouldn't be rendered as text or HTML, but shouldn't download @@ -78,7 +78,7 @@ TEST_F(MimeTypeTests, MimeTypeTests) { "image/bmp", }; for (size_t i = 0; i < arraysize(not_text); ++i) { - CheckMimeType(not_text[i], L""); + CheckMimeType(not_text[i], ""); test_shell_->webView()->mainFrame()->stopLoading(); } diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc index 67b61bafff610..350ba29fababc 100644 --- a/webkit/glue/webkit_glue.cc +++ b/webkit/glue/webkit_glue.cc @@ -84,29 +84,29 @@ void EnableWebCoreNotImplementedLogging() { WebKit::enableLogChannel("NotYetImplemented"); } -std::wstring DumpDocumentText(WebFrame* web_frame) { +string16 DumpDocumentText(WebFrame* web_frame) { // We use the document element's text instead of the body text here because // not all documents have a body, such as XML documents. WebElement document_element = web_frame->document().documentElement(); if (document_element.isNull()) - return std::wstring(); + return string16(); - return UTF16ToWideHack(document_element.innerText()); + return document_element.innerText(); } -std::wstring DumpFramesAsText(WebFrame* web_frame, bool recursive) { - std::wstring result; +string16 DumpFramesAsText(WebFrame* web_frame, bool recursive) { + string16 result; // Add header for all but the main frame. Skip empty frames. if (web_frame->parent() && !web_frame->document().documentElement().isNull()) { - result.append(L"\n--------\nFrame: '"); - result.append(UTF16ToWideHack(web_frame->name())); - result.append(L"'\n--------\n"); + result.append(ASCIIToUTF16("\n--------\nFrame: '")); + result.append(web_frame->name()); + result.append(ASCIIToUTF16("'\n--------\n")); } result.append(DumpDocumentText(web_frame)); - result.append(L"\n"); + result.append(ASCIIToUTF16("\n")); if (recursive) { WebFrame* child = web_frame->firstChild(); @@ -117,8 +117,8 @@ std::wstring DumpFramesAsText(WebFrame* web_frame, bool recursive) { return result; } -std::wstring DumpRenderer(WebFrame* web_frame) { - return UTF16ToWideHack(web_frame->renderTreeAsText()); +string16 DumpRenderer(WebFrame* web_frame) { + return web_frame->renderTreeAsText(); } bool CounterValueForElementById(WebFrame* web_frame, const std::string& id, diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h index 6cc55b24eddd8..d5149842a197d 100644 --- a/webkit/glue/webkit_glue.h +++ b/webkit/glue/webkit_glue.h @@ -50,15 +50,15 @@ void SetJavaScriptFlags(const std::string& flags); void EnableWebCoreNotImplementedLogging(); // Returns the text of the document element. -std::wstring DumpDocumentText(WebKit::WebFrame* web_frame); +string16 DumpDocumentText(WebKit::WebFrame* web_frame); // Returns the text of the document element and optionally its child frames. // If recursive is false, this is equivalent to DumpDocumentText followed by // a newline. If recursive is true, it recursively dumps all frames as text. -std::wstring DumpFramesAsText(WebKit::WebFrame* web_frame, bool recursive); +string16 DumpFramesAsText(WebKit::WebFrame* web_frame, bool recursive); // Returns the renderer's description of its tree (its externalRepresentation). -std::wstring DumpRenderer(WebKit::WebFrame* web_frame); +string16 DumpRenderer(WebKit::WebFrame* web_frame); // Fill the value of counter in the element specified by the id into // counter_value. Return false when the specified id doesn't exist. diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index ffaba74427877..cb1e00700c51b 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -260,14 +260,14 @@ void TestShell::Dump(TestShell* shell) { if (should_dump_as_text) { bool recursive = shell->layout_test_controller_-> ShouldDumpChildFramesAsText(); - std::string data_utf8 = WideToUTF8( + std::string data_utf8 = UTF16ToUTF8( webkit_glue::DumpFramesAsText(frame, recursive)); if (fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout) != data_utf8.size()) { LOG(FATAL) << "Short write to stdout, disk full?"; } } else { - printf("%s", WideToUTF8( + printf("%s", UTF16ToUTF8( webkit_glue::DumpRenderer(frame)).c_str()); bool recursive = shell->layout_test_controller_-> @@ -717,7 +717,7 @@ void TestShell::DumpDocumentText() { return; const std::string data = - WideToUTF8(webkit_glue::DumpDocumentText(webView()->mainFrame())); + UTF16ToUTF8(webkit_glue::DumpDocumentText(webView()->mainFrame())); file_util::WriteFile(file_path, data.c_str(), data.length()); } @@ -727,11 +727,11 @@ void TestShell::DumpRenderTree() { return; const std::string data = - WideToUTF8(webkit_glue::DumpRenderer(webView()->mainFrame())); + UTF16ToUTF8(webkit_glue::DumpRenderer(webView()->mainFrame())); file_util::WriteFile(file_path, data.c_str(), data.length()); } -std::wstring TestShell::GetDocumentText() { +string16 TestShell::GetDocumentText() { return webkit_glue::DumpDocumentText(webView()->mainFrame()); } diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index 048c5fff0627b..b35bb592fc2e8 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -215,7 +215,7 @@ public: bool Navigate(const TestNavigationEntry& entry, bool reload); bool PromptForSaveFile(const wchar_t* prompt_title, FilePath* result); - std::wstring GetDocumentText(); + string16 GetDocumentText(); void DumpDocumentText(); void DumpRenderTree(); -- GitLab