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" | |
12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
13 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
14 #include "base/test/scoped_task_scheduler.h" | 13 #include "base/test/scoped_task_environment.h" |
15 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
16 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
17 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 16 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
18 #include "content/browser/renderer_host/render_widget_host_impl.h" | 17 #include "content/browser/renderer_host/render_widget_host_impl.h" |
19 #include "content/browser/renderer_host/text_input_client_message_filter.h" | 18 #include "content/browser/renderer_host/text_input_client_message_filter.h" |
20 #include "content/common/text_input_client_messages.h" | 19 #include "content/common/text_input_client_messages.h" |
21 #include "content/public/test/mock_render_process_host.h" | 20 #include "content/public/test/mock_render_process_host.h" |
22 #include "content/public/test/test_browser_context.h" | 21 #include "content/public/test/test_browser_context.h" |
23 #include "ipc/ipc_test_sink.h" | 22 #include "ipc/ipc_test_sink.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 15 matching lines...) Expand all Loading... |
40 void Paste() override {} | 39 void Paste() override {} |
41 void SelectAll() override {} | 40 void SelectAll() override {} |
42 }; | 41 }; |
43 | 42 |
44 // This test does not test the WebKit side of the dictionary system (which | 43 // This test does not test the WebKit side of the dictionary system (which |
45 // performs the actual data fetching), but rather this just tests that the | 44 // performs the actual data fetching), but rather this just tests that the |
46 // service's signaling system works. | 45 // service's signaling system works. |
47 class TextInputClientMacTest : public testing::Test { | 46 class TextInputClientMacTest : public testing::Test { |
48 public: | 47 public: |
49 TextInputClientMacTest() | 48 TextInputClientMacTest() |
50 : task_scheduler_(&message_loop_), | 49 : scoped_task_environment_( |
| 50 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
51 browser_context_(), | 51 browser_context_(), |
52 process_factory_(), | 52 process_factory_(), |
53 delegate_(), | 53 delegate_(), |
54 thread_("TextInputClientMacTestThread") { | 54 thread_("TextInputClientMacTestThread") { |
55 RenderProcessHost* rph = | 55 RenderProcessHost* rph = |
56 process_factory_.CreateRenderProcessHost(&browser_context_, nullptr); | 56 process_factory_.CreateRenderProcessHost(&browser_context_, nullptr); |
57 int32_t routing_id = rph->GetNextRoutingID(); | 57 int32_t routing_id = rph->GetNextRoutingID(); |
58 widget_.reset(new RenderWidgetHostImpl(&delegate_, rph, routing_id, false)); | 58 widget_.reset(new RenderWidgetHostImpl(&delegate_, rph, routing_id, false)); |
59 } | 59 } |
60 | 60 |
(...skipping 26 matching lines...) Expand all Loading... |
87 | 87 |
88 RenderWidgetHostImpl* widget() { return widget_.get(); } | 88 RenderWidgetHostImpl* widget() { return widget_.get(); } |
89 | 89 |
90 IPC::TestSink& ipc_sink() { | 90 IPC::TestSink& ipc_sink() { |
91 return static_cast<MockRenderProcessHost*>(widget()->GetProcess())->sink(); | 91 return static_cast<MockRenderProcessHost*>(widget()->GetProcess())->sink(); |
92 } | 92 } |
93 | 93 |
94 private: | 94 private: |
95 friend class ScopedTestingThread; | 95 friend class ScopedTestingThread; |
96 | 96 |
97 base::MessageLoopForUI message_loop_; | |
98 | |
99 // TaskScheduler is used by RenderWidgetHostImpl constructor. | 97 // TaskScheduler is used by RenderWidgetHostImpl constructor. |
100 base::test::ScopedTaskScheduler task_scheduler_; | 98 base::test::ScopedTaskEnvironment scoped_task_environment_; |
101 | 99 |
102 TestBrowserContext browser_context_; | 100 TestBrowserContext browser_context_; |
103 | 101 |
104 // Gets deleted when the last RWH in the "process" gets destroyed. | 102 // Gets deleted when the last RWH in the "process" gets destroyed. |
105 MockRenderProcessHostFactory process_factory_; | 103 MockRenderProcessHostFactory process_factory_; |
106 MockRenderWidgetHostDelegate delegate_; | 104 MockRenderWidgetHostDelegate delegate_; |
107 std::unique_ptr<RenderWidgetHostImpl> widget_; | 105 std::unique_ptr<RenderWidgetHostImpl> widget_; |
108 | 106 |
109 base::Thread thread_; | 107 base::Thread thread_; |
110 }; | 108 }; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 211 |
214 TEST_F(TextInputClientMacTest, TimeoutRectForRange) { | 212 TEST_F(TextInputClientMacTest, TimeoutRectForRange) { |
215 NSRect rect = service()->GetFirstRectForRange(widget(), NSMakeRange(0, 32)); | 213 NSRect rect = service()->GetFirstRectForRange(widget(), NSMakeRange(0, 32)); |
216 EXPECT_EQ(1U, ipc_sink().message_count()); | 214 EXPECT_EQ(1U, ipc_sink().message_count()); |
217 EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( | 215 EXPECT_TRUE(ipc_sink().GetUniqueMessageMatching( |
218 TextInputClientMsg_FirstRectForCharacterRange::ID)); | 216 TextInputClientMsg_FirstRectForCharacterRange::ID)); |
219 EXPECT_NSEQ(NSZeroRect, rect); | 217 EXPECT_NSEQ(NSZeroRect, rect); |
220 } | 218 } |
221 | 219 |
222 } // namespace content | 220 } // namespace content |
OLD | NEW |