| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.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" | 8 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" |
| 9 #include "net/base/upload_element.h" | 9 #include "net/base/upload_bytes_element_reader.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 using base::BinaryValue; | 12 using base::BinaryValue; |
| 13 using base::ListValue; | 13 using base::ListValue; |
| 14 using base::StringValue; | 14 using base::StringValue; |
| 15 using base::Value; | 15 using base::Value; |
| 16 | 16 |
| 17 namespace keys = extension_web_request_api_constants; | 17 namespace keys = extension_web_request_api_constants; |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 // This only tests the handling of dots in keys. Other functionality is covered | 21 // This only tests the handling of dots in keys. Other functionality is covered |
| 22 // by ExtensionWebRequestTest.AccessRequestBodyData and | 22 // by ExtensionWebRequestTest.AccessRequestBodyData and |
| 23 // WebRequestFormDataParserTest. | 23 // WebRequestFormDataParserTest. |
| 24 TEST(WebRequestUploadDataPresenterTest, ParsedData) { | 24 TEST(WebRequestUploadDataPresenterTest, ParsedData) { |
| 25 // Input. | 25 // Input. |
| 26 const char block[] = "key.with.dots=value"; | 26 const char block[] = "key.with.dots=value"; |
| 27 net::UploadElement element; | 27 net::UploadBytesElementReader element(block, sizeof(block) - 1); |
| 28 element.SetToBytes(block, sizeof(block) - 1); | |
| 29 | 28 |
| 30 // Expected output. | 29 // Expected output. |
| 31 scoped_ptr<ListValue> values(new ListValue); | 30 scoped_ptr<ListValue> values(new ListValue); |
| 32 values->Append(Value::CreateStringValue("value")); | 31 values->Append(Value::CreateStringValue("value")); |
| 33 DictionaryValue expected_form; | 32 DictionaryValue expected_form; |
| 34 expected_form.SetWithoutPathExpansion("key.with.dots", values.release()); | 33 expected_form.SetWithoutPathExpansion("key.with.dots", values.release()); |
| 35 | 34 |
| 36 // Real output. | 35 // Real output. |
| 37 scoped_ptr<ParsedDataPresenter> parsed_data_presenter( | 36 scoped_ptr<ParsedDataPresenter> parsed_data_presenter( |
| 38 ParsedDataPresenter::CreateForTests()); | 37 ParsedDataPresenter::CreateForTests()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 raw_presenter.FeedNextFile(kFilename); | 76 raw_presenter.FeedNextFile(kFilename); |
| 78 raw_presenter.FeedNextBytes(block2, block2_size); | 77 raw_presenter.FeedNextBytes(block2, block2_size); |
| 79 EXPECT_TRUE(raw_presenter.Succeeded()); | 78 EXPECT_TRUE(raw_presenter.Succeeded()); |
| 80 scoped_ptr<Value> result = raw_presenter.Result(); | 79 scoped_ptr<Value> result = raw_presenter.Result(); |
| 81 ASSERT_TRUE(result.get() != NULL); | 80 ASSERT_TRUE(result.get() != NULL); |
| 82 | 81 |
| 83 EXPECT_TRUE(result->Equals(&expected_list)); | 82 EXPECT_TRUE(result->Equals(&expected_list)); |
| 84 } | 83 } |
| 85 | 84 |
| 86 } // namespace extensions | 85 } // namespace extensions |
| OLD | NEW |