Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/extensions/api/web_request/upload_data_presenter_unittest.cc

Issue 10694055: Add read-only access to POST data for webRequest's onBeforeRequest (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Indents corrected + LazyInstance made Leaky Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // 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 const char block1[] = "test";
28 const size_t block1_size = sizeof(block1) - 1;
29 const char kFilename[] = "path/test_filename.ext";
30 const char block2[] = "another test";
31 const size_t block2_size = sizeof(block2) - 1;
32
33 // Expected output.
34 scoped_ptr<BinaryValue> expected_a(
35 BinaryValue::CreateWithCopiedBuffer(block1, 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, block2_size));
41 ASSERT_TRUE(expected_c.get() != NULL);
42
43 ListValue expected_list;
44 RawDataPresenter::AppendResultWithKey(
45 &expected_list, keys::kRequestBodyRawBytesKey, expected_a.release());
46 RawDataPresenter::AppendResultWithKey(
47 &expected_list, keys::kRequestBodyRawFileKey, expected_b.release());
48 RawDataPresenter::AppendResultWithKey(
49 &expected_list, keys::kRequestBodyRawBytesKey, expected_c.release());
50
51 // Real output.
52 RawDataPresenter raw_presenter;
53 raw_presenter.FeedNextBytes(block1, block1_size);
54 raw_presenter.FeedNextFile(kFilename);
55 raw_presenter.FeedNextBytes(block2, block2_size);
56 EXPECT_TRUE(raw_presenter.Succeeded());
57 scoped_ptr<Value> result = raw_presenter.Result();
battre 2012/09/09 22:08:35 ASSERT_TRUE(result.get());
vabr (Chromium) 2012/09/12 11:18:08 Done.
58
59 EXPECT_TRUE(result->Equals(&expected_list));
60 }
61
62 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698