Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: chrome/browser/extensions/activity_log/ad_injection_unittest.cc

Issue 384983003: Enabling AdInjectionBrowserTest after Activity Log refactoring. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments & unit tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/time/time.h" 5 #include "base/time/time.h"
6 #include "chrome/browser/extensions/activity_log/activity_actions.h" 6 #include "chrome/browser/extensions/activity_log/activity_actions.h"
7 #include "components/rappor/byte_vector_utils.h" 7 #include "components/rappor/byte_vector_utils.h"
8 #include "components/rappor/proto/rappor_metric.pb.h" 8 #include "components/rappor/proto/rappor_metric.pb.h"
9 #include "components/rappor/rappor_service.h" 9 #include "components/rappor/rappor_service.h"
10 #include "extensions/common/value_builder.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace extensions { 13 namespace extensions {
13 14
14 namespace { 15 namespace {
15 16
16 scoped_refptr<Action> CreateAction(const std::string& api_name) { 17 scoped_refptr<Action> CreateAction(const std::string& api_name,
18 const std::string& element,
19 const std::string& attr) {
17 scoped_refptr<Action> action = new Action("id", 20 scoped_refptr<Action> action = new Action("id",
18 base::Time::Now(), 21 base::Time::Now(),
19 Action::ACTION_DOM_ACCESS, 22 Action::ACTION_DOM_ACCESS,
20 api_name); 23 api_name);
21 action->set_arg_url(GURL("http://www.notarealhost.notarealtld")); 24 action->set_args(ListBuilder()
25 .Append(element)
26 .Append(attr)
27 .Append("http://www.google.co.uk")
28 .Append("http://www.google.co.uk")
29 .Build());
22 return action; 30 return action;
23 } 31 }
24 32
25 } // namespace 33 } // namespace
26 34
27 class TestRapporService : public rappor::RapporService { 35 class TestRapporService : public rappor::RapporService {
28 public: 36 public:
29 TestRapporService(); 37 TestRapporService();
30 virtual ~TestRapporService(); 38 virtual ~TestRapporService();
31 39
(...skipping 19 matching lines...) Expand all
51 } 59 }
52 60
53 // Test that the actions properly upload the URLs to the RAPPOR service if 61 // Test that the actions properly upload the URLs to the RAPPOR service if
54 // the action may have injected the ad. 62 // the action may have injected the ad.
55 TEST(AdInjectionUnittest, CheckActionForAdInjectionTest) { 63 TEST(AdInjectionUnittest, CheckActionForAdInjectionTest) {
56 TestRapporService rappor_service; 64 TestRapporService rappor_service;
57 rappor::RapporReports reports = rappor_service.GetReports(); 65 rappor::RapporReports reports = rappor_service.GetReports();
58 EXPECT_EQ(0, reports.report_size()); 66 EXPECT_EQ(0, reports.report_size());
59 67
60 scoped_refptr<Action> modify_iframe_src = 68 scoped_refptr<Action> modify_iframe_src =
61 CreateAction("HTMLIFrameElement.src"); 69 CreateAction("blinkSetAttribute", "iframe", "src");
62 modify_iframe_src->DidInjectAd(&rappor_service); 70 modify_iframe_src->DidInjectAd(&rappor_service);
63 reports = rappor_service.GetReports(); 71 reports = rappor_service.GetReports();
64 EXPECT_EQ(1, reports.report_size()); 72 EXPECT_EQ(1, reports.report_size());
65 73
66 scoped_refptr<Action> modify_embed_src =
67 CreateAction("HTMLEmbedElement.src");
68 modify_embed_src->DidInjectAd(&rappor_service);
69 reports = rappor_service.GetReports();
70 EXPECT_EQ(1, reports.report_size());
71
72 scoped_refptr<Action> modify_anchor_href = 74 scoped_refptr<Action> modify_anchor_href =
73 CreateAction("HTMLAnchorElement.href"); 75 CreateAction("blinkSetAttribute", "a", "href");
74 modify_anchor_href->DidInjectAd(&rappor_service); 76 modify_anchor_href->DidInjectAd(&rappor_service);
75 reports = rappor_service.GetReports(); 77 reports = rappor_service.GetReports();
76 EXPECT_EQ(1, reports.report_size()); 78 EXPECT_EQ(1, reports.report_size());
77 79
78 scoped_refptr<Action> harmless_action = CreateAction("Location.replace"); 80 scoped_refptr<Action> harmless_action =
81 CreateAction("Location.replace", "", "");
79 harmless_action->DidInjectAd(&rappor_service); 82 harmless_action->DidInjectAd(&rappor_service);
80 reports = rappor_service.GetReports(); 83 reports = rappor_service.GetReports();
81 EXPECT_EQ(0, reports.report_size()); 84 EXPECT_EQ(0, reports.report_size());
82 } 85 }
83 86
84 } // namespace extensions 87 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698