Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / activity_log / ad_injection_unittest.cc
blobcbd8c41f9be0d73aa16fd20b2182afee4a2841b9
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 {
14 namespace {
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",
20 base::Time::Now(),
21 Action::ACTION_DOM_ACCESS,
22 api_name);
23 action->set_args(ListBuilder()
24 .Append(element)
25 .Append(attr)
26 .Append("http://www.google.co.uk")
27 .Append("http://www.google.co.uk")
28 .Build());
29 return action;
32 } // namespace
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