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

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

Issue 2540023003: Dispatch encoded_data_length separately in content/child (Closed)
Patch Set: fix 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 27 matching lines...) Expand all
38 } 38 }
39 39
40 FrameTestHelpers::WebViewHelper m_webViewHelper; 40 FrameTestHelpers::WebViewHelper m_webViewHelper;
41 }; 41 };
42 42
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 const char* data, 47 const char* data,
48 int dataLength, 48 int dataLength) override {
49 int encodedDataLength) override {
50 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk"; 49 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk";
51 originalClient->didReceiveData(data, dataLength, encodedDataLength); 50 originalClient->didReceiveData(data, dataLength);
52 } 51 }
53 } delegate; 52 } delegate;
54 53
55 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(&delegate); 54 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(&delegate);
56 FrameTestHelpers::loadFrame(mainFrame(), "https://example.com/foo.html"); 55 FrameTestHelpers::loadFrame(mainFrame(), "https://example.com/foo.html");
57 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr); 56 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr);
58 57
59 // TODO(dcheng): How should the test verify that the original callback is 58 // TODO(dcheng): How should the test verify that the original callback is
60 // invoked? The test currently still passes even if the test delegate 59 // invoked? The test currently still passes even if the test delegate
61 // forgets to invoke the callback. 60 // forgets to invoke the callback.
62 } 61 }
63 62
64 // Test normal case of DocumentLoader::dataReceived(): data in multiple chunks, 63 // Test normal case of DocumentLoader::dataReceived(): data in multiple chunks,
65 // with no reentrancy. 64 // with no reentrancy.
66 TEST_F(DocumentLoaderTest, MultiChunkNoReentrancy) { 65 TEST_F(DocumentLoaderTest, MultiChunkNoReentrancy) {
67 class TestDelegate : public WebURLLoaderTestDelegate { 66 class TestDelegate : public WebURLLoaderTestDelegate {
68 public: 67 public:
69 void didReceiveData(WebURLLoaderClient* originalClient, 68 void didReceiveData(WebURLLoaderClient* originalClient,
70 const char* data, 69 const char* data,
71 int dataLength, 70 int dataLength) override {
72 int encodedDataLength) override {
73 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk"; 71 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk";
74 // Chunk the reply into one byte chunks. 72 // Chunk the reply into one byte chunks.
75 for (int i = 0; i < dataLength; ++i) 73 for (int i = 0; i < dataLength; ++i)
76 originalClient->didReceiveData(&data[i], 1, 1); 74 originalClient->didReceiveData(&data[i], 1);
77 } 75 }
78 } delegate; 76 } delegate;
79 77
80 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(&delegate); 78 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(&delegate);
81 FrameTestHelpers::loadFrame(mainFrame(), "https://example.com/foo.html"); 79 FrameTestHelpers::loadFrame(mainFrame(), "https://example.com/foo.html");
82 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr); 80 Platform::current()->getURLLoaderMockFactory()->setLoaderDelegate(nullptr);
83 } 81 }
84 82
85 // Finally, test reentrant callbacks to DocumentLoader::dataReceived(). 83 // Finally, test reentrant callbacks to DocumentLoader::dataReceived().
86 TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) { 84 TEST_F(DocumentLoaderTest, MultiChunkWithReentrancy) {
87 // This test delegate chunks the response stage into three distinct stages: 85 // This test delegate chunks the response stage into three distinct stages:
88 // 1. The first dataReceived() callback, which triggers frame detach due to 86 // 1. The first dataReceived() callback, which triggers frame detach due to
89 // commiting a provisional load. 87 // commiting a provisional load.
90 // 2. The middle part of the response, which is dispatched to 88 // 2. The middle part of the response, which is dispatched to
91 // dataReceived() reentrantly. 89 // dataReceived() reentrantly.
92 // 3. The final chunk, which is dispatched normally at the top-level. 90 // 3. The final chunk, which is dispatched normally at the top-level.
93 class TestDelegate : public WebURLLoaderTestDelegate, 91 class TestDelegate : public WebURLLoaderTestDelegate,
94 public FrameTestHelpers::TestWebFrameClient { 92 public FrameTestHelpers::TestWebFrameClient {
95 public: 93 public:
96 TestDelegate() 94 TestDelegate()
97 : m_loaderClient(nullptr), 95 : m_loaderClient(nullptr),
98 m_dispatchingDidReceiveData(false), 96 m_dispatchingDidReceiveData(false),
99 m_servedReentrantly(false) {} 97 m_servedReentrantly(false) {}
100 98
101 // WebURLLoaderTestDelegate overrides: 99 // WebURLLoaderTestDelegate overrides:
102 void didReceiveData(WebURLLoaderClient* originalClient, 100 void didReceiveData(WebURLLoaderClient* originalClient,
103 const char* data, 101 const char* data,
104 int dataLength, 102 int dataLength) override {
105 int encodedDataLength) override {
106 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk"; 103 EXPECT_EQ(34, dataLength) << "foo.html was not served in a single chunk";
107 104
108 m_loaderClient = originalClient; 105 m_loaderClient = originalClient;
109 for (int i = 0; i < dataLength; ++i) 106 for (int i = 0; i < dataLength; ++i)
110 m_data.push(data[i]); 107 m_data.push(data[i]);
111 108
112 { 109 {
113 // Serve the first byte to the real WebURLLoaderCLient, which 110 // Serve the first byte to the real WebURLLoaderCLient, which
114 // should trigger frameDetach() due to committing a provisional 111 // should trigger frameDetach() due to committing a provisional
115 // load. 112 // load.
(...skipping 18 matching lines...) Expand all
134 while (m_data.size() > 10) 131 while (m_data.size() > 10)
135 dispatchOneByte(); 132 dispatchOneByte();
136 m_servedReentrantly = true; 133 m_servedReentrantly = true;
137 } 134 }
138 TestWebFrameClient::frameDetached(frame, detachType); 135 TestWebFrameClient::frameDetached(frame, detachType);
139 } 136 }
140 137
141 void dispatchOneByte() { 138 void dispatchOneByte() {
142 char c = m_data.front(); 139 char c = m_data.front();
143 m_data.pop(); 140 m_data.pop();
144 m_loaderClient->didReceiveData(&c, 1, 1); 141 m_loaderClient->didReceiveData(&c, 1);
145 } 142 }
146 143
147 bool servedReentrantly() const { return m_servedReentrantly; } 144 bool servedReentrantly() const { return m_servedReentrantly; }
148 145
149 private: 146 private:
150 WebURLLoaderClient* m_loaderClient; 147 WebURLLoaderClient* m_loaderClient;
151 std::queue<char> m_data; 148 std::queue<char> m_data;
152 bool m_dispatchingDidReceiveData; 149 bool m_dispatchingDidReceiveData;
153 bool m_servedReentrantly; 150 bool m_servedReentrantly;
154 } delegate; 151 } delegate;
(...skipping 18 matching lines...) Expand all
173 TEST_F(DocumentLoaderTest, isCommittedButEmpty) { 170 TEST_F(DocumentLoaderTest, isCommittedButEmpty) {
174 WebViewImpl* webViewImpl = 171 WebViewImpl* webViewImpl =
175 m_webViewHelper.initializeAndLoad("about:blank", true); 172 m_webViewHelper.initializeAndLoad("about:blank", true);
176 EXPECT_TRUE(toLocalFrame(webViewImpl->page()->mainFrame()) 173 EXPECT_TRUE(toLocalFrame(webViewImpl->page()->mainFrame())
177 ->loader() 174 ->loader()
178 .documentLoader() 175 .documentLoader()
179 ->isCommittedButEmpty()); 176 ->isCommittedButEmpty());
180 } 177 }
181 178
182 } // namespace blink 179 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698