Chromium Code Reviews| 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/base64.h" | |
| 6 #include "base/basictypes.h" | |
| 7 #include "base/values.h" | |
| 8 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.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 extensions { | |
| 17 | |
| 18 class WebRequestUploadDataPresenterTest : public testing::Test { | |
| 19 public: | |
| 20 WebRequestUploadDataPresenterTest() {} | |
| 21 | |
| 22 protected: | |
| 23 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.
| |
| 24 }; | |
| 25 | |
| 26 // ChunkedErrorPresenter is tested within | |
| 27 // ExtensionWebRequestTest.AccessRequestBodyData . | |
| 28 | |
| 29 // ParsedDataPresenter is tested on these places: | |
| 30 // * The underlying parser in WebRequestFormDataParserTest. | |
| 31 // * The extraction of data from URLRequest in | |
| 32 // ExtensionWebRequestTest.AccessRequestBodyData. | |
| 33 | |
| 34 TEST_F(WebRequestUploadDataPresenterTest, RawData) { | |
| 35 // Input. | |
| 36 char block_data1[] = "test"; | |
| 37 std::vector<char> block1(block_data1, block_data1 + arraysize(block_data1)); | |
| 38 const char kFilename[] = "path/test_filename.ext"; | |
| 39 char block_data2[] = "another test"; | |
| 40 std::vector<char> block2(block_data2, block_data2 + arraysize(block_data2)); | |
| 41 | |
| 42 // Expected output. | |
| 43 scoped_ptr<BinaryValue> expected_a( | |
| 44 BinaryValue::CreateWithCopiedBuffer(&(block1[0]), block1.size())); | |
| 45 ASSERT_TRUE(expected_a.get() != NULL); | |
| 46 std::string encoded_filename; | |
| 47 ASSERT_TRUE(base::Base64Encode(kFilename, &encoded_filename)); | |
| 48 scoped_ptr<StringValue> expected_b(new StringValue(encoded_filename)); | |
| 49 ASSERT_TRUE(expected_b.get() != NULL); | |
| 50 scoped_ptr<BinaryValue> expected_c( | |
| 51 BinaryValue::CreateWithCopiedBuffer(&(block2[0]), block2.size())); | |
| 52 ASSERT_TRUE(expected_c.get() != NULL); | |
| 53 | |
| 54 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
| |
| 55 expected_list.Append(expected_a.release()); | |
| 56 expected_list.Append(expected_b.release()); | |
| 57 expected_list.Append(expected_c.release()); | |
| 58 | |
| 59 // Real output. | |
| 60 RawDataPresenter raw_presenter; | |
| 61 raw_presenter.FeedNextBytes(block1); | |
| 62 raw_presenter.FeedNextFile(kFilename); | |
| 63 raw_presenter.FeedNextBytes(block2); | |
| 64 EXPECT_TRUE(raw_presenter.Succeeded()); | |
| 65 scoped_ptr<Value> result = raw_presenter.Result(); | |
| 66 | |
| 67 EXPECT_TRUE(result->Equals(&expected_list)); | |
| 68 } | |
| 69 | |
| 70 } // namespace extensions | |
| OLD | NEW |