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 "chrome/browser/extensions/api/web_request/web_request_api_constants.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 using base::BinaryValue; |
| 12 using base::ListValue; |
| 13 using base::StringValue; |
| 14 using base::Value; |
| 15 |
| 16 namespace keys = extension_web_request_api_constants; |
| 17 |
| 18 namespace extensions { |
| 19 |
| 20 // ChunkedErrorPresenter is tested within |
| 21 // ExtensionWebRequestTest.AccessRequestBodyData . |
| 22 |
| 23 // ParsedDataPresenter is tested on these places: |
| 24 // * The underlying parser in WebRequestFormDataParserTest. |
| 25 // * The extraction of data from URLRequest in |
| 26 // ExtensionWebRequestTest.AccessRequestBodyData. |
| 27 |
| 28 TEST(WebRequestUploadDataPresenterTest, RawData) { |
| 29 // Input. |
| 30 const char block1[] = "test"; |
| 31 const size_t block1_size = strlen(block1); |
| 32 const char kFilename[] = "path/test_filename.ext"; |
| 33 const char block2[] = "another test"; |
| 34 const size_t block2_size = strlen(block2); |
| 35 |
| 36 // Expected output. |
| 37 scoped_ptr<BinaryValue> expected_a( |
| 38 BinaryValue::CreateWithCopiedBuffer(block1, block1_size)); |
| 39 ASSERT_TRUE(expected_a.get() != NULL); |
| 40 scoped_ptr<StringValue> expected_b(Value::CreateStringValue(kFilename)); |
| 41 ASSERT_TRUE(expected_b.get() != NULL); |
| 42 scoped_ptr<BinaryValue> expected_c( |
| 43 BinaryValue::CreateWithCopiedBuffer(block2, block2_size)); |
| 44 ASSERT_TRUE(expected_c.get() != NULL); |
| 45 |
| 46 ListValue expected_list; |
| 47 RawDataPresenter::AppendResultWithKey( |
| 48 &expected_list, keys::kRequestBodyRawBytesKey, expected_a.release()); |
| 49 RawDataPresenter::AppendResultWithKey( |
| 50 &expected_list, keys::kRequestBodyRawFileKey, expected_b.release()); |
| 51 RawDataPresenter::AppendResultWithKey( |
| 52 &expected_list, keys::kRequestBodyRawBytesKey, expected_c.release()); |
| 53 |
| 54 // Real output. |
| 55 RawDataPresenter raw_presenter; |
| 56 raw_presenter.FeedNextBytes(block1, block1_size); |
| 57 raw_presenter.FeedNextFile(kFilename); |
| 58 raw_presenter.FeedNextBytes(block2, block2_size); |
| 59 EXPECT_TRUE(raw_presenter.Succeeded()); |
| 60 scoped_ptr<Value> result = raw_presenter.Result(); |
| 61 |
| 62 EXPECT_TRUE(result->Equals(&expected_list)); |
| 63 } |
| 64 |
| 65 } // namespace extensions |
OLD | NEW |