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.
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 "extensions/browser/api/activity_log/web_request_constants.h"
10 #include "extensions/common/value_builder.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace extensions
{
15 class ActivityLogPolicyUtilTest
: public testing::Test
{};
17 // Test that incognito values are stripped, and non-incognito ones aren't.
18 TEST_F(ActivityLogPolicyUtilTest
, StripPrivacySensitive
) {
19 scoped_refptr
<Action
> action
=
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"));
30 ASSERT_EQ("<incognito>http://www.google.com/", action
->SerializePageUrl());
32 ActivityLogPolicy::Util::StripPrivacySensitiveFields(action
);
34 ASSERT_FALSE(action
->page_url().is_valid());
35 ASSERT_EQ("", action
->SerializePageUrl());
36 ASSERT_EQ("", action
->page_title());
37 ASSERT_EQ("http://www.youtube.com/", action
->arg_url().spec());
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
,
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"))
53 ActivityLogPolicy::Util::StripPrivacySensitiveFields(action
);
56 "{\"web_request\":{\"added_request_headers\":true,\"new_url\":true}}",
57 ActivityLogPolicy::Util::Serialize(action
->other()));
60 // Test that argument values are stripped as appropriate.
61 TEST_F(ActivityLogPolicyUtilTest
, StripArguments
) {
62 ActivityLogPolicy::Util::ApiSet whitelist
;
64 std::make_pair(Action::ACTION_API_CALL
, "tabs.executeScript"));
66 // API is in whitelist; not stripped.
67 scoped_refptr
<Action
> action
=
70 Action::ACTION_API_CALL
,
71 "tabs.executeScript");
72 action
->mutable_args()->AppendString("woof");
73 ActivityLogPolicy::Util::StripArguments(whitelist
, action
);
74 ASSERT_EQ("[\"woof\"]", ActivityLogPolicy::Util::Serialize(action
->args()));
76 // Not in whitelist: stripped.
78 "punky", base::Time::Now(), Action::ACTION_API_CALL
, "tabs.create");
79 action
->mutable_args()->AppendString("woof");
80 ActivityLogPolicy::Util::StripArguments(whitelist
, action
);
81 ASSERT_EQ("", ActivityLogPolicy::Util::Serialize(action
->args()));
84 // Test parsing of URLs serialized to strings.
85 TEST_F(ActivityLogPolicyUtilTest
, ParseUrls
) {
86 scoped_refptr
<Action
> action
=
89 Action::ACTION_API_CALL
,
90 "tabs.executeScript");
91 action
->ParsePageUrl("<incognito>http://www.google.com/");
92 EXPECT_EQ("http://www.google.com/", action
->page_url().spec());
93 EXPECT_TRUE(action
->page_incognito());
96 } // namespace extensions