Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / activity_log / ad_injection_unittest.cc
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.
4
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"
11
12 namespace extensions {
13
14 namespace {
15
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;
30 }
31
32 }  // namespace
33
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());
39
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());
44
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());
49
50   scoped_refptr<Action> harmless_action =
51       CreateAction("Location.replace", "", "");
52   harmless_action->DidInjectAd(&rappor_service);
53   EXPECT_EQ(0, rappor_service.GetReportsCount());
54 }
55
56 }  // namespace extensions