1 // Copyright 2014 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/prefs/testing_pref_service.h"
6 #include "base/time/time.h"
7 #include "chrome/browser/extensions/activity_log/activity_actions.h"
8 #include "components/rappor/test_rappor_service.h"
9 #include "extensions/common/value_builder.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace extensions
{
16 scoped_refptr
<Action
> CreateAction(const std::string
& api_name
,
17 const std::string
& element
,
18 const std::string
& attr
) {
19 scoped_refptr
<Action
> action
= new Action("id",
21 Action::ACTION_DOM_ACCESS
,
23 action
->set_args(ListBuilder()
26 .Append("http://www.google.co.uk")
27 .Append("http://www.google.co.uk")
34 // Test that the actions properly upload the URLs to the RAPPOR service if
35 // the action may have injected the ad.
36 TEST(AdInjectionUnittest
, CheckActionForAdInjectionTest
) {
37 rappor::TestRapporService rappor_service
;
38 ASSERT_EQ(0, rappor_service
.GetReportsCount());
40 scoped_refptr
<Action
> modify_iframe_src
=
41 CreateAction("blinkSetAttribute", "iframe", "src");
42 modify_iframe_src
->DidInjectAd(&rappor_service
);
43 EXPECT_EQ(1, rappor_service
.GetReportsCount());
45 scoped_refptr
<Action
> modify_anchor_href
=
46 CreateAction("blinkSetAttribute", "a", "href");
47 modify_anchor_href
->DidInjectAd(&rappor_service
);
48 EXPECT_EQ(1, rappor_service
.GetReportsCount());
50 scoped_refptr
<Action
> harmless_action
=
51 CreateAction("Location.replace", "", "");
52 harmless_action
->DidInjectAd(&rappor_service
);
53 EXPECT_EQ(0, rappor_service
.GetReportsCount());
56 } // namespace extensions