| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (ime_message->result) { | 309 if (ime_message->result) { |
| 310 // Retrieve the content of this page and compare it with the expected | 310 // Retrieve the content of this page and compare it with the expected |
| 311 // result. | 311 // result. |
| 312 const int kMaxOutputCharacters = 128; | 312 const int kMaxOutputCharacters = 128; |
| 313 std::wstring output; | 313 std::wstring output; |
| 314 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); | 314 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); |
| 315 EXPECT_EQ(output, ime_message->result); | 315 EXPECT_EQ(output, ime_message->result); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 |
| 320 // Test that the RenderView::OnSetTextDirection() function can change the text |
| 321 // direction of the selected input element. |
| 322 TEST_F(RenderViewTest, OnSetTextDirection) { |
| 323 // Load an HTML page consisting of a <textarea> element and a <div> element. |
| 324 // This test changes the text direction of the <textarea> element, and |
| 325 // writes the values of its 'dir' attribute and its 'direction' property to |
| 326 // verify that the text direction is changed. |
| 327 view_->set_delay_seconds_for_form_state_sync(0); |
| 328 LoadHTML("<html>" |
| 329 "<head>" |
| 330 "</head>" |
| 331 "<body>" |
| 332 "<textarea id=\"test\"></textarea>" |
| 333 "<div id=\"result\" contenteditable=\"true\"></div>" |
| 334 "</body>" |
| 335 "</html>"); |
| 336 render_thread_.sink().ClearMessages(); |
| 337 |
| 338 static const struct { |
| 339 WebTextDirection direction; |
| 340 const wchar_t* expected_result; |
| 341 } kTextDirection[] = { |
| 342 {WEB_TEXT_DIRECTION_RTL, L"\x000A" L"rtl,rtl"}, |
| 343 {WEB_TEXT_DIRECTION_LTR, L"\x000A" L"ltr,ltr"}, |
| 344 }; |
| 345 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) { |
| 346 // Set the text direction of the <textarea> element. |
| 347 ExecuteJavaScript("document.getElementById('test').focus();"); |
| 348 view_->OnSetTextDirection(kTextDirection[i].direction); |
| 349 |
| 350 // Write the values of its DOM 'dir' attribute and its CSS 'direction' |
| 351 // property to the <div> element. |
| 352 ExecuteJavaScript("var result = document.getElementById('result');" |
| 353 "var node = document.getElementById('test');" |
| 354 "var style = getComputedStyle(node, null);" |
| 355 "result.innerText =" |
| 356 " node.getAttribute('dir') + ',' +" |
| 357 " style.getPropertyValue('direction');"); |
| 358 |
| 359 // Copy the document content to std::wstring and compare with the |
| 360 // expected result. |
| 361 const int kMaxOutputCharacters = 16; |
| 362 std::wstring output; |
| 363 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); |
| 364 EXPECT_EQ(output, kTextDirection[i].expected_result); |
| 365 } |
| 366 } |
| OLD | NEW |