| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/values.h" |
| 6 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
| 7 #include "chrome/browser/extensions/activity_log/activity_actions.h" |
| 8 #include "chrome/browser/extensions/activity_log/activity_log_policy.h" |
| 9 #include "chrome/browser/extensions/activity_log/web_request_constants.h" |
| 10 #include "chrome/common/extensions/value_builder.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 class ActivityLogPolicyUtilTest : public testing::Test {}; |
| 16 |
| 17 // Test that incognito values are stripped, and non-incognito ones aren't. |
| 18 TEST_F(ActivityLogPolicyUtilTest, StripPrivacySensitive) { |
| 19 scoped_refptr<Action> action = |
| 20 new Action("punky", |
| 21 base::Time::Now(), |
| 22 Action::ACTION_API_CALL, |
| 23 "tabs.executeScript"); |
| 24 action->mutable_args()->AppendString("woof"); |
| 25 action->set_page_url(GURL("http://www.google.com/")); |
| 26 action->set_page_incognito(true); |
| 27 action->set_page_title("private"); |
| 28 action->set_arg_url(GURL("http://www.youtube.com/?privatekey")); |
| 29 |
| 30 ASSERT_EQ("<incognito>http://www.google.com/", action->SerializePageUrl()); |
| 31 |
| 32 ActivityLogPolicy::Util::StripPrivacySensitiveFields(action); |
| 33 |
| 34 ASSERT_FALSE(action->page_url().is_valid()); |
| 35 ASSERT_EQ("<incognito>", action->SerializePageUrl()); |
| 36 ASSERT_EQ("", action->page_title()); |
| 37 ASSERT_EQ("http://www.youtube.com/", action->arg_url().spec()); |
| 38 } |
| 39 |
| 40 // Test that WebRequest details are stripped for privacy. |
| 41 TEST_F(ActivityLogPolicyUtilTest, StripPrivacySensitiveWebRequest) { |
| 42 scoped_refptr<Action> action = new Action( |
| 43 "punky", base::Time::Now(), Action::ACTION_WEB_REQUEST, "webRequest"); |
| 44 action->mutable_other()->Set( |
| 45 activity_log_constants::kActionWebRequest, |
| 46 DictionaryBuilder() |
| 47 .Set(activity_log_web_request_constants::kNewUrlKey, |
| 48 "http://www.youtube.com/") |
| 49 .Set(activity_log_web_request_constants::kAddedRequestHeadersKey, |
| 50 ListBuilder().Append("arg")) |
| 51 .Build().release()); |
| 52 |
| 53 ActivityLogPolicy::Util::StripPrivacySensitiveFields(action); |
| 54 |
| 55 ASSERT_EQ( |
| 56 "{\"web_request\":{\"added_request_headers\":true,\"new_url\":true}}", |
| 57 ActivityLogPolicy::Util::Serialize(action->other())); |
| 58 } |
| 59 |
| 60 // Test that argument values are stripped as appropriate. |
| 61 TEST_F(ActivityLogPolicyUtilTest, StripArguments) { |
| 62 std::set<std::string> whitelist; |
| 63 whitelist.insert("tabs.executeScript"); |
| 64 |
| 65 // API is in whitelist; not stripped. |
| 66 scoped_refptr<Action> action = |
| 67 new Action("punky", |
| 68 base::Time::Now(), |
| 69 Action::ACTION_API_CALL, |
| 70 "tabs.executeScript"); |
| 71 action->mutable_args()->AppendString("woof"); |
| 72 ActivityLogPolicy::Util::StripArguments(whitelist, action); |
| 73 ASSERT_EQ("[\"woof\"]", ActivityLogPolicy::Util::Serialize(action->args())); |
| 74 |
| 75 // Not in whitelist: stripped. |
| 76 action = new Action( |
| 77 "punky", base::Time::Now(), Action::ACTION_API_CALL, "tabs.create"); |
| 78 action->mutable_args()->AppendString("woof"); |
| 79 ActivityLogPolicy::Util::StripArguments(whitelist, action); |
| 80 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 } |
| 89 |
| 90 // Test parsing of URLs serialized to strings. |
| 91 TEST_F(ActivityLogPolicyUtilTest, ParseUrls) { |
| 92 scoped_refptr<Action> action = |
| 93 new Action("punky", |
| 94 base::Time::Now(), |
| 95 Action::ACTION_API_CALL, |
| 96 "tabs.executeScript"); |
| 97 action->ParsePageUrl("<incognito>http://www.google.com/"); |
| 98 EXPECT_EQ("http://www.google.com/", action->page_url().spec()); |
| 99 EXPECT_TRUE(action->page_incognito()); |
| 100 } |
| 101 |
| 102 } // namespace extensions |
| OLD | NEW |