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

Side by Side Diff: content/renderer/render_view_browsertest.cc

Issue 2541073002: Fix UaF in RenderFrameImpl::OnBeforeUnload. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <tuple> 7 #include <tuple>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 request_params.pending_history_list_offset = 2; 2178 request_params.pending_history_list_offset = 2;
2179 frame()->Navigate(CommonNavigationParams(), StartNavigationParams(), 2179 frame()->Navigate(CommonNavigationParams(), StartNavigationParams(),
2180 request_params); 2180 request_params);
2181 2181
2182 // The history list in RenderView should have been updated. 2182 // The history list in RenderView should have been updated.
2183 EXPECT_EQ(1, view()->historyBackListCount()); 2183 EXPECT_EQ(1, view()->historyBackListCount());
2184 EXPECT_EQ(2, view()->historyBackListCount() + 2184 EXPECT_EQ(2, view()->historyBackListCount() +
2185 view()->historyForwardListCount() + 1); 2185 view()->historyForwardListCount() + 1);
2186 } 2186 }
2187 2187
2188 // IPC Listener that runs a callback when a console.log() is executed from
2189 // javascript.
2190 class ConsoleCallbackFilter : public IPC::Listener {
2191 public:
2192 explicit ConsoleCallbackFilter(
2193 base::Callback<void(const base::string16&)> callback)
2194 : callback_(callback) {}
2195
2196 bool OnMessageReceived(const IPC::Message& msg) override {
2197 bool handled = true;
2198 IPC_BEGIN_MESSAGE_MAP(ConsoleCallbackFilter, msg)
2199 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAddMessageToConsole,
2200 OnDidAddMessageToConsole)
2201 IPC_MESSAGE_UNHANDLED(handled = false)
2202 IPC_END_MESSAGE_MAP()
2203 return handled;
2204 }
2205
2206 void OnDidAddMessageToConsole(int32_t,
2207 const base::string16& message,
2208 int32_t,
2209 const base::string16&) {
2210 callback_.Run(message);
2211 }
2212
2213 private:
2214 base::Callback<void(const base::string16&)> callback_;
2215 };
2216
2217 // Tests that there's no UaF after dispatchBeforeUnloadEvent.
2218 // See https://crbug.com/666714.
2219 TEST_F(RenderViewImplTest, DispatchBeforeUnloadCanDetachFrame) {
2220 LoadHTML(
2221 "<script>window.onbeforeunload = function() { "
2222 "window.console.log('OnBeforeUnload called'); }</script>");
2223
2224 // Creates a callback that swaps the frame when the 'OnBeforeUnload called'
2225 // log is printed from the beforeunload handler.
2226 std::unique_ptr<ConsoleCallbackFilter> callback_filter(
2227 new ConsoleCallbackFilter(base::Bind(
2228 [](RenderFrameImpl* frame, const base::string16& msg) {
2229 // Makes sure this happens during the beforeunload handler.
2230 EXPECT_EQ(base::UTF8ToUTF16("OnBeforeUnload called"), msg);
2231
2232 // Swaps the main frame.
2233 frame->OnMessageReceived(FrameMsg_SwapOut(
2234 frame->GetRoutingID(), 1, false, FrameReplicationState()));
2235 },
2236 base::Unretained(frame()))));
2237 render_thread_->sink().AddFilter(callback_filter.get());
2238
2239 // Simulates a BeforeUnload IPC received from the browser.
2240 frame()->OnMessageReceived(
2241 FrameMsg_BeforeUnload(frame()->GetRoutingID(), false));
2242
2243 render_thread_->sink().RemoveFilter(callback_filter.get());
2244 }
2245
2188 TEST_F(RenderViewImplBlinkSettingsTest, Default) { 2246 TEST_F(RenderViewImplBlinkSettingsTest, Default) {
2189 DoSetUp(); 2247 DoSetUp();
2190 EXPECT_FALSE(settings()->viewportEnabled()); 2248 EXPECT_FALSE(settings()->viewportEnabled());
2191 } 2249 }
2192 2250
2193 TEST_F(RenderViewImplBlinkSettingsTest, CommandLine) { 2251 TEST_F(RenderViewImplBlinkSettingsTest, CommandLine) {
2194 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2252 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2195 switches::kBlinkSettings, 2253 switches::kBlinkSettings,
2196 "multiTargetTapNotificationEnabled=true,viewportEnabled=true"); 2254 "multiTargetTapNotificationEnabled=true,viewportEnabled=true");
2197 DoSetUp(); 2255 DoSetUp();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 ExpectPauseAndResume(3); 2550 ExpectPauseAndResume(3);
2493 blink::WebScriptSource source2( 2551 blink::WebScriptSource source2(
2494 WebString::fromUTF8("function func2() { func1(); }; func2();")); 2552 WebString::fromUTF8("function func2() { func1(); }; func2();"));
2495 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); 2553 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1);
2496 2554
2497 EXPECT_FALSE(IsPaused()); 2555 EXPECT_FALSE(IsPaused());
2498 Detach(); 2556 Detach();
2499 } 2557 }
2500 2558
2501 } // namespace content 2559 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698