Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/public/test/text_input_test_utils.h" | |
| 6 | |
| 7 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/strings/sys_string_conversions.h" | |
| 11 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | |
| 12 #include "content/browser/site_instance_impl.h" | |
| 13 #include "content/common/mac/attributed_string_coder.h" | |
| 14 #include "content/common/text_input_client_messages.h" | |
| 15 #include "content/public/browser/browser_thread.h" | |
| 16 #include "content/public/browser/render_process_host.h" | |
| 17 #include "content/public/test/test_utils.h" | |
| 18 #include "ipc/ipc_message_macros.h" | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 TestTextInputClientMessageFilter::TestTextInputClientMessageFilter( | |
| 23 RenderProcessHost* host) | |
| 24 : BrowserMessageFilter(TextInputClientMsgStart), | |
| 25 host_(host), | |
| 26 received_string_from_range_(false) { | |
| 27 host->AddFilter(this); | |
| 28 } | |
| 29 | |
| 30 TestTextInputClientMessageFilter::~TestTextInputClientMessageFilter() {} | |
| 31 | |
| 32 void TestTextInputClientMessageFilter::WaitForStringFromRange() { | |
| 33 if (received_string_from_range_) | |
| 34 return; | |
| 35 message_loop_runner_ = new MessageLoopRunner(); | |
| 36 message_loop_runner_->Run(); | |
| 37 } | |
| 38 | |
| 39 bool TestTextInputClientMessageFilter::OnMessageReceived( | |
| 40 const IPC::Message& message) { | |
| 41 if (message.type() == TextInputClientReplyMsg_GotStringForRange::ID) { | |
| 42 received_string_from_range_ = true; | |
| 43 | |
| 44 // Now decode the string to get the word. | |
| 45 TextInputClientReplyMsg_GotStringForRange::Param params; | |
| 46 TextInputClientReplyMsg_GotStringForRange::Read(&message, ¶ms); | |
| 47 const mac::AttributedStringCoder::EncodedString& encoded_string = | |
| 48 std::get<0>(params); | |
| 49 NSAttributedString* decoded = | |
| 50 mac::AttributedStringCoder::Decode(&encoded_string); | |
| 51 string_from_range_ = base::SysNSStringToUTF8([decoded string]); | |
| 52 | |
| 53 // Stop the message loop if it is running. | |
| 54 if (message_loop_runner_) { | |
| 55 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 56 message_loop_runner_->QuitClosure()); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 // unhandled - leave it for the actual TextInputClientMessageFilter to handle. | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 void AskForLookUpDictoinaryForRange(RenderWidgetHostView* tab_view, | |
| 65 const gfx::Range& range) { | |
| 66 RenderWidgetHostViewCocoa* cocoa_view = | |
| 67 static_cast<RenderWidgetHostViewMac*>(tab_view)->cocoa_view(); | |
| 68 | |
| 69 // Explicitly ask for the dictionary for the given range. | |
| 70 [cocoa_view showLookUpDictionaryOverlayFromRange:range.ToNSRange() | |
| 71 targetView:cocoa_view]; | |
| 72 } | |
| 73 | |
| 74 size_t GetOpenNSWindowsCount() { | |
| 75 return [[[NSApplication sharedApplication] windows] count]; | |
|
Avi (use Gerrit)
2016/10/07 21:11:26
return [[NSApp windows] count];
EhsanK
2016/10/11 19:31:56
Done.
| |
| 76 } | |
| 77 | |
| 78 } // namespace content | |
| OLD | NEW |