Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
|
Devlin
2016/11/14 17:44:38
no (c)
Ivan Šandrk
2016/11/14 20:16:13
Done.
| |
| 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 "extensions/browser/api/web_request/web_request_event_details.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace extensions { | |
| 10 | |
| 11 TEST(WebRequestEventDetailsTest, WhitelistedCopyForPublicSession) { | |
| 12 // Create the original instance and populate it with some values. | |
| 13 std::unique_ptr<WebRequestEventDetails> orig(new WebRequestEventDetails); | |
| 14 | |
| 15 orig->render_process_id_ = 1; | |
| 16 orig->render_frame_id_ = 2; | |
| 17 orig->extra_info_spec_ = 3; | |
| 18 | |
| 19 orig->request_body_.reset(new base::DictionaryValue); | |
| 20 orig->request_headers_.reset(new base::ListValue); | |
| 21 orig->response_headers_.reset(new base::ListValue); | |
| 22 | |
| 23 const char* const safe_attributes[] = { | |
| 24 "method", "requestId", "timeStamp", "type", "tabId", "frameId", | |
| 25 "parentFrameId", "fromCache", "error", "ip", "statusLine", "statusCode" | |
| 26 }; | |
| 27 | |
| 28 for (const char* safe_attr : safe_attributes) { | |
| 29 orig->dict_.SetString(safe_attr, safe_attr); | |
| 30 } | |
| 31 | |
| 32 orig->dict_.SetString("url", "http://www.foo.bar/baz"); | |
| 33 | |
| 34 // Add some extra dict_ values that should be filtered out. | |
| 35 orig->dict_.SetString("foo", "foo value"); | |
|
Devlin
2016/11/14 17:44:38
I'd prefer we stick to values that might be set -
Ivan Šandrk
2016/11/14 20:16:13
Done.
| |
| 36 orig->dict_.SetString("bar", "bar value"); | |
| 37 | |
| 38 // Make a copy and check that filtering works. | |
| 39 std::unique_ptr<WebRequestEventDetails> copy( | |
| 40 orig->WhitelistedCopyForPublicSession()); | |
| 41 | |
| 42 EXPECT_EQ(copy->render_process_id_, orig->render_process_id_); | |
| 43 EXPECT_EQ(copy->render_frame_id_, orig->render_frame_id_); | |
| 44 EXPECT_EQ(copy->extra_info_spec_, 0); | |
|
Devlin
2016/11/14 17:44:38
EXPECT_EQ(expected, actual)
Ivan Šandrk
2016/11/14 20:16:13
Done.
| |
| 45 | |
| 46 EXPECT_EQ(copy->request_body_, nullptr); | |
| 47 EXPECT_EQ(copy->request_headers_, nullptr); | |
| 48 EXPECT_EQ(copy->response_headers_, nullptr); | |
| 49 | |
| 50 for (const char* safe_attr : safe_attributes) { | |
| 51 std::string copy_str, orig_str; | |
| 52 copy->dict_.GetString(safe_attr, ©_str); | |
| 53 orig->dict_.GetString(safe_attr, &orig_str); | |
| 54 EXPECT_EQ(copy_str, orig_str); | |
| 55 } | |
| 56 | |
| 57 // URL is stripped down to origin. | |
| 58 std::string url; | |
| 59 copy->dict_.GetString("url", &url); | |
| 60 EXPECT_EQ(url, "http://www.foo.bar/"); | |
| 61 | |
| 62 // Extras are filtered out (+1 for url). | |
| 63 EXPECT_EQ(copy->dict_.size(), arraysize(safe_attributes) + 1); | |
| 64 } | |
| 65 | |
| 66 } // namespace extensions | |
| OLD | NEW |