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

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

Issue 1052993006: Refactor frame navigation/detach state cleanup to be more sane. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: shuffle Created 5 years, 8 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 | Annotate | Revision Log
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 6562 matching lines...) Expand 10 before | Expand all | Expand 10 after
6573 6573
6574 // Make sure that an embedder-triggered detach with a remote frame parent 6574 // Make sure that an embedder-triggered detach with a remote frame parent
6575 // doesn't leave behind dangling pointers. 6575 // doesn't leave behind dangling pointers.
6576 TEST_F(WebFrameTest, EmbedderTriggeredDetachWithRemoteMainFrame) 6576 TEST_F(WebFrameTest, EmbedderTriggeredDetachWithRemoteMainFrame)
6577 { 6577 {
6578 // FIXME: Refactor some of this logic into WebViewHelper to make it easier t o 6578 // FIXME: Refactor some of this logic into WebViewHelper to make it easier t o
6579 // write tests with a top-level remote frame. 6579 // write tests with a top-level remote frame.
6580 FrameTestHelpers::TestWebViewClient viewClient; 6580 FrameTestHelpers::TestWebViewClient viewClient;
6581 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; 6581 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
6582 WebView* view = WebView::create(&viewClient); 6582 WebView* view = WebView::create(&viewClient);
6583 view->setMainFrame(WebRemoteFrame::create(&remoteClient)); 6583 view->setMainFrame(remoteClient.frame());
6584 FrameTestHelpers::TestWebFrameClient childFrameClient; 6584 FrameTestHelpers::TestWebFrameClient childFrameClient;
6585 WebLocalFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createLoc alChild("", WebSandboxFlags::None, &childFrameClient); 6585 WebLocalFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createLoc alChild("", WebSandboxFlags::None, &childFrameClient);
6586 6586
6587 // Purposely keep the LocalFrame alive so it's the last thing to be destroye d. 6587 // Purposely keep the LocalFrame alive so it's the last thing to be destroye d.
6588 RefPtrWillBePersistent<Frame> childCoreFrame = toCoreFrame(childFrame); 6588 RefPtrWillBePersistent<Frame> childCoreFrame = toCoreFrame(childFrame);
6589 view->close(); 6589 view->close();
6590 childCoreFrame.clear(); 6590 childCoreFrame.clear();
6591 } 6591 }
6592 6592
6593 class WebFrameSwapTest : public WebFrameTest { 6593 class WebFrameSwapTest : public WebFrameTest {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
6787 TEST_F(WebFrameSwapTest, SwapPreservesGlobalContext) 6787 TEST_F(WebFrameSwapTest, SwapPreservesGlobalContext)
6788 { 6788 {
6789 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6789 v8::HandleScope scope(v8::Isolate::GetCurrent());
6790 v8::Local<v8::Value> windowTop = mainFrame()->executeScriptAndReturnValue(We bScriptSource("window")); 6790 v8::Local<v8::Value> windowTop = mainFrame()->executeScriptAndReturnValue(We bScriptSource("window"));
6791 ASSERT_TRUE(windowTop->IsObject()); 6791 ASSERT_TRUE(windowTop->IsObject());
6792 v8::Local<v8::Value> originalWindow = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource( 6792 v8::Local<v8::Value> originalWindow = mainFrame()->executeScriptAndReturnVal ue(WebScriptSource(
6793 "document.querySelector('#frame2').contentWindow;")); 6793 "document.querySelector('#frame2').contentWindow;"));
6794 ASSERT_TRUE(originalWindow->IsObject()); 6794 ASSERT_TRUE(originalWindow->IsObject());
6795 6795
6796 // Make sure window reference stays the same when swapping to a remote frame . 6796 // Make sure window reference stays the same when swapping to a remote frame .
6797 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(nullptr); 6797 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
6798 WebRemoteFrame* remoteFrame = remoteClient.frame();
6798 WebFrame* targetFrame = mainFrame()->firstChild()->nextSibling(); 6799 WebFrame* targetFrame = mainFrame()->firstChild()->nextSibling();
6799 targetFrame->swap(remoteFrame); 6800 targetFrame->swap(remoteFrame);
6800 // FIXME: This cleanup should be unnecessary, but the interaction between fr ame detach 6801 // FIXME: This cleanup should be unnecessary, but the interaction between fr ame detach
6801 // and swap is completely broken atm. swap() calls detachChildren() on the f rame being 6802 // and swap is completely broken atm. swap() calls detachChildren() on the f rame being
6802 // swapped out, and frame B has a child. When the child of B is detached, it schedules a 6803 // swapped out, and frame B has a child. When the child of B is detached, it schedules a
6803 // FrameLoader timer to check for load completion in its parent. 6804 // FrameLoader timer to check for load completion in its parent.
6804 // Other tests end up spinning the message loop (e.g. to wait for load compl etion of 6805 // Other tests end up spinning the message loop (e.g. to wait for load compl etion of
6805 // another test page, so this timer callback is processed before FrameHost a nd Page are 6806 // another test page, so this timer callback is processed before FrameHost a nd Page are
6806 // destroyed by the reset() at the end of the test case. However, this test does not spin 6807 // destroyed by the reset() at the end of the test case. However, this test does not spin
6807 // the event loop in its body, so the timer task remains in the queue and en ds up running 6808 // the event loop in its body, so the timer task remains in the queue and en ds up running
(...skipping 26 matching lines...) Expand all
6834 // Manually reset to break WebViewHelper's dependency on the stack allocated 6835 // Manually reset to break WebViewHelper's dependency on the stack allocated
6835 // TestWebFrameClient. 6836 // TestWebFrameClient.
6836 reset(); 6837 reset();
6837 remoteFrame->close(); 6838 remoteFrame->close();
6838 } 6839 }
6839 6840
6840 TEST_F(WebFrameSwapTest, RemoteFramesAreIndexable) 6841 TEST_F(WebFrameSwapTest, RemoteFramesAreIndexable)
6841 { 6842 {
6842 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6843 v8::HandleScope scope(v8::Isolate::GetCurrent());
6843 6844
6844 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(nullptr); 6845 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
6846 WebRemoteFrame* remoteFrame = remoteClient.frame();
6845 mainFrame()->lastChild()->swap(remoteFrame); 6847 mainFrame()->lastChild()->swap(remoteFrame);
6846 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique()); 6848 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique());
6847 v8::Local<v8::Value> remoteWindow = mainFrame()->executeScriptAndReturnValue (WebScriptSource("window[2]")); 6849 v8::Local<v8::Value> remoteWindow = mainFrame()->executeScriptAndReturnValue (WebScriptSource("window[2]"));
6848 EXPECT_TRUE(remoteWindow->IsObject()); 6850 EXPECT_TRUE(remoteWindow->IsObject());
6849 v8::Local<v8::Value> windowLength = mainFrame()->executeScriptAndReturnValue (WebScriptSource("window.length")); 6851 v8::Local<v8::Value> windowLength = mainFrame()->executeScriptAndReturnValue (WebScriptSource("window.length"));
6850 ASSERT_TRUE(windowLength->IsNumber()); 6852 ASSERT_TRUE(windowLength->IsNumber());
6851 v8::Local<v8::Integer> windowLengthInteger = windowLength->ToInteger(); 6853 v8::Local<v8::Integer> windowLengthInteger = windowLength->ToInteger();
6852 EXPECT_EQ(3, windowLengthInteger->Value()); 6854 EXPECT_EQ(3, windowLengthInteger->Value());
6855
6856 reset();
6853 } 6857 }
6854 6858
6855 TEST_F(WebFrameSwapTest, RemoteFrameLengthAccess) 6859 TEST_F(WebFrameSwapTest, RemoteFrameLengthAccess)
6856 { 6860 {
6857 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6861 v8::HandleScope scope(v8::Isolate::GetCurrent());
6858 6862
6859 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(nullptr); 6863 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
6864 WebRemoteFrame* remoteFrame = remoteClient.frame();
6860 mainFrame()->lastChild()->swap(remoteFrame); 6865 mainFrame()->lastChild()->swap(remoteFrame);
6861 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique()); 6866 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique());
6862 v8::Local<v8::Value> remoteWindowLength = mainFrame()->executeScriptAndRetur nValue(WebScriptSource("window[2].length")); 6867 v8::Local<v8::Value> remoteWindowLength = mainFrame()->executeScriptAndRetur nValue(WebScriptSource("window[2].length"));
6863 ASSERT_TRUE(remoteWindowLength->IsNumber()); 6868 ASSERT_TRUE(remoteWindowLength->IsNumber());
6864 v8::Local<v8::Integer> remoteWindowLengthInteger = remoteWindowLength->ToInt eger(); 6869 v8::Local<v8::Integer> remoteWindowLengthInteger = remoteWindowLength->ToInt eger();
6865 EXPECT_EQ(0, remoteWindowLengthInteger->Value()); 6870 EXPECT_EQ(0, remoteWindowLengthInteger->Value());
6871
6872 reset();
6866 } 6873 }
6867 6874
6868 TEST_F(WebFrameSwapTest, RemoteWindowNamedAccess) 6875 TEST_F(WebFrameSwapTest, RemoteWindowNamedAccess)
6869 { 6876 {
6870 v8::HandleScope scope(v8::Isolate::GetCurrent()); 6877 v8::HandleScope scope(v8::Isolate::GetCurrent());
6871 6878
6872 // FIXME: Once OOPIF unit test infrastructure is in place, test that named 6879 // FIXME: Once OOPIF unit test infrastructure is in place, test that named
6873 // window access on a remote window works. For now, just test that accessing 6880 // window access on a remote window works. For now, just test that accessing
6874 // a named property doesn't crash. 6881 // a named property doesn't crash.
6875 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(nullptr); 6882 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
6883 WebRemoteFrame* remoteFrame = remoteClient.frame();
6876 mainFrame()->lastChild()->swap(remoteFrame); 6884 mainFrame()->lastChild()->swap(remoteFrame);
6877 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique()); 6885 remoteFrame->setReplicatedOrigin(SecurityOrigin::createUnique());
6878 v8::Local<v8::Value> remoteWindowProperty = mainFrame()->executeScriptAndRet urnValue(WebScriptSource("window[2].foo")); 6886 v8::Local<v8::Value> remoteWindowProperty = mainFrame()->executeScriptAndRet urnValue(WebScriptSource("window[2].foo"));
6879 EXPECT_TRUE(remoteWindowProperty.IsEmpty()); 6887 EXPECT_TRUE(remoteWindowProperty.IsEmpty());
6888
6889 reset();
6880 } 6890 }
6881 6891
6882 class RemoteToLocalSwapWebFrameClient : public FrameTestHelpers::TestWebFrameCli ent { 6892 class RemoteToLocalSwapWebFrameClient : public FrameTestHelpers::TestWebFrameCli ent {
6883 public: 6893 public:
6884 explicit RemoteToLocalSwapWebFrameClient(WebRemoteFrame* remoteFrame) 6894 explicit RemoteToLocalSwapWebFrameClient(WebRemoteFrame* remoteFrame)
6885 : m_historyCommitType(WebHistoryInertCommit) 6895 : m_historyCommitType(WebHistoryInertCommit)
6886 , m_remoteFrame(remoteFrame) 6896 , m_remoteFrame(remoteFrame)
6887 { 6897 {
6888 } 6898 }
6889 6899
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
6929 6939
6930 const WebURLRequest& lastRequest() const { return m_lastRequest; } 6940 const WebURLRequest& lastRequest() const { return m_lastRequest; }
6931 6941
6932 private: 6942 private:
6933 WebURLRequest m_lastRequest; 6943 WebURLRequest m_lastRequest;
6934 }; 6944 };
6935 6945
6936 TEST_F(WebFrameSwapTest, NavigateRemoteFrameViaLocation) 6946 TEST_F(WebFrameSwapTest, NavigateRemoteFrameViaLocation)
6937 { 6947 {
6938 RemoteNavigationClient client; 6948 RemoteNavigationClient client;
6939 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(&client); 6949 WebRemoteFrame* remoteFrame = client.frame();
6940 WebFrame* targetFrame = mainFrame()->firstChild(); 6950 WebFrame* targetFrame = mainFrame()->firstChild();
6941 ASSERT_TRUE(targetFrame); 6951 ASSERT_TRUE(targetFrame);
6942 targetFrame->swap(remoteFrame); 6952 targetFrame->swap(remoteFrame);
6943 ASSERT_TRUE(mainFrame()->firstChild()); 6953 ASSERT_TRUE(mainFrame()->firstChild());
6944 ASSERT_EQ(mainFrame()->firstChild(), remoteFrame); 6954 ASSERT_EQ(mainFrame()->firstChild(), remoteFrame);
6945 6955
6946 remoteFrame->setReplicatedOrigin(WebSecurityOrigin::createFromString("http:/ /127.0.0.1")); 6956 remoteFrame->setReplicatedOrigin(WebSecurityOrigin::createFromString("http:/ /127.0.0.1"));
6947 mainFrame()->executeScript(WebScriptSource( 6957 mainFrame()->executeScript(WebScriptSource(
6948 "document.getElementsByTagName('iframe')[0].contentWindow.location = 'da ta:text/html,hi'")); 6958 "document.getElementsByTagName('iframe')[0].contentWindow.location = 'da ta:text/html,hi'"));
6949 ASSERT_FALSE(client.lastRequest().isNull()); 6959 ASSERT_FALSE(client.lastRequest().isNull());
6950 EXPECT_EQ(WebURL(toKURL("data:text/html,hi")), client.lastRequest().url()); 6960 EXPECT_EQ(WebURL(toKURL("data:text/html,hi")), client.lastRequest().url());
6951 6961
6952 // Manually reset to break WebViewHelper's dependency on the stack allocated 6962 // Manually reset to break WebViewHelper's dependency on the stack allocated
6953 // TestWebFrameClient. 6963 // TestWebFrameClient.
6954 reset(); 6964 reset();
6955 remoteFrame->close();
6956 } 6965 }
6957 6966
6958 class MockDocumentThreadableLoaderClient : public DocumentThreadableLoaderClient { 6967 class MockDocumentThreadableLoaderClient : public DocumentThreadableLoaderClient {
6959 public: 6968 public:
6960 MockDocumentThreadableLoaderClient() : m_failed(false) { } 6969 MockDocumentThreadableLoaderClient() : m_failed(false) { }
6961 virtual void didFail(const ResourceError&) override { m_failed = true;} 6970 virtual void didFail(const ResourceError&) override { m_failed = true;}
6962 6971
6963 void reset() { m_failed = false; } 6972 void reset() { m_failed = false; }
6964 bool failed() { return m_failed; } 6973 bool failed() { return m_failed; }
6965 6974
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
7063 EXPECT_EQ(4u, frameClient.provisionalLoadCount()); 7072 EXPECT_EQ(4u, frameClient.provisionalLoadCount());
7064 EXPECT_FALSE(frameClient.wasLastProvisionalLoadATransition()); 7073 EXPECT_FALSE(frameClient.wasLastProvisionalLoadATransition());
7065 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); 7074 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount());
7066 } 7075 }
7067 7076
7068 TEST_F(WebFrameTest, DetachRemoteFrame) 7077 TEST_F(WebFrameTest, DetachRemoteFrame)
7069 { 7078 {
7070 FrameTestHelpers::TestWebViewClient viewClient; 7079 FrameTestHelpers::TestWebViewClient viewClient;
7071 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; 7080 FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
7072 WebView* view = WebView::create(&viewClient); 7081 WebView* view = WebView::create(&viewClient);
7073 view->setMainFrame(WebRemoteFrame::create(&remoteClient)); 7082 view->setMainFrame(remoteClient.frame());
7074 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient; 7083 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient;
7075 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe moteChild("", WebSandboxFlags::None, &childFrameClient); 7084 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe moteChild("", WebSandboxFlags::None, &childFrameClient);
7076 childFrame->detach(); 7085 childFrame->detach();
7077 view->close(); 7086 view->close();
7078 } 7087 }
7079 7088
7080 } // namespace blink 7089 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698