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

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

Issue 2455393002: PS - Adjusting webRequest API for use in Public Sessions (Closed)
Patch Set: webRequest and webRequestBlocking are safe permissions now Created 4 years, 1 month 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 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;
54 copy->dict_.GetString(safe_attr, &copy_str);
55 EXPECT_EQ(safe_attr, copy_str);
56 }
57
58 // URL is stripped down to origin.
59 std::string url;
60 copy->dict_.GetString("url", &url);
61 EXPECT_EQ("http://www.foo.bar/", url);
62
63 // Extras are filtered out (+1 for url).
64 EXPECT_EQ(arraysize(safe_attributes) + 1, copy->dict_.size());
65 }
66
67 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698