Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "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 original and copy, and populate them with some values. | |
| 13 std::unique_ptr<WebRequestEventDetails> orig(new WebRequestEventDetails); | |
| 14 std::unique_ptr<WebRequestEventDetails> copy(new WebRequestEventDetails); | |
| 15 | |
| 16 const char* const safe_attributes[] = { | |
| 17 "method", "requestId", "timeStamp", "type", "tabId", "frameId", | |
| 18 "parentFrameId", "fromCache", "error", "ip", "statusLine", "statusCode" | |
| 19 }; | |
| 20 | |
| 21 for (WebRequestEventDetails* ptr : {orig.get(), copy.get()}) { | |
| 22 ptr->render_process_id_ = 1; | |
| 23 ptr->render_frame_id_ = 2; | |
| 24 ptr->extra_info_spec_ = 3; | |
| 25 | |
| 26 ptr->request_body_.reset(new base::DictionaryValue); | |
| 27 ptr->request_headers_.reset(new base::ListValue); | |
| 28 ptr->response_headers_.reset(new base::ListValue); | |
| 29 | |
| 30 for (const char* safe_attr : safe_attributes) { | |
| 31 ptr->dict_.SetString(safe_attr, safe_attr); | |
| 32 } | |
| 33 | |
| 34 ptr->dict_.SetString("url", "http://www.foo.bar/baz"); | |
| 35 | |
| 36 // Add some extra dict_ values that should be filtered out. | |
| 37 ptr->dict_.SetString("requestBody", "request body value"); | |
| 38 ptr->dict_.SetString("requestHeaders", "request headers value"); | |
| 39 } | |
| 40 | |
| 41 // Filter the copy out then check that filtering really works. | |
| 42 copy->FilterForPublicSession(); | |
| 43 | |
| 44 EXPECT_EQ(orig->render_process_id_, copy->render_process_id_); | |
| 45 EXPECT_EQ(orig->render_frame_id_, copy->render_frame_id_); | |
| 46 EXPECT_EQ(0, copy->extra_info_spec_); | |
| 47 | |
| 48 EXPECT_EQ(nullptr, copy->request_body_); | |
| 49 EXPECT_EQ(nullptr, copy->request_headers_); | |
| 50 EXPECT_EQ(nullptr, copy->response_headers_); | |
| 51 | |
| 52 for (const char* safe_attr : safe_attributes) { | |
| 53 std::string copy_str, orig_str; | |
|
Devlin
2016/11/15 15:12:02
nit: chromium style says one variable per line, so
Ivan Šandrk
2016/11/15 16:07:39
Done.
| |
| 54 copy->dict_.GetString(safe_attr, ©_str); | |
|
Devlin
2016/11/15 15:12:02
We should know that the string value is |safe_attr
Ivan Šandrk
2016/11/15 16:07:39
Good point, done.
| |
| 55 orig->dict_.GetString(safe_attr, &orig_str); | |
| 56 EXPECT_EQ(orig_str, copy_str); | |
| 57 } | |
| 58 | |
| 59 // URL is stripped down to origin. | |
| 60 std::string url; | |
| 61 copy->dict_.GetString("url", &url); | |
| 62 EXPECT_EQ("http://www.foo.bar/", url); | |
| 63 | |
| 64 // Extras are filtered out (+1 for url). | |
| 65 EXPECT_EQ(arraysize(safe_attributes) + 1, copy->dict_.size()); | |
| 66 } | |
| 67 | |
| 68 } // namespace extensions | |
| OLD | NEW |