OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "base/values.h" |
| 7 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 using base::BinaryValue; |
| 11 using base::ListValue; |
| 12 using base::StringValue; |
| 13 using base::Value; |
| 14 |
| 15 namespace extensions { |
| 16 |
| 17 // ChunkedErrorPresenter is tested within |
| 18 // ExtensionWebRequestTest.AccessRequestBodyData . |
| 19 |
| 20 // ParsedDataPresenter is tested on these places: |
| 21 // * The underlying parser in WebRequestFormDataParserTest. |
| 22 // * The extraction of data from URLRequest in |
| 23 // ExtensionWebRequestTest.AccessRequestBodyData. |
| 24 |
| 25 TEST(WebRequestUploadDataPresenterTest, RawData) { |
| 26 // Input. |
| 27 char block_data1[] = "test"; |
| 28 std::vector<char> block1(block_data1, block_data1 + arraysize(block_data1)); |
| 29 const char kFilename[] = "path/test_filename.ext"; |
| 30 char block_data2[] = "another test"; |
| 31 std::vector<char> block2(block_data2, block_data2 + arraysize(block_data2)); |
| 32 |
| 33 // Expected output. |
| 34 scoped_ptr<BinaryValue> expected_a( |
| 35 BinaryValue::CreateWithCopiedBuffer(&(block1[0]), block1.size())); |
| 36 ASSERT_TRUE(expected_a.get() != NULL); |
| 37 scoped_ptr<StringValue> expected_b(Value::CreateStringValue(kFilename)); |
| 38 ASSERT_TRUE(expected_b.get() != NULL); |
| 39 scoped_ptr<BinaryValue> expected_c( |
| 40 BinaryValue::CreateWithCopiedBuffer(&(block2[0]), block2.size())); |
| 41 ASSERT_TRUE(expected_c.get() != NULL); |
| 42 |
| 43 ListValue expected_list; |
| 44 expected_list.Append(expected_a.release()); |
| 45 expected_list.Append(expected_b.release()); |
| 46 expected_list.Append(expected_c.release()); |
| 47 |
| 48 // Real output. |
| 49 RawDataPresenter raw_presenter; |
| 50 raw_presenter.FeedNextBytes(block1); |
| 51 raw_presenter.FeedNextFile(kFilename); |
| 52 raw_presenter.FeedNextBytes(block2); |
| 53 EXPECT_TRUE(raw_presenter.Succeeded()); |
| 54 scoped_ptr<Value> result = raw_presenter.Result(); |
| 55 |
| 56 EXPECT_TRUE(result->Equals(&expected_list)); |
| 57 } |
| 58 |
| 59 } // namespace extensions |
OLD | NEW |