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

Side by Side Diff: Source/web/tests/WebFrameTest.cpp

Issue 1041473002: Detach old frame on WebFrame::swap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.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
« no previous file with comments | « Source/web/tests/FrameTestHelpers.cpp ('k') | public/web/WebFrameClient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 7004 matching lines...) Expand 10 before | Expand all | Expand 10 after
7015 ASSERT_TRUE(windowTop->IsObject()); 7015 ASSERT_TRUE(windowTop->IsObject());
7016 v8::Local<v8::Value> originalWindow = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource( 7016 v8::Local<v8::Value> originalWindow = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource(
7017 "document.querySelector('#frame2').contentWindow;")); 7017 "document.querySelector('#frame2').contentWindow;"));
7018 ASSERT_TRUE(originalWindow->IsObject()); 7018 ASSERT_TRUE(originalWindow->IsObject());
7019 7019
7020 // Make sure window reference stays the same when swapping to a remote frame . 7020 // Make sure window reference stays the same when swapping to a remote frame .
7021 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; 7021 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
7022 WebRemoteFrame* remoteFrame = remoteClient.frame(); 7022 WebRemoteFrame* remoteFrame = remoteClient.frame();
7023 WebFrame* targetFrame = mainFrame()->firstChild()->nextSibling(); 7023 WebFrame* targetFrame = mainFrame()->firstChild()->nextSibling();
7024 targetFrame->swap(remoteFrame); 7024 targetFrame->swap(remoteFrame);
7025 // FIXME: This cleanup should be unnecessary, but the interaction between fr ame detach
7026 // and swap is completely broken atm. swap() calls detachChildren() on the f rame being
7027 // swapped out, and frame B has a child. When the child of B is detached, it schedules a
7028 // FrameLoader timer to check for load completion in its parent.
7029 // Other tests end up spinning the message loop (e.g. to wait for load compl etion of
7030 // another test page, so this timer callback is processed before FrameHost a nd Page are
7031 // destroyed by the reset() at the end of the test case. However, this test does not spin
7032 // the event loop in its body, so the timer task remains in the queue and en ds up running
7033 // in the setup for the following test. Since the FrameHost/Page for the ass ociated
7034 // FrameLoader have already been destroyed, this leads to crashes/use-after- frees. To
7035 // prevent that, manually call detach() on the Frame to release its resource s and cancel
7036 // pending callbacks.
7037 toCoreFrame(targetFrame)->detach();
7038 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique()); 7025 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique());
7039 v8::Local<v8::Value> remoteWindow = mainFrame()->executeScriptAndReturnValue (WebScriptSource( 7026 v8::Local<v8::Value> remoteWindow = mainFrame()->executeScriptAndReturnValue (WebScriptSource(
7040 "document.querySelector('#frame2').contentWindow;")); 7027 "document.querySelector('#frame2').contentWindow;"));
7041 EXPECT_TRUE(originalWindow->StrictEquals(remoteWindow)); 7028 EXPECT_TRUE(originalWindow->StrictEquals(remoteWindow));
7042 // Check that its view is consistent with the world. 7029 // Check that its view is consistent with the world.
7043 v8::Local<v8::Value> remoteWindowTop = mainFrame()->executeScriptAndReturnVa lue(WebScriptSource( 7030 v8::Local<v8::Value> remoteWindowTop = mainFrame()->executeScriptAndReturnVa lue(WebScriptSource(
7044 "document.querySelector('#frame2').contentWindow.top;")); 7031 "document.querySelector('#frame2').contentWindow.top;"));
7045 EXPECT_TRUE(windowTop->StrictEquals(remoteWindowTop)); 7032 EXPECT_TRUE(windowTop->StrictEquals(remoteWindowTop));
7046 7033
7047 // Now check that remote -> local works too, since it goes through a differe nt code path. 7034 // Now check that remote -> local works too, since it goes through a differe nt code path.
7048 FrameTestHelpers::TestWebFrameClient client; 7035 FrameTestHelpers::TestWebFrameClient client;
7049 WebLocalFrame* localFrame = WebLocalFrame::create(WebTreeScopeType::Document , &client); 7036 WebLocalFrame* localFrame = WebLocalFrame::create(WebTreeScopeType::Document , &client);
7050 localFrame->initializeToReplaceRemoteFrame(remoteFrame, "", WebSandboxFlags: :None); 7037 localFrame->initializeToReplaceRemoteFrame(remoteFrame, "", WebSandboxFlags: :None);
7051 remoteFrame->swap(localFrame); 7038 remoteFrame->swap(localFrame);
7052 v8::Local<v8::Value> localWindow = mainFrame()->executeScriptAndReturnValue( WebScriptSource( 7039 v8::Local<v8::Value> localWindow = mainFrame()->executeScriptAndReturnValue( WebScriptSource(
7053 "document.querySelector('#frame2').contentWindow;")); 7040 "document.querySelector('#frame2').contentWindow;"));
7054 EXPECT_TRUE(originalWindow->StrictEquals(localWindow)); 7041 EXPECT_TRUE(originalWindow->StrictEquals(localWindow));
7055 v8::Local<v8::Value> localWindowTop = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource( 7042 v8::Local<v8::Value> localWindowTop = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource(
7056 "document.querySelector('#frame2').contentWindow.top;")); 7043 "document.querySelector('#frame2').contentWindow.top;"));
7057 EXPECT_TRUE(windowTop->StrictEquals(localWindowTop)); 7044 EXPECT_TRUE(windowTop->StrictEquals(localWindowTop));
7058 7045
7059 // Manually reset to break WebViewHelper's dependency on the stack allocated 7046 // Manually reset to break WebViewHelper's dependency on the stack allocated
7060 // TestWebFrameClient. 7047 // TestWebFrameClient.
7061 reset(); 7048 reset();
7062 remoteFrame->close();
7063 } 7049 }
7064 7050
7065 TEST_F(WebFrameSwapTest, SwapInitializesGlobal) 7051 TEST_F(WebFrameSwapTest, SwapInitializesGlobal)
7066 { 7052 {
7067 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7053 v8::HandleScope scope(v8::Isolate::GetCurrent());
7068 7054
7069 v8::Local<v8::Value> windowTop = mainFrame()->executeScriptAndReturnValue(We bScriptSource("window")); 7055 v8::Local<v8::Value> windowTop = mainFrame()->executeScriptAndReturnValue(We bScriptSource("window"));
7070 ASSERT_TRUE(windowTop->IsObject()); 7056 ASSERT_TRUE(windowTop->IsObject());
7071 7057
7072 v8::Local<v8::Value> lastChild = mainFrame()->executeScriptAndReturnValue(We bScriptSource("saved = window[2]")); 7058 v8::Local<v8::Value> lastChild = mainFrame()->executeScriptAndReturnValue(We bScriptSource("saved = window[2]"));
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
7712 ScrollUpdate(&webViewHelper, 30, 0); 7698 ScrollUpdate(&webViewHelper, 30, 0);
7713 Mock::VerifyAndClearExpectations(&client); 7699 Mock::VerifyAndClearExpectations(&client);
7714 7700
7715 // Overscroll is not reported. 7701 // Overscroll is not reported.
7716 EXPECT_CALL(client, didOverscroll(WebFloatSize(), WebFloatSize(), WebFloatPo int(33, 33), WebFloatSize())).Times(0); 7702 EXPECT_CALL(client, didOverscroll(WebFloatSize(), WebFloatSize(), WebFloatPo int(33, 33), WebFloatSize())).Times(0);
7717 ScrollEnd(&webViewHelper); 7703 ScrollEnd(&webViewHelper);
7718 Mock::VerifyAndClearExpectations(&client); 7704 Mock::VerifyAndClearExpectations(&client);
7719 } 7705 }
7720 7706
7721 } // namespace blink 7707 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/tests/FrameTestHelpers.cpp ('k') | public/web/WebFrameClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698