| 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/frame_host/cross_site_transferring_request.h" | 10 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 : should_create_webui_(false) { | 52 : should_create_webui_(false) { |
| 53 } | 53 } |
| 54 virtual ~RenderFrameHostManagerTestWebUIControllerFactory() {} | 54 virtual ~RenderFrameHostManagerTestWebUIControllerFactory() {} |
| 55 | 55 |
| 56 void set_should_create_webui(bool should_create_webui) { | 56 void set_should_create_webui(bool should_create_webui) { |
| 57 should_create_webui_ = should_create_webui; | 57 should_create_webui_ = should_create_webui; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // WebUIFactory implementation. | 60 // WebUIFactory implementation. |
| 61 virtual WebUIController* CreateWebUIControllerForURL( | 61 virtual WebUIController* CreateWebUIControllerForURL( |
| 62 WebUI* web_ui, const GURL& url) const OVERRIDE { | 62 WebUI* web_ui, const GURL& url) const override { |
| 63 if (!(should_create_webui_ && HasWebUIScheme(url))) | 63 if (!(should_create_webui_ && HasWebUIScheme(url))) |
| 64 return NULL; | 64 return NULL; |
| 65 return new WebUIController(web_ui); | 65 return new WebUIController(web_ui); |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 68 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
| 69 const GURL& url) const OVERRIDE { | 69 const GURL& url) const override { |
| 70 return WebUI::kNoWebUI; | 70 return WebUI::kNoWebUI; |
| 71 } | 71 } |
| 72 | 72 |
| 73 virtual bool UseWebUIForURL(BrowserContext* browser_context, | 73 virtual bool UseWebUIForURL(BrowserContext* browser_context, |
| 74 const GURL& url) const OVERRIDE { | 74 const GURL& url) const override { |
| 75 return HasWebUIScheme(url); | 75 return HasWebUIScheme(url); |
| 76 } | 76 } |
| 77 | 77 |
| 78 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, | 78 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
| 79 const GURL& url) const OVERRIDE { | 79 const GURL& url) const override { |
| 80 return HasWebUIScheme(url); | 80 return HasWebUIScheme(url); |
| 81 } | 81 } |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 bool should_create_webui_; | 84 bool should_create_webui_; |
| 85 | 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory); | 86 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostManagerTestWebUIControllerFactory); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate { | 89 class BeforeUnloadFiredWebContentsDelegate : public WebContentsDelegate { |
| 90 public: | 90 public: |
| 91 BeforeUnloadFiredWebContentsDelegate() {} | 91 BeforeUnloadFiredWebContentsDelegate() {} |
| 92 virtual ~BeforeUnloadFiredWebContentsDelegate() {} | 92 virtual ~BeforeUnloadFiredWebContentsDelegate() {} |
| 93 | 93 |
| 94 virtual void BeforeUnloadFired(WebContents* web_contents, | 94 virtual void BeforeUnloadFired(WebContents* web_contents, |
| 95 bool proceed, | 95 bool proceed, |
| 96 bool* proceed_to_fire_unload) OVERRIDE { | 96 bool* proceed_to_fire_unload) override { |
| 97 *proceed_to_fire_unload = proceed; | 97 *proceed_to_fire_unload = proceed; |
| 98 } | 98 } |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 DISALLOW_COPY_AND_ASSIGN(BeforeUnloadFiredWebContentsDelegate); | 101 DISALLOW_COPY_AND_ASSIGN(BeforeUnloadFiredWebContentsDelegate); |
| 102 }; | 102 }; |
| 103 | 103 |
| 104 // This observer keeps track of the last deleted RenderViewHost to avoid | 104 // This observer keeps track of the last deleted RenderViewHost to avoid |
| 105 // accessing it and causing use-after-free condition. | 105 // accessing it and causing use-after-free condition. |
| 106 class RenderViewHostDeletedObserver : public WebContentsObserver { | 106 class RenderViewHostDeletedObserver : public WebContentsObserver { |
| 107 public: | 107 public: |
| 108 RenderViewHostDeletedObserver(RenderViewHost* rvh) | 108 RenderViewHostDeletedObserver(RenderViewHost* rvh) |
| 109 : WebContentsObserver(WebContents::FromRenderViewHost(rvh)), | 109 : WebContentsObserver(WebContents::FromRenderViewHost(rvh)), |
| 110 process_id_(rvh->GetProcess()->GetID()), | 110 process_id_(rvh->GetProcess()->GetID()), |
| 111 routing_id_(rvh->GetRoutingID()), | 111 routing_id_(rvh->GetRoutingID()), |
| 112 deleted_(false) { | 112 deleted_(false) { |
| 113 } | 113 } |
| 114 | 114 |
| 115 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE { | 115 virtual void RenderViewDeleted(RenderViewHost* render_view_host) override { |
| 116 if (render_view_host->GetProcess()->GetID() == process_id_ && | 116 if (render_view_host->GetProcess()->GetID() == process_id_ && |
| 117 render_view_host->GetRoutingID() == routing_id_) { | 117 render_view_host->GetRoutingID() == routing_id_) { |
| 118 deleted_ = true; | 118 deleted_ = true; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool deleted() { | 122 bool deleted() { |
| 123 return deleted_; | 123 return deleted_; |
| 124 } | 124 } |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 int process_id_; | 127 int process_id_; |
| 128 int routing_id_; | 128 int routing_id_; |
| 129 bool deleted_; | 129 bool deleted_; |
| 130 | 130 |
| 131 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver); | 131 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDeletedObserver); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 // This observer keeps track of the last deleted RenderFrameHost to avoid | 134 // This observer keeps track of the last deleted RenderFrameHost to avoid |
| 135 // accessing it and causing use-after-free condition. | 135 // accessing it and causing use-after-free condition. |
| 136 class RenderFrameHostDeletedObserver : public WebContentsObserver { | 136 class RenderFrameHostDeletedObserver : public WebContentsObserver { |
| 137 public: | 137 public: |
| 138 RenderFrameHostDeletedObserver(RenderFrameHost* rfh) | 138 RenderFrameHostDeletedObserver(RenderFrameHost* rfh) |
| 139 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)), | 139 : WebContentsObserver(WebContents::FromRenderFrameHost(rfh)), |
| 140 process_id_(rfh->GetProcess()->GetID()), | 140 process_id_(rfh->GetProcess()->GetID()), |
| 141 routing_id_(rfh->GetRoutingID()), | 141 routing_id_(rfh->GetRoutingID()), |
| 142 deleted_(false) { | 142 deleted_(false) { |
| 143 } | 143 } |
| 144 | 144 |
| 145 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE { | 145 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) override { |
| 146 if (render_frame_host->GetProcess()->GetID() == process_id_ && | 146 if (render_frame_host->GetProcess()->GetID() == process_id_ && |
| 147 render_frame_host->GetRoutingID() == routing_id_) { | 147 render_frame_host->GetRoutingID() == routing_id_) { |
| 148 deleted_ = true; | 148 deleted_ = true; |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool deleted() { | 152 bool deleted() { |
| 153 return deleted_; | 153 return deleted_; |
| 154 } | 154 } |
| 155 | 155 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 168 // sent. The test is successful if the event is not observed. | 168 // sent. The test is successful if the event is not observed. |
| 169 // See http://crbug.com/351815 | 169 // See http://crbug.com/351815 |
| 170 class PluginFaviconMessageObserver : public WebContentsObserver { | 170 class PluginFaviconMessageObserver : public WebContentsObserver { |
| 171 public: | 171 public: |
| 172 PluginFaviconMessageObserver(WebContents* web_contents) | 172 PluginFaviconMessageObserver(WebContents* web_contents) |
| 173 : WebContentsObserver(web_contents), | 173 : WebContentsObserver(web_contents), |
| 174 plugin_crashed_(false), | 174 plugin_crashed_(false), |
| 175 favicon_received_(false) { } | 175 favicon_received_(false) { } |
| 176 | 176 |
| 177 virtual void PluginCrashed(const base::FilePath& plugin_path, | 177 virtual void PluginCrashed(const base::FilePath& plugin_path, |
| 178 base::ProcessId plugin_pid) OVERRIDE { | 178 base::ProcessId plugin_pid) override { |
| 179 plugin_crashed_ = true; | 179 plugin_crashed_ = true; |
| 180 } | 180 } |
| 181 | 181 |
| 182 virtual void DidUpdateFaviconURL( | 182 virtual void DidUpdateFaviconURL( |
| 183 const std::vector<FaviconURL>& candidates) OVERRIDE { | 183 const std::vector<FaviconURL>& candidates) override { |
| 184 favicon_received_ = true; | 184 favicon_received_ = true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 bool plugin_crashed() { | 187 bool plugin_crashed() { |
| 188 return plugin_crashed_; | 188 return plugin_crashed_; |
| 189 } | 189 } |
| 190 | 190 |
| 191 bool favicon_received() { | 191 bool favicon_received() { |
| 192 return favicon_received_; | 192 return favicon_received_; |
| 193 } | 193 } |
| 194 | 194 |
| 195 private: | 195 private: |
| 196 bool plugin_crashed_; | 196 bool plugin_crashed_; |
| 197 bool favicon_received_; | 197 bool favicon_received_; |
| 198 | 198 |
| 199 DISALLOW_COPY_AND_ASSIGN(PluginFaviconMessageObserver); | 199 DISALLOW_COPY_AND_ASSIGN(PluginFaviconMessageObserver); |
| 200 }; | 200 }; |
| 201 | 201 |
| 202 // Ensures that RenderFrameDeleted and RenderFrameCreated are called in a | 202 // Ensures that RenderFrameDeleted and RenderFrameCreated are called in a |
| 203 // consistent manner. | 203 // consistent manner. |
| 204 class FrameLifetimeConsistencyChecker : public WebContentsObserver { | 204 class FrameLifetimeConsistencyChecker : public WebContentsObserver { |
| 205 public: | 205 public: |
| 206 explicit FrameLifetimeConsistencyChecker(WebContentsImpl* web_contents) | 206 explicit FrameLifetimeConsistencyChecker(WebContentsImpl* web_contents) |
| 207 : WebContentsObserver(web_contents) { | 207 : WebContentsObserver(web_contents) { |
| 208 RenderViewCreated(web_contents->GetRenderViewHost()); | 208 RenderViewCreated(web_contents->GetRenderViewHost()); |
| 209 RenderFrameCreated(web_contents->GetMainFrame()); | 209 RenderFrameCreated(web_contents->GetMainFrame()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE { | 212 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) override { |
| 213 std::pair<int, int> routing_pair = | 213 std::pair<int, int> routing_pair = |
| 214 std::make_pair(render_frame_host->GetProcess()->GetID(), | 214 std::make_pair(render_frame_host->GetProcess()->GetID(), |
| 215 render_frame_host->GetRoutingID()); | 215 render_frame_host->GetRoutingID()); |
| 216 bool was_live_already = !live_routes_.insert(routing_pair).second; | 216 bool was_live_already = !live_routes_.insert(routing_pair).second; |
| 217 bool was_used_before = deleted_routes_.count(routing_pair) != 0; | 217 bool was_used_before = deleted_routes_.count(routing_pair) != 0; |
| 218 | 218 |
| 219 if (was_live_already) { | 219 if (was_live_already) { |
| 220 FAIL() << "RenderFrameCreated called more than once for routing pair: " | 220 FAIL() << "RenderFrameCreated called more than once for routing pair: " |
| 221 << Format(render_frame_host); | 221 << Format(render_frame_host); |
| 222 } else if (was_used_before) { | 222 } else if (was_used_before) { |
| 223 FAIL() << "RenderFrameCreated called for routing pair " | 223 FAIL() << "RenderFrameCreated called for routing pair " |
| 224 << Format(render_frame_host) << " that was previously deleted."; | 224 << Format(render_frame_host) << " that was previously deleted."; |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE { | 228 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) override { |
| 229 std::pair<int, int> routing_pair = | 229 std::pair<int, int> routing_pair = |
| 230 std::make_pair(render_frame_host->GetProcess()->GetID(), | 230 std::make_pair(render_frame_host->GetProcess()->GetID(), |
| 231 render_frame_host->GetRoutingID()); | 231 render_frame_host->GetRoutingID()); |
| 232 bool was_live = live_routes_.erase(routing_pair); | 232 bool was_live = live_routes_.erase(routing_pair); |
| 233 bool was_dead_already = !deleted_routes_.insert(routing_pair).second; | 233 bool was_dead_already = !deleted_routes_.insert(routing_pair).second; |
| 234 | 234 |
| 235 if (was_dead_already) { | 235 if (was_dead_already) { |
| 236 FAIL() << "RenderFrameDeleted called more than once for routing pair " | 236 FAIL() << "RenderFrameDeleted called more than once for routing pair " |
| 237 << Format(render_frame_host); | 237 << Format(render_frame_host); |
| 238 } else if (!was_live) { | 238 } else if (!was_live) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 252 } | 252 } |
| 253 std::set<std::pair<int, int> > live_routes_; | 253 std::set<std::pair<int, int> > live_routes_; |
| 254 std::set<std::pair<int, int> > deleted_routes_; | 254 std::set<std::pair<int, int> > deleted_routes_; |
| 255 }; | 255 }; |
| 256 | 256 |
| 257 } // namespace | 257 } // namespace |
| 258 | 258 |
| 259 class RenderFrameHostManagerTest | 259 class RenderFrameHostManagerTest |
| 260 : public RenderViewHostImplTestHarness { | 260 : public RenderViewHostImplTestHarness { |
| 261 public: | 261 public: |
| 262 virtual void SetUp() OVERRIDE { | 262 virtual void SetUp() override { |
| 263 RenderViewHostImplTestHarness::SetUp(); | 263 RenderViewHostImplTestHarness::SetUp(); |
| 264 WebUIControllerFactory::RegisterFactory(&factory_); | 264 WebUIControllerFactory::RegisterFactory(&factory_); |
| 265 lifetime_checker_.reset(new FrameLifetimeConsistencyChecker(contents())); | 265 lifetime_checker_.reset(new FrameLifetimeConsistencyChecker(contents())); |
| 266 } | 266 } |
| 267 | 267 |
| 268 virtual void TearDown() OVERRIDE { | 268 virtual void TearDown() override { |
| 269 lifetime_checker_.reset(); | 269 lifetime_checker_.reset(); |
| 270 RenderViewHostImplTestHarness::TearDown(); | 270 RenderViewHostImplTestHarness::TearDown(); |
| 271 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); | 271 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void set_should_create_webui(bool should_create_webui) { | 274 void set_should_create_webui(bool should_create_webui) { |
| 275 factory_.set_should_create_webui(should_create_webui); | 275 factory_.set_should_create_webui(should_create_webui); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void NavigateActiveAndCommit(const GURL& url) { | 278 void NavigateActiveAndCommit(const GURL& url) { |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 // http://crbug.com/259859. | 663 // http://crbug.com/259859. |
| 664 class RenderViewHostDestroyer : public WebContentsObserver { | 664 class RenderViewHostDestroyer : public WebContentsObserver { |
| 665 public: | 665 public: |
| 666 RenderViewHostDestroyer(RenderViewHost* render_view_host, | 666 RenderViewHostDestroyer(RenderViewHost* render_view_host, |
| 667 WebContents* web_contents) | 667 WebContents* web_contents) |
| 668 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), | 668 : WebContentsObserver(WebContents::FromRenderViewHost(render_view_host)), |
| 669 render_view_host_(render_view_host), | 669 render_view_host_(render_view_host), |
| 670 web_contents_(web_contents) {} | 670 web_contents_(web_contents) {} |
| 671 | 671 |
| 672 virtual void RenderViewDeleted( | 672 virtual void RenderViewDeleted( |
| 673 RenderViewHost* render_view_host) OVERRIDE { | 673 RenderViewHost* render_view_host) override { |
| 674 if (render_view_host == render_view_host_) | 674 if (render_view_host == render_view_host_) |
| 675 delete web_contents_; | 675 delete web_contents_; |
| 676 } | 676 } |
| 677 | 677 |
| 678 private: | 678 private: |
| 679 RenderViewHost* render_view_host_; | 679 RenderViewHost* render_view_host_; |
| 680 WebContents* web_contents_; | 680 WebContents* web_contents_; |
| 681 | 681 |
| 682 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDestroyer); | 682 DISALLOW_COPY_AND_ASSIGN(RenderViewHostDestroyer); |
| 683 }; | 683 }; |
| (...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1692 pending_rfh->GetSiteInstance()->increment_active_frame_count(); | 1692 pending_rfh->GetSiteInstance()->increment_active_frame_count(); |
| 1693 | 1693 |
| 1694 contents()->GetMainFrame()->OnMessageReceived( | 1694 contents()->GetMainFrame()->OnMessageReceived( |
| 1695 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); | 1695 FrameHostMsg_BeforeUnload_ACK(0, false, now, now)); |
| 1696 EXPECT_FALSE(contents()->cross_navigation_pending()); | 1696 EXPECT_FALSE(contents()->cross_navigation_pending()); |
| 1697 EXPECT_FALSE(rfh_deleted_observer.deleted()); | 1697 EXPECT_FALSE(rfh_deleted_observer.deleted()); |
| 1698 } | 1698 } |
| 1699 } | 1699 } |
| 1700 | 1700 |
| 1701 } // namespace content | 1701 } // namespace content |
| OLD | NEW |