OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 10 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.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/web_contents_delegate.h" | 28 #include "content/public/browser/web_contents_delegate.h" |
29 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
30 #include "content/public/browser/web_ui_controller.h" | 30 #include "content/public/browser/web_ui_controller.h" |
31 #include "content/public/common/bindings_policy.h" | 31 #include "content/public/common/bindings_policy.h" |
32 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
33 #include "content/public/common/javascript_message_type.h" | 33 #include "content/public/common/javascript_message_type.h" |
34 #include "content/public/common/url_constants.h" | 34 #include "content/public/common/url_constants.h" |
35 #include "content/public/common/url_utils.h" | 35 #include "content/public/common/url_utils.h" |
| 36 #include "content/public/test/browser_test_utils.h" |
36 #include "content/public/test/mock_render_process_host.h" | 37 #include "content/public/test/mock_render_process_host.h" |
37 #include "content/public/test/test_notification_tracker.h" | 38 #include "content/public/test/test_notification_tracker.h" |
38 #include "content/test/test_content_browser_client.h" | 39 #include "content/test/test_content_browser_client.h" |
39 #include "content/test/test_content_client.h" | 40 #include "content/test/test_content_client.h" |
40 #include "content/test/test_render_frame_host.h" | 41 #include "content/test/test_render_frame_host.h" |
41 #include "content/test/test_render_view_host.h" | 42 #include "content/test/test_render_view_host.h" |
42 #include "content/test/test_web_contents.h" | 43 #include "content/test/test_web_contents.h" |
43 #include "net/base/load_flags.h" | 44 #include "net/base/load_flags.h" |
44 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
45 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 46 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 115 } |
115 | 116 |
116 bool is_closed() { return close_called_; } | 117 bool is_closed() { return close_called_; } |
117 | 118 |
118 private: | 119 private: |
119 DISALLOW_COPY_AND_ASSIGN(CloseWebContentsDelegate); | 120 DISALLOW_COPY_AND_ASSIGN(CloseWebContentsDelegate); |
120 | 121 |
121 bool close_called_; | 122 bool close_called_; |
122 }; | 123 }; |
123 | 124 |
124 // This observer keeps track of the last deleted RenderViewHost to avoid | |
125 // accessing it and causing use-after-free condition. | |
126 class RenderViewHostDeletedObserver : public WebContentsObserver { | |
127 public: | |
128 RenderViewHostDeletedObserver(RenderViewHost* rvh) | |
129 : WebContentsObserver(WebContents::FromRenderViewHost(rvh)), | |
130 process_id_(rvh->GetProcess()->GetID()), | |
131 routing_id_(rvh->GetRoutingID()), | |
132 deleted_(false) { | |
133 } | |
134 | |
135 void RenderViewDeleted(RenderViewHost* render_view_host) override { | |
136 if (render_view_host->GetProcess()->GetID() == process_id_ && | |
137 render_view_host->GetRoutingID() == routing_id_) { | |
138 deleted_ = true; | |
139 } | |
140 } | |
141 | |
142 bool deleted() { | |
143 return deleted_; | |
144 } | |
145 | |
146 private: | |
147 int process_id_; | |
148 int routing_id_; | |
149 bool deleted_; | |
150 | |
151 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver); | |
152 }; | |
153 | |
154 // This observer keeps track of the last created RenderFrameHost to allow tests | 125 // This observer keeps track of the last created RenderFrameHost to allow tests |
155 // to ensure that no RenderFrameHost objects are created when not expected. | 126 // to ensure that no RenderFrameHost objects are created when not expected. |
156 class RenderFrameHostCreatedObserver : public WebContentsObserver { | 127 class RenderFrameHostCreatedObserver : public WebContentsObserver { |
157 public: | 128 public: |
158 RenderFrameHostCreatedObserver(WebContents* web_contents) | 129 RenderFrameHostCreatedObserver(WebContents* web_contents) |
159 : WebContentsObserver(web_contents), | 130 : WebContentsObserver(web_contents), |
160 created_(false) { | 131 created_(false) { |
161 } | 132 } |
162 | 133 |
163 void RenderFrameCreated(RenderFrameHost* render_frame_host) override { | 134 void RenderFrameCreated(RenderFrameHost* render_frame_host) override { |
164 created_ = true; | 135 created_ = true; |
165 } | 136 } |
166 | 137 |
167 bool created() { | 138 bool created() { |
168 return created_; | 139 return created_; |
169 } | 140 } |
170 | 141 |
171 private: | 142 private: |
172 bool created_; | 143 bool created_; |
173 | 144 |
174 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostCreatedObserver); | 145 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostCreatedObserver); |
175 }; | 146 }; |
176 | 147 |
177 // This observer keeps track of the last deleted RenderFrameHost to avoid | |
178 // accessing it and causing use-after-free condition. | |
179 class RenderFrameHostDeletedObserver : public WebContentsObserver { | |
180 public: | |
181 RenderFrameHostDeletedObserver(RenderFrameHost* rfh) | |
182 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)), | |
183 process_id_(rfh->GetProcess()->GetID()), | |
184 routing_id_(rfh->GetRoutingID()), | |
185 deleted_(false) { | |
186 } | |
187 | |
188 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override { | |
189 if (render_frame_host->GetProcess()->GetID() == process_id_ && | |
190 render_frame_host->GetRoutingID() == routing_id_) { | |
191 deleted_ = true; | |
192 } | |
193 } | |
194 | |
195 bool deleted() { | |
196 return deleted_; | |
197 } | |
198 | |
199 private: | |
200 int process_id_; | |
201 int routing_id_; | |
202 bool deleted_; | |
203 | |
204 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver); | |
205 }; | |
206 | |
207 // This WebContents observer keep track of its RVH change. | 148 // This WebContents observer keep track of its RVH change. |
208 class RenderViewHostChangedObserver : public WebContentsObserver { | 149 class RenderViewHostChangedObserver : public WebContentsObserver { |
209 public: | 150 public: |
210 RenderViewHostChangedObserver(WebContents* web_contents) | 151 RenderViewHostChangedObserver(WebContents* web_contents) |
211 : WebContentsObserver(web_contents), host_changed_(false) {} | 152 : WebContentsObserver(web_contents), host_changed_(false) {} |
212 | 153 |
213 // WebContentsObserver. | 154 // WebContentsObserver. |
214 void RenderViewHostChanged(RenderViewHost* old_host, | 155 void RenderViewHostChanged(RenderViewHost* old_host, |
215 RenderViewHost* new_host) override { | 156 RenderViewHost* new_host) override { |
216 host_changed_ = true; | 157 host_changed_ = true; |
(...skipping 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2179 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2239 contents2->NavigateAndCommit(kUrl3); | 2180 contents2->NavigateAndCommit(kUrl3); |
2240 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); | 2181 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); |
2241 EXPECT_NE(nullptr, | 2182 EXPECT_NE(nullptr, |
2242 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); | 2183 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); |
2243 EXPECT_EQ(nullptr, | 2184 EXPECT_EQ(nullptr, |
2244 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); | 2185 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); |
2245 } | 2186 } |
2246 | 2187 |
2247 } // namespace content | 2188 } // namespace content |
OLD | NEW |