Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 class ConsoleCallbackFilter : public IPC::Listener { | |
| 2189 public: | |
| 2190 explicit ConsoleCallbackFilter( | |
| 2191 base::Callback<void(const base::string16&)> callback) | |
| 2192 : callback_(callback) {} | |
| 2193 | |
| 2194 bool OnMessageReceived(const IPC::Message& msg) override { | |
| 2195 bool handled = true; | |
| 2196 IPC_BEGIN_MESSAGE_MAP(ConsoleCallbackFilter, msg) | |
| 2197 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAddMessageToConsole, | |
| 2198 OnDidAddMessageToConsole) | |
| 2199 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 2200 IPC_END_MESSAGE_MAP() | |
| 2201 return handled; | |
| 2202 } | |
| 2203 | |
| 2204 void OnDidAddMessageToConsole(int32_t, | |
| 2205 const base::string16& message, | |
| 2206 int32_t, | |
| 2207 const base::string16&) { | |
| 2208 callback_.Run(message); | |
| 2209 } | |
| 2210 | |
| 2211 private: | |
| 2212 base::Callback<void(const base::string16&)> callback_; | |
| 2213 }; | |
| 2214 | |
| 2215 // Tests that there's no UaF after dispatchBeforeUnloadEvent. | |
| 2216 // See https://crbug.com/666714. | |
| 2217 TEST_F(RenderViewImplTest, DispatchBeforeUnloadCanDetachFrame) { | |
| 2218 LoadHTML( | |
| 2219 "<script>window.onbeforeunload = function() { " | |
| 2220 "window.console.log('OnBeforeUnload called'); }</script>"); | |
| 2221 std::unique_ptr<ConsoleCallbackFilter> callback_filter( | |
|
Charlie Reis
2016/11/23 07:07:00
Nice. Let's add a comment explaining what this is
lfg
2016/11/23 16:48:02
Done. Can you do a quick sanity check to make sure
Charlie Reis
2016/11/23 17:47:11
Thanks-- looks good.
| |
| 2222 new ConsoleCallbackFilter(base::Bind( | |
| 2223 [](RenderFrameImpl* frame, const base::string16& msg) { | |
| 2224 EXPECT_EQ(base::UTF8ToUTF16("OnBeforeUnload called"), msg); | |
| 2225 frame->OnMessageReceived(FrameMsg_SwapOut( | |
| 2226 frame->GetRoutingID(), 1, false, FrameReplicationState())); | |
| 2227 }, | |
| 2228 base::Unretained(frame())))); | |
| 2229 render_thread_->sink().AddFilter(callback_filter.get()); | |
| 2230 frame()->OnMessageReceived( | |
| 2231 FrameMsg_BeforeUnload(frame()->GetRoutingID(), false)); | |
| 2232 render_thread_->sink().RemoveFilter(callback_filter.get()); | |
| 2233 } | |
| 2234 | |
| 2188 TEST_F(RenderViewImplBlinkSettingsTest, Default) { | 2235 TEST_F(RenderViewImplBlinkSettingsTest, Default) { |
| 2189 DoSetUp(); | 2236 DoSetUp(); |
| 2190 EXPECT_FALSE(settings()->viewportEnabled()); | 2237 EXPECT_FALSE(settings()->viewportEnabled()); |
| 2191 } | 2238 } |
| 2192 | 2239 |
| 2193 TEST_F(RenderViewImplBlinkSettingsTest, CommandLine) { | 2240 TEST_F(RenderViewImplBlinkSettingsTest, CommandLine) { |
| 2194 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 2241 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 2195 switches::kBlinkSettings, | 2242 switches::kBlinkSettings, |
| 2196 "multiTargetTapNotificationEnabled=true,viewportEnabled=true"); | 2243 "multiTargetTapNotificationEnabled=true,viewportEnabled=true"); |
| 2197 DoSetUp(); | 2244 DoSetUp(); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2492 ExpectPauseAndResume(3); | 2539 ExpectPauseAndResume(3); |
| 2493 blink::WebScriptSource source2( | 2540 blink::WebScriptSource source2( |
| 2494 WebString::fromUTF8("function func2() { func1(); }; func2();")); | 2541 WebString::fromUTF8("function func2() { func1(); }; func2();")); |
| 2495 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); | 2542 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); |
| 2496 | 2543 |
| 2497 EXPECT_FALSE(IsPaused()); | 2544 EXPECT_FALSE(IsPaused()); |
| 2498 Detach(); | 2545 Detach(); |
| 2499 } | 2546 } |
| 2500 | 2547 |
| 2501 } // namespace content | 2548 } // namespace content |
| OLD | NEW |