Skip to content
Snippets Groups Projects
Commit 94f957fc authored by evan@chromium.org's avatar evan@chromium.org
Browse files

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
parent 5e04fb58
No related merge requests found
......@@ -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
......@@ -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
......
......@@ -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();
}
......
......@@ -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,
......
......@@ -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.
......
......@@ -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());
}
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment