| OLD | NEW |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
| 6 #include "chrome/common/render_messages.h" | 6 #include "chrome/common/render_messages.h" |
| 7 #include "chrome/renderer/mock_render_process.h" | 7 #include "chrome/renderer/mock_render_process.h" |
| 8 #include "chrome/renderer/mock_render_thread.h" | 8 #include "chrome/renderer/mock_render_thread.h" |
| 9 #include "chrome/renderer/render_view.h" | 9 #include "chrome/renderer/render_view.h" |
| 10 #include "chrome/renderer/renderer_webkitclient_impl.h" | 10 #include "chrome/renderer/renderer_webkitclient_impl.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (ime_message->result) { | 310 if (ime_message->result) { |
| 311 // Retrieve the content of this page and compare it with the expected | 311 // Retrieve the content of this page and compare it with the expected |
| 312 // result. | 312 // result. |
| 313 const int kMaxOutputCharacters = 128; | 313 const int kMaxOutputCharacters = 128; |
| 314 std::wstring output; | 314 std::wstring output; |
| 315 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); | 315 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); |
| 316 EXPECT_EQ(output, ime_message->result); | 316 EXPECT_EQ(output, ime_message->result); |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 |
| 321 // Test that the RenderView::OnSetTextDirection() function can change the text |
| 322 // direction of the selected input element. |
| 323 TEST_F(RenderViewTest, OnSetTextDirection) { |
| 324 // Load an HTML page consisting of a <textarea> element and a <div> element. |
| 325 // This test changes the text direction of the <textarea> element, and |
| 326 // writes the values of its 'dir' attribute and its 'direction' property to |
| 327 // verify that the text direction is changed. |
| 328 view_->set_delay_seconds_for_form_state_sync(0); |
| 329 LoadHTML("<html>" |
| 330 "<head>" |
| 331 "</head>" |
| 332 "<body>" |
| 333 "<textarea id=\"test\"></textarea>" |
| 334 "<div id=\"result\" contenteditable=\"true\"></div>" |
| 335 "</body>" |
| 336 "</html>"); |
| 337 render_thread_.sink().ClearMessages(); |
| 338 |
| 339 static const struct { |
| 340 WebTextDirection direction; |
| 341 const wchar_t* expected_result; |
| 342 } kTextDirection[] = { |
| 343 {WEB_TEXT_DIRECTION_RTL, L"\x000A" L"rtl,rtl"}, |
| 344 {WEB_TEXT_DIRECTION_LTR, L"\x000A" L"ltr,ltr"}, |
| 345 }; |
| 346 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) { |
| 347 // Set the text direction of the <textarea> element. |
| 348 ExecuteJavaScript("document.getElementById('test').focus();"); |
| 349 view_->OnSetTextDirection(kTextDirection[i].direction); |
| 350 |
| 351 // Write the values of its DOM 'dir' attribute and its CSS 'direction' |
| 352 // property to the <div> element. |
| 353 ExecuteJavaScript("var result = document.getElementById('result');" |
| 354 "var node = document.getElementById('test');" |
| 355 "var style = getComputedStyle(node, null);" |
| 356 "result.innerText =" |
| 357 " node.getAttribute('dir') + ',' +" |
| 358 " style.getPropertyValue('direction');"); |
| 359 |
| 360 // Copy the document content to std::wstring and compare with the |
| 361 // expected result. |
| 362 const int kMaxOutputCharacters = 16; |
| 363 std::wstring output; |
| 364 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); |
| 365 EXPECT_EQ(output, kTextDirection[i].expected_result); |
| 366 } |
| 367 } |
| OLD | NEW |