Chromium Code Reviews| 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 #import "content/browser/renderer_host/text_input_client_mac.h" | 5 #import "content/browser/renderer_host/text_input_client_mac.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/test/scoped_task_scheduler.h" | |
| 13 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 14 #include "content/browser/renderer_host/render_process_host_impl.h" | 16 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 17 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 16 #include "content/browser/renderer_host/render_widget_host_impl.h" | 18 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 17 #include "content/browser/renderer_host/text_input_client_message_filter.h" | 19 #include "content/browser/renderer_host/text_input_client_message_filter.h" |
| 18 #include "content/common/text_input_client_messages.h" | 20 #include "content/common/text_input_client_messages.h" |
| 19 #include "content/public/test/mock_render_process_host.h" | 21 #include "content/public/test/mock_render_process_host.h" |
| 20 #include "content/public/test/test_browser_context.h" | 22 #include "content/public/test/test_browser_context.h" |
| 21 #include "ipc/ipc_test_sink.h" | 23 #include "ipc/ipc_test_sink.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 38 void Paste() override {} | 40 void Paste() override {} |
| 39 void SelectAll() override {} | 41 void SelectAll() override {} |
| 40 }; | 42 }; |
| 41 | 43 |
| 42 // This test does not test the WebKit side of the dictionary system (which | 44 // This test does not test the WebKit side of the dictionary system (which |
| 43 // performs the actual data fetching), but rather this just tests that the | 45 // performs the actual data fetching), but rather this just tests that the |
| 44 // service's signaling system works. | 46 // service's signaling system works. |
| 45 class TextInputClientMacTest : public testing::Test { | 47 class TextInputClientMacTest : public testing::Test { |
| 46 public: | 48 public: |
| 47 TextInputClientMacTest() | 49 TextInputClientMacTest() |
| 48 : browser_context_(), | 50 : task_scheduler_(&message_loop_), |
| 51 browser_context_(), | |
| 49 process_factory_(), | 52 process_factory_(), |
| 50 delegate_(), | 53 delegate_(), |
| 51 thread_("TextInputClientMacTestThread") { | 54 thread_("TextInputClientMacTestThread") { |
| 52 RenderProcessHost* rph = | 55 RenderProcessHost* rph = |
| 53 process_factory_.CreateRenderProcessHost(&browser_context_, nullptr); | 56 process_factory_.CreateRenderProcessHost(&browser_context_, nullptr); |
| 54 int32_t routing_id = rph->GetNextRoutingID(); | 57 int32_t routing_id = rph->GetNextRoutingID(); |
| 55 widget_.reset(new RenderWidgetHostImpl(&delegate_, rph, routing_id, false)); | 58 widget_.reset(new RenderWidgetHostImpl(&delegate_, rph, routing_id, false)); |
| 56 } | 59 } |
| 57 | 60 |
| 61 void TearDown() override { | |
| 62 // |widget_| needs to be cleared before flushing the message loop, otherwise | |
| 63 // |widgets_|'s destructor calls MockRenderProcessHost::Cleanup, it | |
| 64 // schedules the MRPH deletion, and then MockRenderProcessHostFactory also | |
| 65 // deletes the MRPH before scheduled MRPH deletion is invoked. | |
|
kinuko
2017/03/31 14:26:55
Whoa.
| |
| 66 widget_.reset(); | |
| 67 base::RunLoop().RunUntilIdle(); | |
| 68 } | |
| 69 | |
| 58 // Accessor for the TextInputClientMac instance. | 70 // Accessor for the TextInputClientMac instance. |
| 59 TextInputClientMac* service() { | 71 TextInputClientMac* service() { |
| 60 return TextInputClientMac::GetInstance(); | 72 return TextInputClientMac::GetInstance(); |
| 61 } | 73 } |
| 62 | 74 |
| 63 // Helper method to post a task on the testing thread's MessageLoop after | 75 // Helper method to post a task on the testing thread's MessageLoop after |
| 64 // a short delay. | 76 // a short delay. |
| 65 void PostTask(const tracked_objects::Location& from_here, | 77 void PostTask(const tracked_objects::Location& from_here, |
| 66 const base::Closure& task) { | 78 const base::Closure& task) { |
| 67 PostTask(from_here, task, base::TimeDelta::FromMilliseconds(kTaskDelayMs)); | 79 PostTask(from_here, task, base::TimeDelta::FromMilliseconds(kTaskDelayMs)); |
| 68 } | 80 } |
| 69 | 81 |
| 70 void PostTask(const tracked_objects::Location& from_here, | 82 void PostTask(const tracked_objects::Location& from_here, |
| 71 const base::Closure& task, | 83 const base::Closure& task, |
| 72 const base::TimeDelta delay) { | 84 const base::TimeDelta delay) { |
| 73 thread_.task_runner()->PostDelayedTask(from_here, task, delay); | 85 thread_.task_runner()->PostDelayedTask(from_here, task, delay); |
| 74 } | 86 } |
| 75 | 87 |
| 76 RenderWidgetHostImpl* widget() { return widget_.get(); } | 88 RenderWidgetHostImpl* widget() { return widget_.get(); } |
| 77 | 89 |
| 78 IPC::TestSink& ipc_sink() { | 90 IPC::TestSink& ipc_sink() { |
| 79 return static_cast<MockRenderProcessHost*>(widget()->GetProcess())->sink(); | 91 return static_cast<MockRenderProcessHost*>(widget()->GetProcess())->sink(); |
| 80 } | 92 } |
| 81 | 93 |
| 82 private: | 94 private: |
| 83 friend class ScopedTestingThread; | 95 friend class ScopedTestingThread; |
| 84 | 96 |
| 85 base::MessageLoopForUI message_loop_; | 97 base::MessageLoopForUI message_loop_; |
| 98 | |
| 99 // TaskScheduler is used by RenderWidgetHostImpl constructor. | |
| 100 base::test::ScopedTaskScheduler task_scheduler_; | |
| 101 | |
| 86 TestBrowserContext browser_context_; | 102 TestBrowserContext browser_context_; |
| 87 | 103 |
| 88 // Gets deleted when the last RWH in the "process" gets destroyed. | 104 // Gets deleted when the last RWH in the "process" gets destroyed. |
| 89 MockRenderProcessHostFactory process_factory_; | 105 MockRenderProcessHostFactory process_factory_; |
| 90 MockRenderWidgetHostDelegate delegate_; | 106 MockRenderWidgetHostDelegate delegate_; |
| 91 std::unique_ptr<RenderWidgetHostImpl> widget_; | 107 std::unique_ptr<RenderWidgetHostImpl> widget_; |
| 92 | 108 |
| 93 base::Thread thread_; | 109 base::Thread thread_; |
| 94 }; | 110 }; |
| 95 | 111 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 | 213 |
| 198 TEST_F(TextInputClientMacTest, TimeoutRectForRange) { | 214 TEST_F(TextInputClientMacTest, TimeoutRectForRange) { |
| 199 NSRect rect = service()->GetFirstRectForRange(widget(), NSMakeRange(0, 32)); | 215 NSRect rect = service()->GetFirstRectForRange(widget(), NSMakeRange(0, 32)); |
| 200 EXPECT_EQ(1U, ipc_sink().message_count()); | 216 EXPECT_EQ(1U, ipc_sink().message_count()); |
| 201 EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( | 217 EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( |
| 202 TextInputClientMsg_FirstRectForCharacterRange::ID)); | 218 TextInputClientMsg_FirstRectForCharacterRange::ID)); |
| 203 EXPECT_NSEQ(NSZeroRect, rect); | 219 EXPECT_NSEQ(NSZeroRect, rect); |
| 204 } | 220 } |
| 205 | 221 |
| 206 } // namespace content | 222 } // namespace content |
| OLD | NEW |