| Index: chrome/renderer/render_view_unittest.cc
|
| ===================================================================
|
| --- chrome/renderer/render_view_unittest.cc (revision 12427)
|
| +++ chrome/renderer/render_view_unittest.cc (working copy)
|
| @@ -316,3 +316,51 @@
|
| }
|
| }
|
| }
|
| +
|
| +// Test that the RenderView::OnSetTextDirection() function can change the text
|
| +// direction of the selected input element.
|
| +TEST_F(RenderViewTest, OnSetTextDirection) {
|
| + // Load an HTML page consisting of a <textarea> element and a <div> element.
|
| + // This test changes the text direction of the <textarea> element, and
|
| + // writes the values of its 'dir' attribute and its 'direction' property to
|
| + // verify that the text direction is changed.
|
| + view_->set_delay_seconds_for_form_state_sync(0);
|
| + LoadHTML("<html>"
|
| + "<head>"
|
| + "</head>"
|
| + "<body>"
|
| + "<textarea id=\"test\"></textarea>"
|
| + "<div id=\"result\" contenteditable=\"true\"></div>"
|
| + "</body>"
|
| + "</html>");
|
| + render_thread_.sink().ClearMessages();
|
| +
|
| + static const struct {
|
| + WebTextDirection direction;
|
| + const wchar_t* expected_result;
|
| + } kTextDirection[] = {
|
| + {WEB_TEXT_DIRECTION_RTL, L"\x000A" L"rtl,rtl"},
|
| + {WEB_TEXT_DIRECTION_LTR, L"\x000A" L"ltr,ltr"},
|
| + };
|
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) {
|
| + // Set the text direction of the <textarea> element.
|
| + ExecuteJavaScript("document.getElementById('test').focus();");
|
| + view_->OnSetTextDirection(kTextDirection[i].direction);
|
| +
|
| + // Write the values of its DOM 'dir' attribute and its CSS 'direction'
|
| + // property to the <div> element.
|
| + ExecuteJavaScript("var result = document.getElementById('result');"
|
| + "var node = document.getElementById('test');"
|
| + "var style = getComputedStyle(node, null);"
|
| + "result.innerText ="
|
| + " node.getAttribute('dir') + ',' +"
|
| + " style.getPropertyValue('direction');");
|
| +
|
| + // Copy the document content to std::wstring and compare with the
|
| + // expected result.
|
| + const int kMaxOutputCharacters = 16;
|
| + std::wstring output;
|
| + GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output);
|
| + EXPECT_EQ(output, kTextDirection[i].expected_result);
|
| + }
|
| +}
|
|
|