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 7004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7015 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); | 7015 FrameTestHelpers::loadFrame(localFrame, m_baseURL + "subframe-hello.html"); |
7016 std::string content = localFrame->contentAsText(1024).utf8(); | 7016 std::string content = localFrame->contentAsText(1024).utf8(); |
7017 EXPECT_EQ("hello", content); | 7017 EXPECT_EQ("hello", content); |
7018 | 7018 |
7019 // Manually reset to break WebViewHelper's dependency on the stack allocated | 7019 // Manually reset to break WebViewHelper's dependency on the stack allocated |
7020 // TestWebFrameClient. | 7020 // TestWebFrameClient. |
7021 reset(); | 7021 reset(); |
7022 remoteFrame->close(); | 7022 remoteFrame->close(); |
7023 } | 7023 } |
7024 | 7024 |
7025 namespace { | |
7026 | |
7027 class ServeAsyncRequestsTask : public WebThread::Task { | |
7028 public: | |
7029 ServeAsyncRequestsTask(FrameTestHelpers::TestWebFrameClient* client, bool* g otCommit) | |
7030 : m_client(client) | |
7031 , m_gotCommit(gotCommit) | |
7032 { | |
7033 } | |
7034 | |
7035 void run() override | |
7036 { | |
7037 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( ); | |
sky
2015/09/02 23:33:15
This triggers a presubmit hook that fails. I had t
| |
7038 if (!m_gotCommit) | |
7039 Platform::current()->currentThread()->postTask(FROM_HERE, new ServeA syncRequestsTask(m_client, m_gotCommit)); | |
7040 else | |
7041 Platform::current()->unitTestSupport()->exitRunLoop(); | |
7042 } | |
7043 | |
7044 private: | |
7045 FrameTestHelpers::TestWebFrameClient* const m_client; | |
7046 bool* m_gotCommit; | |
7047 }; | |
7048 | |
7049 // Starts a load for frame. The call returns once gotCommit is set to true. | |
7050 void StartLoad(WebFrame* frame, const std::string& url, FrameTestHelpers::TestWe bFrameClient* client, bool* gotCommit) | |
7051 { | |
7052 WebURLRequest urlRequest; | |
7053 urlRequest.initialize(); | |
7054 urlRequest.setURL(URLTestHelpers::toKURL(url)); | |
7055 | |
7056 // Schedule a task to start the load, followed by a task that exits the run loop once gotCommit is set to true. | |
7057 Platform::current()->currentThread()->postTask(FROM_HERE, new FrameTestHelpe rs::LoadTask(frame, urlRequest)); | |
7058 Platform::current()->currentThread()->postTask(FROM_HERE, new ServeAsyncRequ estsTask(client, gotCommit)); | |
7059 Platform::current()->unitTestSupport()->enterRunLoop(); | |
7060 } | |
7061 | |
7062 class SwapMainFrameWhileLoadingWebFrameClient : public FrameTestHelpers::TestWeb FrameClient { | |
7063 public: | |
7064 SwapMainFrameWhileLoadingWebFrameClient(bool* gotCommit) : m_gotCommit(gotCo mmit) {} | |
7065 ~SwapMainFrameWhileLoadingWebFrameClient() override {} | |
7066 | |
7067 void didCommitProvisionalLoad(WebLocalFrame*, const WebHistoryItem&, WebHist oryCommitType) override | |
7068 { | |
7069 *m_gotCommit = true; | |
7070 } | |
7071 | |
7072 private: | |
7073 bool* m_gotCommit; | |
7074 }; | |
7075 | |
7076 } // anonymous namespace | |
7077 | |
7078 TEST_F(WebFrameTest, SwapMainFrameWhileLoading) | |
7079 { | |
7080 bool gotCommit = false; | |
7081 SwapMainFrameWhileLoadingWebFrameClient frameClient(&gotCommit); | |
7082 | |
7083 FrameTestHelpers::WebViewHelper webViewHelper; | |
7084 registerMockedHttpURLLoad("frame-a-b-c.html"); | |
7085 registerMockedHttpURLLoad("subframe-a.html"); | |
7086 registerMockedHttpURLLoad("subframe-b.html"); | |
7087 registerMockedHttpURLLoad("subframe-c.html"); | |
7088 registerMockedHttpURLLoad("subframe-hello.html"); | |
7089 | |
7090 webViewHelper.initialize(true, &frameClient); | |
7091 | |
7092 WebFrame* mainFrame = webViewHelper.webView()->mainFrame(); | |
7093 StartLoad(mainFrame, m_baseURL + "frame-a-b-c.html", &frameClient, &gotCommi t); | |
Nate Chapin
2015/09/03 21:02:06
What does this (and above) do that webViewHelper.i
sky
2015/09/03 21:03:44
It pumps events until didCommitProvisionalLoad is
Nate Chapin
2015/09/03 21:52:38
Instead of pumping manually, could you just do the
| |
7094 | |
7095 WebRemoteFrame* remoteFrame = WebRemoteFrame::create(WebTreeScopeType::Docum ent, nullptr); | |
7096 mainFrame->swap(remoteFrame); | |
7097 } | |
7098 | |
7025 void swapAndVerifyFirstChildConsistency(const char* const message, WebFrame* par ent, WebFrame* newChild) | 7099 void swapAndVerifyFirstChildConsistency(const char* const message, WebFrame* par ent, WebFrame* newChild) |
7026 { | 7100 { |
7027 SCOPED_TRACE(message); | 7101 SCOPED_TRACE(message); |
7028 parent->firstChild()->swap(newChild); | 7102 parent->firstChild()->swap(newChild); |
7029 | 7103 |
7030 EXPECT_EQ(newChild, parent->firstChild()); | 7104 EXPECT_EQ(newChild, parent->firstChild()); |
7031 EXPECT_EQ(newChild->parent(), parent); | 7105 EXPECT_EQ(newChild->parent(), parent); |
7032 EXPECT_EQ(newChild, parent->lastChild()->previousSibling()->previousSibling( )); | 7106 EXPECT_EQ(newChild, parent->lastChild()->previousSibling()->previousSibling( )); |
7033 EXPECT_EQ(newChild->nextSibling(), parent->lastChild()->previousSibling()); | 7107 EXPECT_EQ(newChild->nextSibling(), parent->lastChild()->previousSibling()); |
7034 } | 7108 } |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8092 | 8166 |
8093 TEST_F(WebFrameTest, MaxFramesDetach) | 8167 TEST_F(WebFrameTest, MaxFramesDetach) |
8094 { | 8168 { |
8095 registerMockedHttpURLLoad("max-frames-detach.html"); | 8169 registerMockedHttpURLLoad("max-frames-detach.html"); |
8096 FrameTestHelpers::WebViewHelper webViewHelper; | 8170 FrameTestHelpers::WebViewHelper webViewHelper; |
8097 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "max- frames-detach.html", true); | 8171 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "max- frames-detach.html", true); |
8098 webViewImpl->mainFrameImpl()->collectGarbage(); | 8172 webViewImpl->mainFrameImpl()->collectGarbage(); |
8099 } | 8173 } |
8100 | 8174 |
8101 } // namespace blink | 8175 } // namespace blink |
OLD | NEW |