| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/string16.h" | 5 #include "base/strings/string16.h" |
| 6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/common/frame_messages.h" |
| 9 #include "content/common/frame_replication_state.h" |
| 10 #include "content/common/input_messages.h" |
| 11 #include "content/common/text_input_client_messages.h" |
| 8 #include "content/public/browser/native_web_keyboard_event.h" | 12 #include "content/public/browser/native_web_keyboard_event.h" |
| 9 #include "content/public/common/web_preferences.h" | 13 #include "content/public/common/web_preferences.h" |
| 10 #include "content/public/test/render_view_test.h" | 14 #include "content/public/test/render_view_test.h" |
| 11 #include "content/renderer/render_view_impl.h" | 15 #include "content/renderer/render_view_impl.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" | 17 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" |
| 14 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 15 #include "third_party/WebKit/public/web/WebView.h" | 19 #include "third_party/WebKit/public/web/WebView.h" |
| 16 | 20 |
| 17 #include <Carbon/Carbon.h> // for the kVK_* constants. | 21 #include <Carbon/Carbon.h> // for the kVK_* constants. |
| 18 #include <Cocoa/Cocoa.h> | 22 #include <Cocoa/Cocoa.h> |
| 19 | 23 |
| 20 using blink::WebFrameContentDumper; | 24 using blink::WebFrameContentDumper; |
| 25 using blink::WebCompositionUnderline; |
| 21 | 26 |
| 22 namespace content { | 27 namespace content { |
| 23 | 28 |
| 24 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { | 29 NSEvent* CmdDeadKeyEvent(NSEventType type, unsigned short code) { |
| 25 UniChar uniChar = 0; | 30 UniChar uniChar = 0; |
| 26 switch(code) { | 31 switch(code) { |
| 27 case kVK_UpArrow: | 32 case kVK_UpArrow: |
| 28 uniChar = NSUpArrowFunctionKey; | 33 uniChar = NSUpArrowFunctionKey; |
| 29 break; | 34 break; |
| 30 case kVK_DownArrow: | 35 case kVK_DownArrow: |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); | 150 EditCommands(1, EditCommand("moveToBeginningOfDocument", ""))); |
| 146 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); | 151 SendNativeKeyEvent(NativeWebKeyboardEvent(arrowUpKeyDown)); |
| 147 ProcessPendingMessages(); | 152 ProcessPendingMessages(); |
| 148 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); | 153 ExecuteJavaScriptForTests("scroll.textContent = window.pageYOffset"); |
| 149 output = WebFrameContentDumper::dumpWebViewAsText(view->GetWebView(), | 154 output = WebFrameContentDumper::dumpWebViewAsText(view->GetWebView(), |
| 150 kMaxOutputCharacters) | 155 kMaxOutputCharacters) |
| 151 .ascii(); | 156 .ascii(); |
| 152 EXPECT_EQ(kArrowUpNoScroll, output); | 157 EXPECT_EQ(kArrowUpNoScroll, output); |
| 153 } | 158 } |
| 154 | 159 |
| 160 // TODO(ekaramad): This test could be removed once we do not send irrelevant |
| 161 // IPCs from browser during the time RenderViewImpl is swapped out |
| 162 // (https://crbug.com/669219). |
| 163 // This test verfies that when RenderViewImpl is swapped out, handling IPCs |
| 164 // which need a WebFrameWidget will not lead to a crash. |
| 165 TEST_F(RenderViewTest, HandleIPCsInSwappedOutState) { |
| 166 LoadHTML("<input/>"); |
| 167 |
| 168 // Normally, we have a WebFrameWidget. |
| 169 EXPECT_TRUE(GetWebWidget()->isWebFrameWidget()); |
| 170 |
| 171 // Swap out the main frame so that the frame widget is destroyed. |
| 172 auto* view = static_cast<RenderViewImpl*>(view_); |
| 173 auto* main_frame = view->GetMainRenderFrame(); |
| 174 main_frame->OnMessageReceived(FrameMsg_SwapOut( |
| 175 main_frame->GetRoutingID(), 123, true, FrameReplicationState())); |
| 176 |
| 177 // We no longer have a frame widget. |
| 178 EXPECT_FALSE(GetWebWidget()->isWebFrameWidget()); |
| 179 |
| 180 int routing_id = view->GetRoutingID(); |
| 181 // Now simulate some TextInputClientMac IPCs. These will be handled by |
| 182 // RenderWidget which forwards them to the TextInputClientObserver |
| 183 using Range = gfx::Range; |
| 184 using Point = gfx::Point; |
| 185 view->OnMessageReceived( |
| 186 TextInputClientMsg_CharacterIndexForPoint(routing_id, Point())); |
| 187 view->OnMessageReceived( |
| 188 TextInputClientMsg_FirstRectForCharacterRange(routing_id, Range())); |
| 189 view->OnMessageReceived( |
| 190 TextInputClientMsg_StringForRange(routing_id, Range())); |
| 191 view->OnMessageReceived( |
| 192 TextInputClientMsg_CharacterIndexForPoint(routing_id, Point())); |
| 193 |
| 194 // Simulate some IME related IPCs. |
| 195 using Text = base::string16; |
| 196 using Underlines = std::vector<blink::WebCompositionUnderline>; |
| 197 view->OnMessageReceived(InputMsg_ImeSetComposition( |
| 198 routing_id, Text(), Underlines(), Range(), 0, 0)); |
| 199 view->OnMessageReceived( |
| 200 InputMsg_ImeCommitText(routing_id, Text(), Underlines(), Range(), 0)); |
| 201 view->OnMessageReceived(InputMsg_ImeFinishComposingText(routing_id, false)); |
| 202 } |
| 203 |
| 155 } // namespace content | 204 } // namespace content |
| OLD | NEW |