OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/values.h" | 5 #include "base/values.h" |
6 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" | 6 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
7 #include "chrome/browser/extensions/activity_log/activity_actions.h" | 7 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
8 #include "chrome/browser/extensions/activity_log/activity_log_policy.h" | 8 #include "chrome/browser/extensions/activity_log/activity_log_policy.h" |
9 #include "chrome/browser/extensions/activity_log/web_request_constants.h" | 9 #include "chrome/browser/extensions/activity_log/web_request_constants.h" |
10 #include "chrome/common/extensions/value_builder.h" | 10 #include "chrome/common/extensions/value_builder.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 ActivityLogPolicy::Util::StripPrivacySensitiveFields(action); | 53 ActivityLogPolicy::Util::StripPrivacySensitiveFields(action); |
54 | 54 |
55 ASSERT_EQ( | 55 ASSERT_EQ( |
56 "{\"web_request\":{\"added_request_headers\":true,\"new_url\":true}}", | 56 "{\"web_request\":{\"added_request_headers\":true,\"new_url\":true}}", |
57 ActivityLogPolicy::Util::Serialize(action->other())); | 57 ActivityLogPolicy::Util::Serialize(action->other())); |
58 } | 58 } |
59 | 59 |
60 // Test that argument values are stripped as appropriate. | 60 // Test that argument values are stripped as appropriate. |
61 TEST_F(ActivityLogPolicyUtilTest, StripArguments) { | 61 TEST_F(ActivityLogPolicyUtilTest, StripArguments) { |
62 std::set<std::string> whitelist; | 62 ActivityLogPolicy::Util::ApiSet whitelist; |
63 whitelist.insert("tabs.executeScript"); | 63 whitelist.insert( |
| 64 std::make_pair(Action::ACTION_API_CALL, "tabs.executeScript")); |
64 | 65 |
65 // API is in whitelist; not stripped. | 66 // API is in whitelist; not stripped. |
66 scoped_refptr<Action> action = | 67 scoped_refptr<Action> action = |
67 new Action("punky", | 68 new Action("punky", |
68 base::Time::Now(), | 69 base::Time::Now(), |
69 Action::ACTION_API_CALL, | 70 Action::ACTION_API_CALL, |
70 "tabs.executeScript"); | 71 "tabs.executeScript"); |
71 action->mutable_args()->AppendString("woof"); | 72 action->mutable_args()->AppendString("woof"); |
72 ActivityLogPolicy::Util::StripArguments(whitelist, action); | 73 ActivityLogPolicy::Util::StripArguments(whitelist, action); |
73 ASSERT_EQ("[\"woof\"]", ActivityLogPolicy::Util::Serialize(action->args())); | 74 ASSERT_EQ("[\"woof\"]", ActivityLogPolicy::Util::Serialize(action->args())); |
74 | 75 |
75 // Not in whitelist: stripped. | 76 // Not in whitelist: stripped. |
76 action = new Action( | 77 action = new Action( |
77 "punky", base::Time::Now(), Action::ACTION_API_CALL, "tabs.create"); | 78 "punky", base::Time::Now(), Action::ACTION_API_CALL, "tabs.create"); |
78 action->mutable_args()->AppendString("woof"); | 79 action->mutable_args()->AppendString("woof"); |
79 ActivityLogPolicy::Util::StripArguments(whitelist, action); | 80 ActivityLogPolicy::Util::StripArguments(whitelist, action); |
80 ASSERT_EQ("", ActivityLogPolicy::Util::Serialize(action->args())); | 81 ASSERT_EQ("", ActivityLogPolicy::Util::Serialize(action->args())); |
81 | |
82 // Not an API type: not stripped. | |
83 action = new Action( | |
84 "punky", base::Time::Now(), Action::ACTION_DOM_ACCESS, "tabs.create"); | |
85 action->mutable_args()->AppendString("woof"); | |
86 ActivityLogPolicy::Util::StripArguments(whitelist, action); | |
87 ASSERT_EQ("[\"woof\"]", ActivityLogPolicy::Util::Serialize(action->args())); | |
88 } | 82 } |
89 | 83 |
90 // Test parsing of URLs serialized to strings. | 84 // Test parsing of URLs serialized to strings. |
91 TEST_F(ActivityLogPolicyUtilTest, ParseUrls) { | 85 TEST_F(ActivityLogPolicyUtilTest, ParseUrls) { |
92 scoped_refptr<Action> action = | 86 scoped_refptr<Action> action = |
93 new Action("punky", | 87 new Action("punky", |
94 base::Time::Now(), | 88 base::Time::Now(), |
95 Action::ACTION_API_CALL, | 89 Action::ACTION_API_CALL, |
96 "tabs.executeScript"); | 90 "tabs.executeScript"); |
97 action->ParsePageUrl("<incognito>http://www.google.com/"); | 91 action->ParsePageUrl("<incognito>http://www.google.com/"); |
98 EXPECT_EQ("http://www.google.com/", action->page_url().spec()); | 92 EXPECT_EQ("http://www.google.com/", action->page_url().spec()); |
99 EXPECT_TRUE(action->page_incognito()); | 93 EXPECT_TRUE(action->page_incognito()); |
100 } | 94 } |
101 | 95 |
102 } // namespace extensions | 96 } // namespace extensions |
OLD | NEW |