| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/shared_memory.h" | 6 #include "base/shared_memory.h" |
| 7 #include "chrome/common/native_web_keyboard_event.h" | 7 #include "chrome/common/native_web_keyboard_event.h" |
| 8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 9 #include "chrome/test/render_view_test.h" | 9 #include "chrome/test/render_view_test.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "printing/image.h" | 11 #include "printing/image.h" |
| 12 #include "printing/native_metafile.h" | 12 #include "printing/native_metafile.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "webkit/api/public/WebURLError.h" | 14 #include "webkit/api/public/WebURLError.h" |
| 15 | 15 |
| 16 using WebKit::WebCompositionCommand; | 16 using WebKit::WebCompositionCommand; |
| 17 using WebKit::WebFrame; |
| 17 using WebKit::WebTextDirection; | 18 using WebKit::WebTextDirection; |
| 18 using WebKit::WebURLError; | 19 using WebKit::WebURLError; |
| 19 | 20 |
| 20 static WebCompositionCommand ToCompositionCommand(int string_type) { | 21 static WebCompositionCommand ToCompositionCommand(int string_type) { |
| 21 switch (string_type) { | 22 switch (string_type) { |
| 22 default: | 23 default: |
| 23 NOTREACHED(); | 24 NOTREACHED(); |
| 24 case -1: | 25 case -1: |
| 25 return WebKit::WebCompositionCommandDiscard; | 26 return WebKit::WebCompositionCommandDiscard; |
| 26 case 0: | 27 case 0: |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Update the status of our IME back-end. | 241 // Update the status of our IME back-end. |
| 241 // TODO(hbono): we should verify messages to be sent from the back-end. | 242 // TODO(hbono): we should verify messages to be sent from the back-end. |
| 242 view_->UpdateIME(); | 243 view_->UpdateIME(); |
| 243 ProcessPendingMessages(); | 244 ProcessPendingMessages(); |
| 244 render_thread_.sink().ClearMessages(); | 245 render_thread_.sink().ClearMessages(); |
| 245 | 246 |
| 246 if (ime_message->result) { | 247 if (ime_message->result) { |
| 247 // Retrieve the content of this page and compare it with the expected | 248 // Retrieve the content of this page and compare it with the expected |
| 248 // result. | 249 // result. |
| 249 const int kMaxOutputCharacters = 128; | 250 const int kMaxOutputCharacters = 128; |
| 250 std::wstring output; | 251 std::wstring output = UTF16ToWideHack( |
| 251 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); | 252 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
| 252 EXPECT_EQ(output, ime_message->result); | 253 EXPECT_EQ(output, ime_message->result); |
| 253 } | 254 } |
| 254 } | 255 } |
| 255 } | 256 } |
| 256 | 257 |
| 257 // Test that the RenderView::OnSetTextDirection() function can change the text | 258 // Test that the RenderView::OnSetTextDirection() function can change the text |
| 258 // direction of the selected input element. | 259 // direction of the selected input element. |
| 259 TEST_F(RenderViewTest, OnSetTextDirection) { | 260 TEST_F(RenderViewTest, OnSetTextDirection) { |
| 260 // Load an HTML page consisting of a <textarea> element and a <div> element. | 261 // Load an HTML page consisting of a <textarea> element and a <div> element. |
| 261 // This test changes the text direction of the <textarea> element, and | 262 // This test changes the text direction of the <textarea> element, and |
| (...skipping 27 matching lines...) Expand all Loading... |
| 289 ExecuteJavaScript("var result = document.getElementById('result');" | 290 ExecuteJavaScript("var result = document.getElementById('result');" |
| 290 "var node = document.getElementById('test');" | 291 "var node = document.getElementById('test');" |
| 291 "var style = getComputedStyle(node, null);" | 292 "var style = getComputedStyle(node, null);" |
| 292 "result.innerText =" | 293 "result.innerText =" |
| 293 " node.getAttribute('dir') + ',' +" | 294 " node.getAttribute('dir') + ',' +" |
| 294 " style.getPropertyValue('direction');"); | 295 " style.getPropertyValue('direction');"); |
| 295 | 296 |
| 296 // Copy the document content to std::wstring and compare with the | 297 // Copy the document content to std::wstring and compare with the |
| 297 // expected result. | 298 // expected result. |
| 298 const int kMaxOutputCharacters = 16; | 299 const int kMaxOutputCharacters = 16; |
| 299 std::wstring output; | 300 std::wstring output = UTF16ToWideHack( |
| 300 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); | 301 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
| 301 EXPECT_EQ(output, kTextDirection[i].expected_result); | 302 EXPECT_EQ(output, kTextDirection[i].expected_result); |
| 302 } | 303 } |
| 303 } | 304 } |
| 304 | 305 |
| 305 // Tests that printing pages work and sending and receiving messages through | 306 // Tests that printing pages work and sending and receiving messages through |
| 306 // that channel all works. | 307 // that channel all works. |
| 307 TEST_F(RenderViewTest, OnPrintPages) { | 308 TEST_F(RenderViewTest, OnPrintPages) { |
| 308 #if defined(OS_WIN) | 309 #if defined(OS_WIN) |
| 309 // Lets simulate a print pages with Hello world. | 310 // Lets simulate a print pages with Hello world. |
| 310 LoadHTML("<body><p>Hello World!</p></body>"); | 311 LoadHTML("<body><p>Hello World!</p></body>"); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 L"%d,%s\x000A" // texts in the second <div> element | 606 L"%d,%s\x000A" // texts in the second <div> element |
| 606 L"%d,%s", // texts in the third <div> element | 607 L"%d,%s", // texts in the third <div> element |
| 607 key_code, kModifierData[j].expected_result, | 608 key_code, kModifierData[j].expected_result, |
| 608 char_code[0], kModifierData[j].expected_result, | 609 char_code[0], kModifierData[j].expected_result, |
| 609 key_code, kModifierData[j].expected_result); | 610 key_code, kModifierData[j].expected_result); |
| 610 | 611 |
| 611 // Retrieve the text in the test page and compare it with the expected | 612 // Retrieve the text in the test page and compare it with the expected |
| 612 // text created from a virtual-key code, a character code, and the | 613 // text created from a virtual-key code, a character code, and the |
| 613 // modifier-key status. | 614 // modifier-key status. |
| 614 const int kMaxOutputCharacters = 1024; | 615 const int kMaxOutputCharacters = 1024; |
| 615 std::wstring output; | 616 std::wstring output = UTF16ToWideHack( |
| 616 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); | 617 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
| 617 | |
| 618 EXPECT_EQ(expected_result, output); | 618 EXPECT_EQ(expected_result, output); |
| 619 } | 619 } |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 #else | 622 #else |
| 623 NOTIMPLEMENTED(); | 623 NOTIMPLEMENTED(); |
| 624 #endif | 624 #endif |
| 625 } | 625 } |
| 626 | 626 |
| 627 // Test that our EditorClientImpl class can insert characters when we send | 627 // Test that our EditorClientImpl class can insert characters when we send |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 std::wstring char_code; | 818 std::wstring char_code; |
| 819 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) | 819 if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0) |
| 820 continue; | 820 continue; |
| 821 } | 821 } |
| 822 } | 822 } |
| 823 | 823 |
| 824 // Retrieve the text in the test page and compare it with the expected | 824 // Retrieve the text in the test page and compare it with the expected |
| 825 // text created from a virtual-key code, a character code, and the | 825 // text created from a virtual-key code, a character code, and the |
| 826 // modifier-key status. | 826 // modifier-key status. |
| 827 const int kMaxOutputCharacters = 4096; | 827 const int kMaxOutputCharacters = 4096; |
| 828 std::wstring output; | 828 std::wstring output = UTF16ToWideHack( |
| 829 GetMainFrame()->GetContentAsPlainText(kMaxOutputCharacters, &output); | 829 GetMainFrame()->contentAsText(kMaxOutputCharacters)); |
| 830 EXPECT_EQ(kLayouts[i].expected_result, output); | 830 EXPECT_EQ(kLayouts[i].expected_result, output); |
| 831 } | 831 } |
| 832 #else | 832 #else |
| 833 NOTIMPLEMENTED(); | 833 NOTIMPLEMENTED(); |
| 834 #endif | 834 #endif |
| 835 } | 835 } |
| 836 | 836 |
| 837 #if 0 | 837 #if 0 |
| 838 // TODO(tyoshino): After fixing flakiness, enable this test. | 838 // TODO(tyoshino): After fixing flakiness, enable this test. |
| 839 TEST_F(RenderViewTest, DidFailProvisionalLoadWithErrorForError) { | 839 TEST_F(RenderViewTest, DidFailProvisionalLoadWithErrorForError) { |
| 840 GetMainFrame()->SetInViewSourceMode(true); | 840 GetMainFrame()->SetInViewSourceMode(true); |
| 841 WebURLError error; | 841 WebURLError error; |
| 842 error.domain.fromUTF8("test_domain"); | 842 error.domain.fromUTF8("test_domain"); |
| 843 error.reason = net::ERR_FILE_NOT_FOUND; | 843 error.reason = net::ERR_FILE_NOT_FOUND; |
| 844 error.unreachableURL = GURL("http://foo"); | 844 error.unreachableURL = GURL("http://foo"); |
| 845 WebFrame* web_frame = GetMainFrame(); | 845 WebFrame* web_frame = GetMainFrame(); |
| 846 WebView* web_view = web_frame->GetView(); | 846 WebView* web_view = web_frame->GetView(); |
| 847 // An error occurred. | 847 // An error occurred. |
| 848 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); | 848 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); |
| 849 // Frame should exit view-source mode. | 849 // Frame should exit view-source mode. |
| 850 EXPECT_FALSE(web_frame->GetInViewSourceMode()); | 850 EXPECT_FALSE(web_frame->GetInViewSourceMode()); |
| 851 } | 851 } |
| 852 #endif | 852 #endif |
| 853 | 853 |
| 854 TEST_F(RenderViewTest, DidFailProvisionalLoadWithErrorForCancellation) { | 854 TEST_F(RenderViewTest, DidFailProvisionalLoadWithErrorForCancellation) { |
| 855 GetMainFrame()->SetInViewSourceMode(true); | 855 GetMainFrame()->enableViewSourceMode(true); |
| 856 WebURLError error; | 856 WebURLError error; |
| 857 error.domain.fromUTF8("test_domain"); | 857 error.domain.fromUTF8("test_domain"); |
| 858 error.reason = net::ERR_ABORTED; | 858 error.reason = net::ERR_ABORTED; |
| 859 error.unreachableURL = GURL("http://foo"); | 859 error.unreachableURL = GURL("http://foo"); |
| 860 WebFrame* web_frame = GetMainFrame(); | 860 WebFrame* web_frame = GetMainFrame(); |
| 861 WebView* web_view = web_frame->GetView(); | 861 WebView* web_view = web_frame->view(); |
| 862 // A cancellation occurred. | 862 // A cancellation occurred. |
| 863 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); | 863 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); |
| 864 // Frame should stay in view-source mode. | 864 // Frame should stay in view-source mode. |
| 865 EXPECT_TRUE(web_frame->GetInViewSourceMode()); | 865 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); |
| 866 } | 866 } |
| OLD | NEW |