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

Side by Side Diff: content/browser/frame_host/render_frame_host_manager_unittest.cc

Issue 1155993003: Fix accessibility with out-of-process iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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/frame_host/cross_site_transferring_request.h" 10 #include "content/browser/frame_host/cross_site_transferring_request.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/public/browser/render_process_host.h" 25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/render_widget_host_iterator.h" 26 #include "content/public/browser/render_widget_host_iterator.h"
27 #include "content/public/browser/web_contents_delegate.h" 27 #include "content/public/browser/web_contents_delegate.h"
28 #include "content/public/browser/web_contents_observer.h" 28 #include "content/public/browser/web_contents_observer.h"
29 #include "content/public/browser/web_ui_controller.h" 29 #include "content/public/browser/web_ui_controller.h"
30 #include "content/public/common/bindings_policy.h" 30 #include "content/public/common/bindings_policy.h"
31 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
32 #include "content/public/common/javascript_message_type.h" 32 #include "content/public/common/javascript_message_type.h"
33 #include "content/public/common/url_constants.h" 33 #include "content/public/common/url_constants.h"
34 #include "content/public/common/url_utils.h" 34 #include "content/public/common/url_utils.h"
35 #include "content/public/test/browser_test_utils.h"
35 #include "content/public/test/mock_render_process_host.h" 36 #include "content/public/test/mock_render_process_host.h"
36 #include "content/public/test/test_notification_tracker.h" 37 #include "content/public/test/test_notification_tracker.h"
37 #include "content/test/test_content_browser_client.h" 38 #include "content/test/test_content_browser_client.h"
38 #include "content/test/test_content_client.h" 39 #include "content/test/test_content_client.h"
39 #include "content/test/test_render_frame_host.h" 40 #include "content/test/test_render_frame_host.h"
40 #include "content/test/test_render_view_host.h" 41 #include "content/test/test_render_view_host.h"
41 #include "content/test/test_web_contents.h" 42 #include "content/test/test_web_contents.h"
42 #include "net/base/load_flags.h" 43 #include "net/base/load_flags.h"
43 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
44 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 45 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 114 }
114 115
115 bool is_closed() { return close_called_; } 116 bool is_closed() { return close_called_; }
116 117
117 private: 118 private:
118 DISALLOW_COPY_AND_ASSIGN(CloseWebContentsDelegate); 119 DISALLOW_COPY_AND_ASSIGN(CloseWebContentsDelegate);
119 120
120 bool close_called_; 121 bool close_called_;
121 }; 122 };
122 123
123 // This observer keeps track of the last deleted RenderViewHost to avoid
124 // accessing it and causing use-after-free condition.
125 class RenderViewHostDeletedObserver : public WebContentsObserver {
126 public:
127 RenderViewHostDeletedObserver(RenderViewHost* rvh)
128 : WebContentsObserver(WebContents::FromRenderViewHost(rvh)),
129 process_id_(rvh->GetProcess()->GetID()),
130 routing_id_(rvh->GetRoutingID()),
131 deleted_(false) {
132 }
133
134 void RenderViewDeleted(RenderViewHost* render_view_host) override {
135 if (render_view_host->GetProcess()->GetID() == process_id_ &&
136 render_view_host->GetRoutingID() == routing_id_) {
137 deleted_ = true;
138 }
139 }
140
141 bool deleted() {
142 return deleted_;
143 }
144
145 private:
146 int process_id_;
147 int routing_id_;
148 bool deleted_;
149
150 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver);
151 };
152
153 // This observer keeps track of the last created RenderFrameHost to allow tests 124 // This observer keeps track of the last created RenderFrameHost to allow tests
154 // to ensure that no RenderFrameHost objects are created when not expected. 125 // to ensure that no RenderFrameHost objects are created when not expected.
155 class RenderFrameHostCreatedObserver : public WebContentsObserver { 126 class RenderFrameHostCreatedObserver : public WebContentsObserver {
156 public: 127 public:
157 RenderFrameHostCreatedObserver(WebContents* web_contents) 128 RenderFrameHostCreatedObserver(WebContents* web_contents)
158 : WebContentsObserver(web_contents), 129 : WebContentsObserver(web_contents),
159 created_(false) { 130 created_(false) {
160 } 131 }
161 132
162 void RenderFrameCreated(RenderFrameHost* render_frame_host) override { 133 void RenderFrameCreated(RenderFrameHost* render_frame_host) override {
163 created_ = true; 134 created_ = true;
164 } 135 }
165 136
166 bool created() { 137 bool created() {
167 return created_; 138 return created_;
168 } 139 }
169 140
170 private: 141 private:
171 bool created_; 142 bool created_;
172 143
173 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostCreatedObserver); 144 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostCreatedObserver);
174 }; 145 };
175 146
176 // This observer keeps track of the last deleted RenderFrameHost to avoid
177 // accessing it and causing use-after-free condition.
178 class RenderFrameHostDeletedObserver : public WebContentsObserver {
179 public:
180 RenderFrameHostDeletedObserver(RenderFrameHost* rfh)
181 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)),
182 process_id_(rfh->GetProcess()->GetID()),
183 routing_id_(rfh->GetRoutingID()),
184 deleted_(false) {
185 }
186
187 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override {
188 if (render_frame_host->GetProcess()->GetID() == process_id_ &&
189 render_frame_host->GetRoutingID() == routing_id_) {
190 deleted_ = true;
191 }
192 }
193
194 bool deleted() {
195 return deleted_;
196 }
197
198 private:
199 int process_id_;
200 int routing_id_;
201 bool deleted_;
202
203 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostDeletedObserver);
204 };
205
206 // This WebContents observer keep track of its RVH change. 147 // This WebContents observer keep track of its RVH change.
207 class RenderViewHostChangedObserver : public WebContentsObserver { 148 class RenderViewHostChangedObserver : public WebContentsObserver {
208 public: 149 public:
209 RenderViewHostChangedObserver(WebContents* web_contents) 150 RenderViewHostChangedObserver(WebContents* web_contents)
210 : WebContentsObserver(web_contents), host_changed_(false) {} 151 : WebContentsObserver(web_contents), host_changed_(false) {}
211 152
212 // WebContentsObserver. 153 // WebContentsObserver.
213 void RenderViewHostChanged(RenderViewHost* old_host, 154 void RenderViewHostChanged(RenderViewHost* old_host,
214 RenderViewHost* new_host) override { 155 RenderViewHost* new_host) override {
215 host_changed_ = true; 156 host_changed_ = true;
(...skipping 1932 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive()); 2089 EXPECT_FALSE(contents2->GetMainFrame()->IsRenderFrameLive());
2149 contents2->NavigateAndCommit(kUrl3); 2090 contents2->NavigateAndCommit(kUrl3);
2150 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive()); 2091 EXPECT_TRUE(contents2->GetMainFrame()->IsRenderFrameLive());
2151 EXPECT_NE(nullptr, 2092 EXPECT_NE(nullptr,
2152 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance())); 2093 iframe->GetRenderFrameProxyHost(contents1->GetSiteInstance()));
2153 EXPECT_EQ(nullptr, 2094 EXPECT_EQ(nullptr,
2154 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance())); 2095 iframe->GetRenderFrameProxyHost(contents2->GetSiteInstance()));
2155 } 2096 }
2156 2097
2157 } // namespace content 2098 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698