| 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 "chrome/common/native_web_keyboard_event.h" | 6 #include "chrome/common/native_web_keyboard_event.h" |
| 7 #include "chrome/common/render_messages.h" | 7 #include "chrome/common/render_messages.h" |
| 8 #include "chrome/test/render_view_test.h" | 8 #include "chrome/test/render_view_test.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "webkit/api/public/WebURLError.h" | 11 #include "webkit/api/public/WebURLError.h" |
| 12 | 12 |
| 13 using WebKit::WebCompositionCommand; |
| 14 using WebKit::WebTextDirection; |
| 13 using WebKit::WebURLError; | 15 using WebKit::WebURLError; |
| 14 | 16 |
| 17 static WebCompositionCommand ToCompositionCommand(int string_type) { |
| 18 switch (string_type) { |
| 19 default: |
| 20 NOTREACHED(); |
| 21 case -1: |
| 22 return WebKit::WebCompositionCommandDiscard; |
| 23 case 0: |
| 24 return WebKit::WebCompositionCommandSet; |
| 25 case 1: |
| 26 return WebKit::WebCompositionCommandConfirm; |
| 27 } |
| 28 } |
| 29 |
| 15 TEST_F(RenderViewTest, OnLoadAlternateHTMLText) { | 30 TEST_F(RenderViewTest, OnLoadAlternateHTMLText) { |
| 16 // Test a new navigation. | 31 // Test a new navigation. |
| 17 GURL test_url("http://www.google.com/some_test_url"); | 32 GURL test_url("http://www.google.com/some_test_url"); |
| 18 view_->OnLoadAlternateHTMLText("<html></html>", true, test_url, | 33 view_->OnLoadAlternateHTMLText("<html></html>", true, test_url, |
| 19 std::string()); | 34 std::string()); |
| 20 | 35 |
| 21 // We should have gotten two different types of start messages in the | 36 // We should have gotten two different types of start messages in the |
| 22 // following order. | 37 // following order. |
| 23 ASSERT_EQ((size_t)2, render_thread_.sink().message_count()); | 38 ASSERT_EQ((size_t)2, render_thread_.sink().message_count()); |
| 24 const IPC::Message* msg = render_thread_.sink().GetMessageAt(0); | 39 const IPC::Message* msg = render_thread_.sink().GetMessageAt(0); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 // Activate (or deactivate) our IME back-end. | 218 // Activate (or deactivate) our IME back-end. |
| 204 view_->OnImeSetInputMode(ime_message->enable); | 219 view_->OnImeSetInputMode(ime_message->enable); |
| 205 break; | 220 break; |
| 206 | 221 |
| 207 case IME_SETFOCUS: | 222 case IME_SETFOCUS: |
| 208 // Update the window focus. | 223 // Update the window focus. |
| 209 view_->OnSetFocus(ime_message->enable); | 224 view_->OnSetFocus(ime_message->enable); |
| 210 break; | 225 break; |
| 211 | 226 |
| 212 case IME_SETCOMPOSITION: | 227 case IME_SETCOMPOSITION: |
| 213 view_->OnImeSetComposition(ime_message->string_type, | 228 view_->OnImeSetComposition( |
| 214 ime_message->cursor_position, | 229 ToCompositionCommand(ime_message->string_type), |
| 215 ime_message->target_start, | 230 ime_message->cursor_position, |
| 216 ime_message->target_end, | 231 ime_message->target_start, |
| 217 ime_message->ime_string); | 232 ime_message->target_end, |
| 233 WideToUTF16Hack(ime_message->ime_string)); |
| 218 break; | 234 break; |
| 219 } | 235 } |
| 220 | 236 |
| 221 // Update the status of our IME back-end. | 237 // Update the status of our IME back-end. |
| 222 // TODO(hbono): we should verify messages to be sent from the back-end. | 238 // TODO(hbono): we should verify messages to be sent from the back-end. |
| 223 view_->UpdateIME(); | 239 view_->UpdateIME(); |
| 224 ProcessPendingMessages(); | 240 ProcessPendingMessages(); |
| 225 render_thread_.sink().ClearMessages(); | 241 render_thread_.sink().ClearMessages(); |
| 226 | 242 |
| 227 if (ime_message->result) { | 243 if (ime_message->result) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 250 "<textarea id=\"test\"></textarea>" | 266 "<textarea id=\"test\"></textarea>" |
| 251 "<div id=\"result\" contenteditable=\"true\"></div>" | 267 "<div id=\"result\" contenteditable=\"true\"></div>" |
| 252 "</body>" | 268 "</body>" |
| 253 "</html>"); | 269 "</html>"); |
| 254 render_thread_.sink().ClearMessages(); | 270 render_thread_.sink().ClearMessages(); |
| 255 | 271 |
| 256 static const struct { | 272 static const struct { |
| 257 WebTextDirection direction; | 273 WebTextDirection direction; |
| 258 const wchar_t* expected_result; | 274 const wchar_t* expected_result; |
| 259 } kTextDirection[] = { | 275 } kTextDirection[] = { |
| 260 {WEB_TEXT_DIRECTION_RTL, L"\x000A" L"rtl,rtl"}, | 276 { WebKit::WebTextDirectionRightToLeft, L"\x000A" L"rtl,rtl" }, |
| 261 {WEB_TEXT_DIRECTION_LTR, L"\x000A" L"ltr,ltr"}, | 277 { WebKit::WebTextDirectionLeftToRight, L"\x000A" L"ltr,ltr" }, |
| 262 }; | 278 }; |
| 263 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) { | 279 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) { |
| 264 // Set the text direction of the <textarea> element. | 280 // Set the text direction of the <textarea> element. |
| 265 ExecuteJavaScript("document.getElementById('test').focus();"); | 281 ExecuteJavaScript("document.getElementById('test').focus();"); |
| 266 view_->OnSetTextDirection(kTextDirection[i].direction); | 282 view_->OnSetTextDirection(kTextDirection[i].direction); |
| 267 | 283 |
| 268 // Write the values of its DOM 'dir' attribute and its CSS 'direction' | 284 // Write the values of its DOM 'dir' attribute and its CSS 'direction' |
| 269 // property to the <div> element. | 285 // property to the <div> element. |
| 270 ExecuteJavaScript("var result = document.getElementById('result');" | 286 ExecuteJavaScript("var result = document.getElementById('result');" |
| 271 "var node = document.getElementById('test');" | 287 "var node = document.getElementById('test');" |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 error.domain.fromUTF8("test_domain"); | 823 error.domain.fromUTF8("test_domain"); |
| 808 error.reason = net::ERR_ABORTED; | 824 error.reason = net::ERR_ABORTED; |
| 809 error.unreachableURL = GURL("http://foo"); | 825 error.unreachableURL = GURL("http://foo"); |
| 810 WebFrame* web_frame = GetMainFrame(); | 826 WebFrame* web_frame = GetMainFrame(); |
| 811 WebView* web_view = web_frame->GetView(); | 827 WebView* web_view = web_frame->GetView(); |
| 812 // A cancellation occurred. | 828 // A cancellation occurred. |
| 813 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); | 829 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); |
| 814 // Frame should stay in view-source mode. | 830 // Frame should stay in view-source mode. |
| 815 EXPECT_TRUE(web_frame->GetInViewSourceMode()); | 831 EXPECT_TRUE(web_frame->GetInViewSourceMode()); |
| 816 } | 832 } |
| OLD | NEW |