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

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
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 6970 matching lines...) Expand 10 before | Expand all | Expand 10 after
6981 ASSERT_TRUE(windowTop->IsObject()); 6981 ASSERT_TRUE(windowTop->IsObject());
6982 v8::Local<v8::Value> originalWindow = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource( 6982 v8::Local<v8::Value> originalWindow = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource(
6983 "document.querySelector('#frame2').contentWindow;")); 6983 "document.querySelector('#frame2').contentWindow;"));
6984 ASSERT_TRUE(originalWindow->IsObject()); 6984 ASSERT_TRUE(originalWindow->IsObject());
6985 6985
6986 // Make sure window reference stays the same when swapping to a remote frame . 6986 // Make sure window reference stays the same when swapping to a remote frame .
6987 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; 6987 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
6988 WebRemoteFrame* remoteFrame = remoteClient.frame(); 6988 WebRemoteFrame* remoteFrame = remoteClient.frame();
6989 WebFrame* targetFrame = mainFrame()->firstChild()->nextSibling(); 6989 WebFrame* targetFrame = mainFrame()->firstChild()->nextSibling();
6990 targetFrame->swap(remoteFrame); 6990 targetFrame->swap(remoteFrame);
6991 // FIXME: This cleanup should be unnecessary, but the interaction between fr ame detach
6992 // and swap is completely broken atm. swap() calls detachChildren() on the f rame being
6993 // swapped out, and frame B has a child. When the child of B is detached, it schedules a
6994 // FrameLoader timer to check for load completion in its parent.
6995 // Other tests end up spinning the message loop (e.g. to wait for load compl etion of
6996 // another test page, so this timer callback is processed before FrameHost a nd Page are
6997 // destroyed by the reset() at the end of the test case. However, this test does not spin
6998 // the event loop in its body, so the timer task remains in the queue and en ds up running
6999 // in the setup for the following test. Since the FrameHost/Page for the ass ociated
7000 // FrameLoader have already been destroyed, this leads to crashes/use-after- frees. To
7001 // prevent that, manually call detach() on the Frame to release its resource s and cancel
7002 // pending callbacks.
7003 toCoreFrame(targetFrame)->detach();
7004 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique()); 6991 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique());
7005 v8::Local<v8::Value> remoteWindow = mainFrame()->executeScriptAndReturnValue (WebScriptSource( 6992 v8::Local<v8::Value> remoteWindow = mainFrame()->executeScriptAndReturnValue (WebScriptSource(
7006 "document.querySelector('#frame2').contentWindow;")); 6993 "document.querySelector('#frame2').contentWindow;"));
7007 EXPECT_TRUE(originalWindow->StrictEquals(remoteWindow)); 6994 EXPECT_TRUE(originalWindow->StrictEquals(remoteWindow));
7008 // Check that its view is consistent with the world. 6995 // Check that its view is consistent with the world.
7009 v8::Local<v8::Value> remoteWindowTop = mainFrame()->executeScriptAndReturnVa lue(WebScriptSource( 6996 v8::Local<v8::Value> remoteWindowTop = mainFrame()->executeScriptAndReturnVa lue(WebScriptSource(
7010 "document.querySelector('#frame2').contentWindow.top;")); 6997 "document.querySelector('#frame2').contentWindow.top;"));
7011 EXPECT_TRUE(windowTop->StrictEquals(remoteWindowTop)); 6998 EXPECT_TRUE(windowTop->StrictEquals(remoteWindowTop));
7012 6999
7013 // Now check that remote -> local works too, since it goes through a differe nt code path. 7000 // Now check that remote -> local works too, since it goes through a differe nt code path.
7014 FrameTestHelpers::TestWebFrameClient client; 7001 FrameTestHelpers::TestWebFrameClient client;
7015 WebLocalFrame* localFrame = WebLocalFrame::create(WebTreeScopeType::Document , &client); 7002 WebLocalFrame* localFrame = WebLocalFrame::create(WebTreeScopeType::Document , &client);
7016 localFrame->initializeToReplaceRemoteFrame(remoteFrame, "", WebSandboxFlags: :None); 7003 localFrame->initializeToReplaceRemoteFrame(remoteFrame, "", WebSandboxFlags: :None);
7017 remoteFrame->swap(localFrame); 7004 remoteFrame->swap(localFrame);
7018 v8::Local<v8::Value> localWindow = mainFrame()->executeScriptAndReturnValue( WebScriptSource( 7005 v8::Local<v8::Value> localWindow = mainFrame()->executeScriptAndReturnValue( WebScriptSource(
7019 "document.querySelector('#frame2').contentWindow;")); 7006 "document.querySelector('#frame2').contentWindow;"));
7020 EXPECT_TRUE(originalWindow->StrictEquals(localWindow)); 7007 EXPECT_TRUE(originalWindow->StrictEquals(localWindow));
7021 v8::Local<v8::Value> localWindowTop = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource( 7008 v8::Local<v8::Value> localWindowTop = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource(
7022 "document.querySelector('#frame2').contentWindow.top;")); 7009 "document.querySelector('#frame2').contentWindow.top;"));
7023 EXPECT_TRUE(windowTop->StrictEquals(localWindowTop)); 7010 EXPECT_TRUE(windowTop->StrictEquals(localWindowTop));
7024 7011
7025 // Manually reset to break WebViewHelper's dependency on the stack allocated 7012 // Manually reset to break WebViewHelper's dependency on the stack allocated
7026 // TestWebFrameClient. 7013 // TestWebFrameClient.
7027 reset(); 7014 reset();
7028 remoteFrame->close();
7029 } 7015 }
7030 7016
7031 TEST_F(WebFrameSwapTest, SwapInitializesGlobal) 7017 TEST_F(WebFrameSwapTest, SwapInitializesGlobal)
7032 { 7018 {
7033 v8::HandleScope scope(v8::Isolate::GetCurrent()); 7019 v8::HandleScope scope(v8::Isolate::GetCurrent());
7034 7020
7035 v8::Local<v8::Value> windowTop = mainFrame()->executeScriptAndReturnValue(We bScriptSource("window")); 7021 v8::Local<v8::Value> windowTop = mainFrame()->executeScriptAndReturnValue(We bScriptSource("window"));
7036 ASSERT_TRUE(windowTop->IsObject()); 7022 ASSERT_TRUE(windowTop->IsObject());
7037 7023
7038 v8::Local<v8::Value> lastChild = mainFrame()->executeScriptAndReturnValue(We bScriptSource("saved = window[2]")); 7024 v8::Local<v8::Value> lastChild = mainFrame()->executeScriptAndReturnValue(We bScriptSource("saved = window[2]"));
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
7448 7434
7449 EXPECT_EQ(parent, firstFrame->parent()); 7435 EXPECT_EQ(parent, firstFrame->parent());
7450 EXPECT_EQ(parent, secondFrame->parent()); 7436 EXPECT_EQ(parent, secondFrame->parent());
7451 EXPECT_EQ(parent, thirdFrame->parent()); 7437 EXPECT_EQ(parent, thirdFrame->parent());
7452 EXPECT_EQ(parent, fourthFrame->parent()); 7438 EXPECT_EQ(parent, fourthFrame->parent());
7453 7439
7454 view->close(); 7440 view->close();
7455 } 7441 }
7456 7442
7457 } // namespace blink 7443 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698