Chromium Code Reviews| Index: chrome/browser/extensions/api/web_request/upload_data_presenter_unittest.cc |
| diff --git a/chrome/browser/extensions/api/web_request/upload_data_presenter_unittest.cc b/chrome/browser/extensions/api/web_request/upload_data_presenter_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d5c7f25872bbbefae3083936643e85e52f1c7588 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/web_request/upload_data_presenter_unittest.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/base64.h" |
| +#include "base/basictypes.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/extensions/api/web_request/upload_data_presenter.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using base::BinaryValue; |
| +using base::ListValue; |
| +using base::StringValue; |
| +using base::Value; |
| + |
| +namespace extensions { |
| + |
| +class WebRequestUploadDataPresenterTest : public testing::Test { |
| + public: |
| + WebRequestUploadDataPresenterTest() {} |
| + |
| + protected: |
| + virtual void SetUp() OVERRIDE {} |
|
battre
2012/08/16 19:18:03
if you don't set up anything, you can remove this
vabr (Chromium)
2012/08/17 18:29:57
Thanks! I did not know that.
|
| +}; |
| + |
| +// ChunkedErrorPresenter is tested within |
| +// ExtensionWebRequestTest.AccessRequestBodyData . |
| + |
| +// ParsedDataPresenter is tested on these places: |
| +// * The underlying parser in WebRequestFormDataParserTest. |
| +// * The extraction of data from URLRequest in |
| +// ExtensionWebRequestTest.AccessRequestBodyData. |
| + |
| +TEST_F(WebRequestUploadDataPresenterTest, RawData) { |
| + // Input. |
| + char block_data1[] = "test"; |
| + std::vector<char> block1(block_data1, block_data1 + arraysize(block_data1)); |
| + const char kFilename[] = "path/test_filename.ext"; |
| + char block_data2[] = "another test"; |
| + std::vector<char> block2(block_data2, block_data2 + arraysize(block_data2)); |
| + |
| + // Expected output. |
| + scoped_ptr<BinaryValue> expected_a( |
| + BinaryValue::CreateWithCopiedBuffer(&(block1[0]), block1.size())); |
| + ASSERT_TRUE(expected_a.get() != NULL); |
| + std::string encoded_filename; |
| + ASSERT_TRUE(base::Base64Encode(kFilename, &encoded_filename)); |
| + scoped_ptr<StringValue> expected_b(new StringValue(encoded_filename)); |
| + ASSERT_TRUE(expected_b.get() != NULL); |
| + scoped_ptr<BinaryValue> expected_c( |
| + BinaryValue::CreateWithCopiedBuffer(&(block2[0]), block2.size())); |
| + ASSERT_TRUE(expected_c.get() != NULL); |
| + |
| + ListValue expected_list; |
|
battre
2012/08/16 19:18:03
How does the consumer of this class know that the
vabr (Chromium)
2012/08/17 18:29:57
On the C++ level this is BinaryValue (bytes array)
battre
2012/08/20 12:09:38
I think this should be discussed with the extensio
vabr (Chromium)
2012/08/23 15:41:54
On a second thought, I refined the structure of re
|
| + expected_list.Append(expected_a.release()); |
| + expected_list.Append(expected_b.release()); |
| + expected_list.Append(expected_c.release()); |
| + |
| + // Real output. |
| + RawDataPresenter raw_presenter; |
| + raw_presenter.FeedNextBytes(block1); |
| + raw_presenter.FeedNextFile(kFilename); |
| + raw_presenter.FeedNextBytes(block2); |
| + EXPECT_TRUE(raw_presenter.Succeeded()); |
| + scoped_ptr<Value> result = raw_presenter.Result(); |
| + |
| + EXPECT_TRUE(result->Equals(&expected_list)); |
| +} |
| + |
| +} // namespace extensions |