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

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

Powered by Google App Engine
This is Rietveld 408576698