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

Side by Side Diff: third_party/WebKit/Source/web/tests/DocumentLoaderTest.cpp

Issue 2510333002: Send encoded_body_length to renderer when response completed (2/3) (Closed)
Patch Set: rebase Created 4 years 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/loader/DocumentLoader.h" 5 #include "core/loader/DocumentLoader.h"
6 6
7 #include "core/page/Page.h" 7 #include "core/page/Page.h"
8 #include "platform/testing/URLTestHelpers.h" 8 #include "platform/testing/URLTestHelpers.h"
9 #include "public/platform/Platform.h" 9 #include "public/platform/Platform.h"
10 #include "public/platform/WebURLLoaderClient.h" 10 #include "public/platform/WebURLLoaderClient.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 TEST_F(DocumentLoaderTest, SingleChunk) { 43 TEST_F(DocumentLoaderTest, SingleChunk) {
44 class TestDelegate : public WebURLLoaderTestDelegate { 44 class TestDelegate : public WebURLLoaderTestDelegate {
45 public: 45 public:
46 void didReceiveData(WebURLLoaderClient* originalClient, 46 void didReceiveData(WebURLLoaderClient* originalClient,
47 WebURLLoader* loader, 47 WebURLLoader* loader,
48 const char* data, 48 const char* data,
49 int dataLength, 49 int dataLength,
50 int encodedDataLength) override { 50 int encodedDataLength) override {
51 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk"; 51 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk";
52 originalClient->didReceiveData(loader, data, dataLength, 52 originalClient->didReceiveData(loader, data, dataLength,
53 encodedDataLength, dataLength); 53 encodedDataLength);
54 } 54 }
55 } delegate; 55 } delegate;
56 56
57 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(&delegate); 57 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(&delegate);
58 FrameTestHelpers::loadFrame(mainFrame(), "https://example.com/foo.html"); 58 FrameTestHelpers::loadFrame(mainFrame(), "https://example.com/foo.html");
59 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr); 59 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr);
60 60
61 // TODO(dcheng): How should the test verify that the original callback is 61 // TODO(dcheng): How should the test verify that the original callback is
62 // invoked? The test currently still passes even if the test delegate 62 // invoked? The test currently still passes even if the test delegate
63 // forgets to invoke the callback. 63 // forgets to invoke the callback.
64 } 64 }
65 65
66 // Test normal case of DocumentLoader::dataReceived(): data in multiple chunks, 66 // Test normal case of DocumentLoader::dataReceived(): data in multiple chunks,
67 // with no reentrancy. 67 // with no reentrancy.
68 TEST_F(DocumentLoaderTest, MultiChunkNoReentrancy) { 68 TEST_F(DocumentLoaderTest, MultiChunkNoReentrancy) {
69 class TestDelegate : public WebURLLoaderTestDelegate { 69 class TestDelegate : public WebURLLoaderTestDelegate {
70 public: 70 public:
71 void didReceiveData(WebURLLoaderClient* originalClient, 71 void didReceiveData(WebURLLoaderClient* originalClient,
72 WebURLLoader* loader, 72 WebURLLoader* loader,
73 const char* data, 73 const char* data,
74 int dataLength, 74 int dataLength,
75 int encodedDataLength) override { 75 int encodedDataLength) override {
76 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk"; 76 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk";
77 // Chunk the reply into one byte chunks. 77 // Chunk the reply into one byte chunks.
78 for (int i = 0; i < dataLength; ++i) 78 for (int i = 0; i < dataLength; ++i)
79 originalClient->didReceiveData(loader, &data[i], 1, 1, 1); 79 originalClient->didReceiveData(loader, &data[i], 1, 1);
80 } 80 }
81 } delegate; 81 } delegate;
82 82
83 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(&delegate); 83 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(&delegate);
84 FrameTestHelpers::loadFrame(mainFrame(), "https://example.com/foo.html"); 84 FrameTestHelpers::loadFrame(mainFrame(), "https://example.com/foo.html");
85 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr); 85 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr);
86 } 86 }
87 87
88 // Finally, test reentrant callbacks to DocumentLoader::dataReceived(). 88 // Finally, test reentrant callbacks to DocumentLoader::dataReceived().
89 TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) { 89 TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 while (m_data.size() > 10) 140 while (m_data.size() > 10)
141 dispatchOneByte(); 141 dispatchOneByte();
142 m_servedReentrantly = true; 142 m_servedReentrantly = true;
143 } 143 }
144 TestWebFrameClient::frameDetached(frame, detachType); 144 TestWebFrameClient::frameDetached(frame, detachType);
145 } 145 }
146 146
147 void dispatchOneByte() { 147 void dispatchOneByte() {
148 char c = m_data.front(); 148 char c = m_data.front();
149 m_data.pop(); 149 m_data.pop();
150 m_loaderClient->didReceiveData(m_loader, &c, 1, 1, 1); 150 m_loaderClient->didReceiveData(m_loader, &c, 1, 1);
151 } 151 }
152 152
153 bool servedReentrantly() const { return m_servedReentrantly; } 153 bool servedReentrantly() const { return m_servedReentrantly; }
154 154
155 private: 155 private:
156 WebURLLoaderClient* m_loaderClient; 156 WebURLLoaderClient* m_loaderClient;
157 WebURLLoader* m_loader; 157 WebURLLoader* m_loader;
158 std::queue<char> m_data; 158 std::queue<char> m_data;
159 bool m_dispatchingDidReceiveData; 159 bool m_dispatchingDidReceiveData;
160 bool m_servedReentrantly; 160 bool m_servedReentrantly;
(...skipping 19 matching lines...) Expand all
180 TEST_F(DocumentLoaderTest, isCommittedButEmpty) { 180 TEST_F(DocumentLoaderTest, isCommittedButEmpty) {
181 WebViewImpl* webViewImpl = 181 WebViewImpl* webViewImpl =
182 m_webViewHelper.initializeAndLoad("about:blank", true); 182 m_webViewHelper.initializeAndLoad("about:blank", true);
183 EXPECT_TRUE(toLocalFrame(webViewImpl->page()->mainFrame()) 183 EXPECT_TRUE(toLocalFrame(webViewImpl->page()->mainFrame())
184 ->loader() 184 ->loader()
185 .documentLoader() 185 .documentLoader()
186 ->isCommittedButEmpty()); 186 ->isCommittedButEmpty());
187 } 187 }
188 188
189 } // namespace blink 189 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/testing/weburl_loader_mock.cc ('k') | third_party/WebKit/Source/web/tests/WebFrameTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698