OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 // TODO(alexmos, dcheng): This test and some other OOPIF tests use | 6892 // TODO(alexmos, dcheng): This test and some other OOPIF tests use |
6883 // very little of the test fixture support in WebFrameSwapTest. We should | 6893 // very little of the test fixture support in WebFrameSwapTest. We should |
6884 // clean these tests up. | 6894 // clean these tests up. |
6885 TEST_F(WebFrameSwapTest, FramesOfRemoteParentAreIndexable) | 6895 TEST_F(WebFrameSwapTest, FramesOfRemoteParentAreIndexable) |
6886 { | 6896 { |
6887 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 6897 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
6888 | 6898 |
6889 WebRemoteFrame* remoteParentFrame = WebRemoteFrame::create(nullptr); | 6899 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; |
| 6900 WebRemoteFrame* remoteParentFrame = remoteClient.frame(); |
6890 mainFrame()->swap(remoteParentFrame); | 6901 mainFrame()->swap(remoteParentFrame); |
6891 remoteParentFrame->setReplicatedOrigin(SecurityOrigin::createUnique()); | 6902 remoteParentFrame->setReplicatedOrigin(SecurityOrigin::createUnique()); |
6892 | 6903 |
6893 FrameTestHelpers::TestWebFrameClient childFrameClient; | 6904 FrameTestHelpers::TestWebFrameClient childFrameClient; |
6894 WebLocalFrame* childFrame = remoteParentFrame->createLocalChild("", WebSandb
oxFlags::None, &childFrameClient); | 6905 WebLocalFrame* childFrame = remoteParentFrame->createLocalChild("", WebSandb
oxFlags::None, &childFrameClient); |
6895 FrameTestHelpers::loadFrame(childFrame, m_baseURL + "subframe-hello.html"); | 6906 FrameTestHelpers::loadFrame(childFrame, m_baseURL + "subframe-hello.html"); |
6896 | 6907 |
6897 v8::Local<v8::Value> window = childFrame->executeScriptAndReturnValue(WebScr
iptSource("window")); | 6908 v8::Local<v8::Value> window = childFrame->executeScriptAndReturnValue(WebScr
iptSource("window")); |
6898 v8::Local<v8::Value> childOfRemoteParent = childFrame->executeScriptAndRetur
nValue(WebScriptSource("parent.frames[0]")); | 6909 v8::Local<v8::Value> childOfRemoteParent = childFrame->executeScriptAndRetur
nValue(WebScriptSource("parent.frames[0]")); |
6899 EXPECT_TRUE(childOfRemoteParent->IsObject()); | 6910 EXPECT_TRUE(childOfRemoteParent->IsObject()); |
6900 EXPECT_TRUE(window->StrictEquals(childOfRemoteParent)); | 6911 EXPECT_TRUE(window->StrictEquals(childOfRemoteParent)); |
6901 | 6912 |
6902 v8::Local<v8::Value> windowLength = childFrame->executeScriptAndReturnValue(
WebScriptSource("parent.frames.length")); | 6913 v8::Local<v8::Value> windowLength = childFrame->executeScriptAndReturnValue(
WebScriptSource("parent.frames.length")); |
6903 ASSERT_TRUE(windowLength->IsNumber()); | 6914 ASSERT_TRUE(windowLength->IsNumber()); |
6904 v8::Local<v8::Integer> windowLengthInteger = windowLength->ToInteger(); | 6915 v8::Local<v8::Integer> windowLengthInteger = windowLength->ToInteger(); |
6905 EXPECT_EQ(1, windowLengthInteger->Value()); | 6916 EXPECT_EQ(1, windowLengthInteger->Value()); |
6906 | 6917 |
6907 // Manually reset to break WebViewHelper's dependency on the stack allocated | 6918 // Manually reset to break WebViewHelper's dependency on the stack allocated
clients. |
6908 // TestWebFrameClient. | |
6909 reset(); | 6919 reset(); |
6910 remoteParentFrame->close(); | |
6911 } | 6920 } |
6912 | 6921 |
6913 class RemoteToLocalSwapWebFrameClient : public FrameTestHelpers::TestWebFrameCli
ent { | 6922 class RemoteToLocalSwapWebFrameClient : public FrameTestHelpers::TestWebFrameCli
ent { |
6914 public: | 6923 public: |
6915 explicit RemoteToLocalSwapWebFrameClient(WebRemoteFrame* remoteFrame) | 6924 explicit RemoteToLocalSwapWebFrameClient(WebRemoteFrame* remoteFrame) |
6916 : m_historyCommitType(WebHistoryInertCommit) | 6925 : m_historyCommitType(WebHistoryInertCommit) |
6917 , m_remoteFrame(remoteFrame) | 6926 , m_remoteFrame(remoteFrame) |
6918 { | 6927 { |
6919 } | 6928 } |
6920 | 6929 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6960 | 6969 |
6961 const WebURLRequest& lastRequest() const { return m_lastRequest; } | 6970 const WebURLRequest& lastRequest() const { return m_lastRequest; } |
6962 | 6971 |
6963 private: | 6972 private: |
6964 WebURLRequest m_lastRequest; | 6973 WebURLRequest m_lastRequest; |
6965 }; | 6974 }; |
6966 | 6975 |
6967 TEST_F(WebFrameSwapTest, NavigateRemoteFrameViaLocation) | 6976 TEST_F(WebFrameSwapTest, NavigateRemoteFrameViaLocation) |
6968 { | 6977 { |
6969 RemoteNavigationClient client; | 6978 RemoteNavigationClient client; |
6970 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(&client); | 6979 WebRemoteFrame* remoteFrame = client.frame(); |
6971 WebFrame* targetFrame = mainFrame()->firstChild(); | 6980 WebFrame* targetFrame = mainFrame()->firstChild(); |
6972 ASSERT_TRUE(targetFrame); | 6981 ASSERT_TRUE(targetFrame); |
6973 targetFrame->swap(remoteFrame); | 6982 targetFrame->swap(remoteFrame); |
6974 ASSERT_TRUE(mainFrame()->firstChild()); | 6983 ASSERT_TRUE(mainFrame()->firstChild()); |
6975 ASSERT_EQ(mainFrame()->firstChild(), remoteFrame); | 6984 ASSERT_EQ(mainFrame()->firstChild(), remoteFrame); |
6976 | 6985 |
6977 remoteFrame->setReplicatedOrigin(WebSecurityOrigin::createFromString("http:/
/127.0.0.1")); | 6986 remoteFrame->setReplicatedOrigin(WebSecurityOrigin::createFromString("http:/
/127.0.0.1")); |
6978 mainFrame()->executeScript(WebScriptSource( | 6987 mainFrame()->executeScript(WebScriptSource( |
6979 "document.getElementsByTagName('iframe')[0].contentWindow.location = 'da
ta:text/html,hi'")); | 6988 "document.getElementsByTagName('iframe')[0].contentWindow.location = 'da
ta:text/html,hi'")); |
6980 ASSERT_FALSE(client.lastRequest().isNull()); | 6989 ASSERT_FALSE(client.lastRequest().isNull()); |
6981 EXPECT_EQ(WebURL(toKURL("data:text/html,hi")), client.lastRequest().url()); | 6990 EXPECT_EQ(WebURL(toKURL("data:text/html,hi")), client.lastRequest().url()); |
6982 | 6991 |
6983 // Manually reset to break WebViewHelper's dependency on the stack allocated | 6992 // Manually reset to break WebViewHelper's dependency on the stack allocated |
6984 // TestWebFrameClient. | 6993 // TestWebFrameClient. |
6985 reset(); | 6994 reset(); |
6986 remoteFrame->close(); | |
6987 } | 6995 } |
6988 | 6996 |
6989 class MockDocumentThreadableLoaderClient : public DocumentThreadableLoaderClient
{ | 6997 class MockDocumentThreadableLoaderClient : public DocumentThreadableLoaderClient
{ |
6990 public: | 6998 public: |
6991 MockDocumentThreadableLoaderClient() : m_failed(false) { } | 6999 MockDocumentThreadableLoaderClient() : m_failed(false) { } |
6992 virtual void didFail(const ResourceError&) override { m_failed = true;} | 7000 virtual void didFail(const ResourceError&) override { m_failed = true;} |
6993 | 7001 |
6994 void reset() { m_failed = false; } | 7002 void reset() { m_failed = false; } |
6995 bool failed() { return m_failed; } | 7003 bool failed() { return m_failed; } |
6996 | 7004 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7094 EXPECT_EQ(4u, frameClient.provisionalLoadCount()); | 7102 EXPECT_EQ(4u, frameClient.provisionalLoadCount()); |
7095 EXPECT_FALSE(frameClient.wasLastProvisionalLoadATransition()); | 7103 EXPECT_FALSE(frameClient.wasLastProvisionalLoadATransition()); |
7096 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); | 7104 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); |
7097 } | 7105 } |
7098 | 7106 |
7099 TEST_F(WebFrameTest, DetachRemoteFrame) | 7107 TEST_F(WebFrameTest, DetachRemoteFrame) |
7100 { | 7108 { |
7101 FrameTestHelpers::TestWebViewClient viewClient; | 7109 FrameTestHelpers::TestWebViewClient viewClient; |
7102 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; | 7110 FrameTestHelpers::TestWebRemoteFrameClient remoteClient; |
7103 WebView* view = WebView::create(&viewClient); | 7111 WebView* view = WebView::create(&viewClient); |
7104 view->setMainFrame(WebRemoteFrame::create(&remoteClient)); | 7112 view->setMainFrame(remoteClient.frame()); |
7105 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient; | 7113 FrameTestHelpers::TestWebRemoteFrameClient childFrameClient; |
7106 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe
moteChild("", WebSandboxFlags::None, &childFrameClient); | 7114 WebRemoteFrame* childFrame = view->mainFrame()->toWebRemoteFrame()->createRe
moteChild("", WebSandboxFlags::None, &childFrameClient); |
7107 childFrame->detach(); | 7115 childFrame->detach(); |
7108 view->close(); | 7116 view->close(); |
7109 } | 7117 } |
7110 | 7118 |
7111 } // namespace blink | 7119 } // namespace blink |
OLD | NEW |