Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: content/public/test/mock_render_process_host.cc

Issue 1159183002: Improve process crash handling in RenderViewHost & mock RenderProcessHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile problem in webview_interactive_uitest.cc Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/test/mock_render_process_host.h" 5 #include "content/public/test/mock_render_process_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 15 matching lines...) Expand all
26 #include "content/public/browser/notification_types.h" 26 #include "content/public/browser/notification_types.h"
27 #include "content/public/browser/render_widget_host_iterator.h" 27 #include "content/public/browser/render_widget_host_iterator.h"
28 #include "content/public/browser/storage_partition.h" 28 #include "content/public/browser/storage_partition.h"
29 29
30 namespace content { 30 namespace content {
31 31
32 MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context) 32 MockRenderProcessHost::MockRenderProcessHost(BrowserContext* browser_context)
33 : bad_msg_count_(0), 33 : bad_msg_count_(0),
34 factory_(NULL), 34 factory_(NULL),
35 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), 35 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
36 has_connection_(false),
36 browser_context_(browser_context), 37 browser_context_(browser_context),
37 prev_routing_id_(0), 38 prev_routing_id_(0),
38 fast_shutdown_started_(false), 39 fast_shutdown_started_(false),
39 deletion_callback_called_(false), 40 deletion_callback_called_(false),
40 is_isolated_guest_(false) { 41 is_isolated_guest_(false) {
41 // Child process security operations can't be unit tested unless we add 42 // Child process security operations can't be unit tested unless we add
42 // ourselves as an existing child process. 43 // ourselves as an existing child process.
43 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID()); 44 ChildProcessSecurityPolicyImpl::GetInstance()->Add(GetID());
44 45
45 RenderProcessHostImpl::RegisterHost(GetID(), this); 46 RenderProcessHostImpl::RegisterHost(GetID(), this);
46 } 47 }
47 48
48 MockRenderProcessHost::~MockRenderProcessHost() { 49 MockRenderProcessHost::~MockRenderProcessHost() {
49 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID()); 50 ChildProcessSecurityPolicyImpl::GetInstance()->Remove(GetID());
50 if (factory_) 51 if (factory_)
51 factory_->Remove(this); 52 factory_->Remove(this);
52 53
53 // In unit tests, Cleanup() might not have been called. 54 // In unit tests, Cleanup() might not have been called.
54 if (!deletion_callback_called_) { 55 if (!deletion_callback_called_) {
55 FOR_EACH_OBSERVER(RenderProcessHostObserver, 56 FOR_EACH_OBSERVER(RenderProcessHostObserver,
56 observers_, 57 observers_,
57 RenderProcessHostDestroyed(this)); 58 RenderProcessHostDestroyed(this));
58 RenderProcessHostImpl::UnregisterHost(GetID()); 59 RenderProcessHostImpl::UnregisterHost(GetID());
59 } 60 }
60 } 61 }
61 62
62 void MockRenderProcessHost::SimulateCrash() { 63 void MockRenderProcessHost::SimulateCrash() {
64 has_connection_ = false;
63 RenderProcessHost::RendererClosedDetails details( 65 RenderProcessHost::RendererClosedDetails details(
64 base::TERMINATION_STATUS_PROCESS_CRASHED, 0); 66 base::TERMINATION_STATUS_PROCESS_CRASHED, 0);
65 NotificationService::current()->Notify( 67 NotificationService::current()->Notify(
66 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), 68 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this),
67 Details<RenderProcessHost::RendererClosedDetails>(&details)); 69 Details<RenderProcessHost::RendererClosedDetails>(&details));
68 70
71 FOR_EACH_OBSERVER(
72 RenderProcessHostObserver, observers_,
73 RenderProcessExited(this, details.status, details.exit_code));
74
69 // Send every routing ID a FrameHostMsg_RenderProcessGone message. To ensure a 75 // Send every routing ID a FrameHostMsg_RenderProcessGone message. To ensure a
70 // predictable order for unittests which may assert against the order, we sort 76 // predictable order for unittests which may assert against the order, we sort
71 // the listeners by descending routing ID, instead of using the arbitrary 77 // the listeners by descending routing ID, instead of using the arbitrary
72 // hash-map order like RenderProcessHostImpl. 78 // hash-map order like RenderProcessHostImpl.
73 std::vector<std::pair<int32, IPC::Listener*>> sorted_listeners_; 79 std::vector<std::pair<int32, IPC::Listener*>> sorted_listeners_;
74 IDMap<IPC::Listener>::iterator iter(&listeners_); 80 IDMap<IPC::Listener>::iterator iter(&listeners_);
75 while (!iter.IsAtEnd()) { 81 while (!iter.IsAtEnd()) {
76 sorted_listeners_.push_back( 82 sorted_listeners_.push_back(
77 std::make_pair(iter.GetCurrentKey(), iter.GetCurrentValue())); 83 std::make_pair(iter.GetCurrentKey(), iter.GetCurrentValue()));
78 iter.Advance(); 84 iter.Advance();
79 } 85 }
80 std::sort(sorted_listeners_.rbegin(), sorted_listeners_.rend()); 86 std::sort(sorted_listeners_.rbegin(), sorted_listeners_.rend());
81 87
82 for (auto& entry_pair : sorted_listeners_) { 88 for (auto& entry_pair : sorted_listeners_) {
83 entry_pair.second->OnMessageReceived(FrameHostMsg_RenderProcessGone( 89 entry_pair.second->OnMessageReceived(FrameHostMsg_RenderProcessGone(
84 entry_pair.first, static_cast<int>(details.status), details.exit_code)); 90 entry_pair.first, static_cast<int>(details.status), details.exit_code));
85 } 91 }
86 } 92 }
87 93
88 void MockRenderProcessHost::EnableSendQueue() { 94 void MockRenderProcessHost::EnableSendQueue() {
89 } 95 }
90 96
91 bool MockRenderProcessHost::Init() { 97 bool MockRenderProcessHost::Init() {
98 has_connection_ = true;
92 return true; 99 return true;
93 } 100 }
94 101
95 int MockRenderProcessHost::GetNextRoutingID() { 102 int MockRenderProcessHost::GetNextRoutingID() {
96 return ++prev_routing_id_; 103 return ++prev_routing_id_;
97 } 104 }
98 105
99 void MockRenderProcessHost::AddRoute( 106 void MockRenderProcessHost::AddRoute(
100 int32 routing_id, 107 int32 routing_id,
101 IPC::Listener* listener) { 108 IPC::Listener* listener) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 sink_.OnMessageReceived(*msg); 177 sink_.OnMessageReceived(*msg);
171 delete msg; 178 delete msg;
172 return true; 179 return true;
173 } 180 }
174 181
175 int MockRenderProcessHost::GetID() const { 182 int MockRenderProcessHost::GetID() const {
176 return id_; 183 return id_;
177 } 184 }
178 185
179 bool MockRenderProcessHost::HasConnection() const { 186 bool MockRenderProcessHost::HasConnection() const {
180 return true; 187 return has_connection_;
181 } 188 }
182 189
183 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) { 190 void MockRenderProcessHost::SetIgnoreInputEvents(bool ignore_input_events) {
184 } 191 }
185 192
186 bool MockRenderProcessHost::IgnoreInputEvents() const { 193 bool MockRenderProcessHost::IgnoreInputEvents() const {
187 return false; 194 return false;
188 } 195 }
189 196
190 void MockRenderProcessHost::Cleanup() { 197 void MockRenderProcessHost::Cleanup() {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin(); 345 for (ScopedVector<MockRenderProcessHost>::iterator it = processes_.begin();
339 it != processes_.end(); ++it) { 346 it != processes_.end(); ++it) {
340 if (*it == host) { 347 if (*it == host) {
341 processes_.weak_erase(it); 348 processes_.weak_erase(it);
342 break; 349 break;
343 } 350 }
344 } 351 }
345 } 352 }
346 353
347 } // content 354 } // content
OLDNEW
« no previous file with comments | « content/public/test/mock_render_process_host.h ('k') | content/public/test/test_renderer_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698