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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/FormDataBytesConsumerTest.cpp

Issue 2376193004: Stop FetchDataLoaderTest from using [Web|Fetch]DataConsumerHandle. (Closed)
Patch Set: fix Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "modules/fetch/FormDataBytesConsumer.h" 5 #include "modules/fetch/FormDataBytesConsumer.h"
6 6
7 #include "core/dom/DOMArrayBuffer.h" 7 #include "core/dom/DOMArrayBuffer.h"
8 #include "core/dom/DOMTypedArray.h" 8 #include "core/dom/DOMTypedArray.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/html/FormData.h" 10 #include "core/html/FormData.h"
11 #include "core/testing/DummyPageHolder.h" 11 #include "core/testing/DummyPageHolder.h"
12 #include "modules/fetch/BytesConsumerTestUtil.h" 12 #include "modules/fetch/BytesConsumerTestUtil.h"
13 #include "platform/blob/BlobData.h" 13 #include "platform/blob/BlobData.h"
14 #include "platform/network/EncodedFormData.h" 14 #include "platform/network/EncodedFormData.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "wtf/RefPtr.h" 17 #include "wtf/RefPtr.h"
18 #include "wtf/Vector.h" 18 #include "wtf/Vector.h"
19 #include "wtf/text/WTFString.h" 19 #include "wtf/text/WTFString.h"
20 20
21 namespace blink { 21 namespace blink {
22 namespace { 22 namespace {
23 23
24 using Result = BytesConsumer::Result; 24 using Result = BytesConsumer::Result;
25 using ::testing::_; 25 using ::testing::_;
26 using ::testing::DoAll; 26 using ::testing::DoAll;
27 using ::testing::InSequence; 27 using ::testing::InSequence;
28 using ::testing::Return; 28 using ::testing::Return;
29 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; 29 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>;
30 using MockBytesConsumer = BytesConsumerTestUtil::MockBytesConsumer;
30 31
31 String toString(const Vector<char>& v) 32 String toString(const Vector<char>& v)
32 { 33 {
33 return String(v.data(), v.size()); 34 return String(v.data(), v.size());
34 } 35 }
35 36
36 PassRefPtr<EncodedFormData> complexFormData() 37 PassRefPtr<EncodedFormData> complexFormData()
37 { 38 {
38 RefPtr<EncodedFormData> data = EncodedFormData::create(); 39 RefPtr<EncodedFormData> data = EncodedFormData::create();
39 40
(...skipping 10 matching lines...) Expand all
50 data->setBoundary(boundary); 51 data->setBoundary(boundary);
51 return data.release(); 52 return data.release();
52 } 53 }
53 54
54 class NoopClient final : public GarbageCollectedFinalized<NoopClient>, public By tesConsumer::Client { 55 class NoopClient final : public GarbageCollectedFinalized<NoopClient>, public By tesConsumer::Client {
55 USING_GARBAGE_COLLECTED_MIXIN(NoopClient); 56 USING_GARBAGE_COLLECTED_MIXIN(NoopClient);
56 public: 57 public:
57 void onStateChange() override {} 58 void onStateChange() override {}
58 }; 59 };
59 60
60 class MockBytesConsumer : public BytesConsumer {
61 public:
62 static MockBytesConsumer* create() { return new ::testing::StrictMock<MockBy tesConsumer>(); }
63
64 MOCK_METHOD2(beginRead, Result(const char**, size_t*));
65 MOCK_METHOD1(endRead, Result(size_t));
66 MOCK_METHOD1(setClient, void(Client*));
67 MOCK_METHOD0(clearClient, void());
68 MOCK_METHOD0(cancel, void());
69 MOCK_CONST_METHOD0(getPublicState, PublicState());
70 MOCK_CONST_METHOD0(getError, Error());
71
72 String debugName() const override { return "MockBytesConsumer"; }
73
74 protected:
75 MockBytesConsumer() = default;
76 };
77
78 class FormDataBytesConsumerTest : public ::testing::Test { 61 class FormDataBytesConsumerTest : public ::testing::Test {
79 public: 62 public:
80 FormDataBytesConsumerTest() : m_page(DummyPageHolder::create()) {} 63 FormDataBytesConsumerTest() : m_page(DummyPageHolder::create()) {}
81 64
82 protected: 65 protected:
83 Document* getDocument() { return &m_page->document(); } 66 Document* getDocument() { return &m_page->document(); }
84 67
85 std::unique_ptr<DummyPageHolder> m_page; 68 std::unique_ptr<DummyPageHolder> m_page;
86 }; 69 };
87 70
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 300
318 const char* buffer = nullptr; 301 const char* buffer = nullptr;
319 size_t available = 0; 302 size_t available = 0;
320 Checkpoint checkpoint; 303 Checkpoint checkpoint;
321 304
322 InSequence s; 305 InSequence s;
323 EXPECT_CALL(checkpoint, Call(1)); 306 EXPECT_CALL(checkpoint, Call(1));
324 EXPECT_CALL(*underlying, beginRead(&buffer, &available)).WillOnce(Return(Res ult::Ok)); 307 EXPECT_CALL(*underlying, beginRead(&buffer, &available)).WillOnce(Return(Res ult::Ok));
325 EXPECT_CALL(*underlying, endRead(0)).WillOnce(Return(Result::Ok)); 308 EXPECT_CALL(*underlying, endRead(0)).WillOnce(Return(Result::Ok));
326 EXPECT_CALL(checkpoint, Call(2)); 309 EXPECT_CALL(checkpoint, Call(2));
327 // drainAsFormData / drainAsBlobDataHandle should not be called here. 310 // drainAsFormData / drainAsBlobDataHandle should not be called here.
yhirano 2016/09/30 09:18:09 I think this expectation was wrong. Calling drainA
328 EXPECT_CALL(checkpoint, Call(3)); 311 EXPECT_CALL(checkpoint, Call(3));
329 // |consumer| delegates the getPublicState call to |underlying|. 312 // |consumer| delegates the getPublicState call to |underlying|.
330 EXPECT_CALL(*underlying, getPublicState()).WillOnce(Return(BytesConsumer::Pu blicState::ReadableOrWaiting)); 313 EXPECT_CALL(*underlying, getPublicState()).WillOnce(Return(BytesConsumer::Pu blicState::ReadableOrWaiting));
331 EXPECT_CALL(checkpoint, Call(4)); 314 EXPECT_CALL(checkpoint, Call(4));
332 315
333 checkpoint.Call(1); 316 checkpoint.Call(1);
334 ASSERT_EQ(Result::Ok, consumer->beginRead(&buffer, &available)); 317 ASSERT_EQ(Result::Ok, consumer->beginRead(&buffer, &available));
335 ASSERT_EQ(Result::Ok, consumer->endRead(0)); 318 ASSERT_EQ(Result::Ok, consumer->endRead(0));
336 checkpoint.Call(2); 319 checkpoint.Call(2);
337 EXPECT_FALSE(consumer->drainAsFormData()); 320 EXPECT_FALSE(consumer->drainAsFormData());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 EXPECT_CALL(*underlying, cancel()); 359 EXPECT_CALL(*underlying, cancel());
377 EXPECT_CALL(checkpoint, Call(2)); 360 EXPECT_CALL(checkpoint, Call(2));
378 361
379 checkpoint.Call(1); 362 checkpoint.Call(1);
380 consumer->cancel(); 363 consumer->cancel();
381 checkpoint.Call(2); 364 checkpoint.Call(2);
382 } 365 }
383 366
384 } // namespace 367 } // namespace
385 } // namespace blink 368 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698