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

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

Issue 19690003: Extension activity log database refactoring (step 3) (Closed) Base URL: http://git.chromium.org/chromium/src.git@refactor2
Patch Set: Rebase Created 7 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 2013 The Chromium Authors. All rights reserved. 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 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "chrome/browser/extensions/activity_log/activity_log.h" 9 #include "chrome/browser/extensions/activity_log/activity_log.h"
10 #include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h" 10 #include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 static void RetrieveActions_LogAndFetchActions( 61 static void RetrieveActions_LogAndFetchActions(
62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
63 ASSERT_EQ(2, static_cast<int>(i->size())); 63 ASSERT_EQ(2, static_cast<int>(i->size()));
64 } 64 }
65 65
66 static void Arguments_Missing( 66 static void Arguments_Missing(
67 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 67 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
68 scoped_refptr<Action> last = i->front(); 68 scoped_refptr<Action> last = i->front();
69 std::string noargs = 69 std::string noargs =
70 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " 70 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call "
71 "API=tabs.testMethod ARGS=[] OTHER={}"; 71 "API=tabs.testMethod";
72 ASSERT_EQ(noargs, last->PrintForDebug()); 72 ASSERT_EQ(noargs, last->PrintForDebug());
73 } 73 }
74 74
75 protected: 75 protected:
76 ExtensionService* extension_service_; 76 ExtensionService* extension_service_;
77 scoped_ptr<TestingProfile> profile_; 77 scoped_ptr<TestingProfile> profile_;
78 content::TestBrowserThreadBundle thread_bundle_; 78 content::TestBrowserThreadBundle thread_bundle_;
79 // Used to preserve a copy of the original command line. 79 // Used to preserve a copy of the original command line.
80 // The test framework will do this itself as well. However, by then, 80 // The test framework will do this itself as well. However, by then,
81 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in 81 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in
(...skipping 11 matching lines...) Expand all
93 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); 93 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get());
94 scoped_refptr<const Extension> extension = 94 scoped_refptr<const Extension> extension =
95 ExtensionBuilder() 95 ExtensionBuilder()
96 .SetManifest(DictionaryBuilder() 96 .SetManifest(DictionaryBuilder()
97 .Set("name", "Test extension") 97 .Set("name", "Test extension")
98 .Set("version", "1.0.0") 98 .Set("version", "1.0.0")
99 .Set("manifest_version", 2)) 99 .Set("manifest_version", 2))
100 .Build(); 100 .Build();
101 extension_service_->AddExtension(extension.get()); 101 extension_service_->AddExtension(extension.get());
102 scoped_ptr<base::ListValue> args(new base::ListValue()); 102 scoped_ptr<base::ListValue> args(new base::ListValue());
103 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), 103 scoped_refptr<Action> action =
104 std::string("tabs.testMethod"), GURL(), args.get(), NULL); 104 new Action(extension->id(), base::Time::Now(), Action::ACTION_API_CALL);
105 action->set_api_name("tabs.testMethod");
106 action->set_args(args.Pass());
107 policy->ProcessAction(action);
105 policy->Close(); 108 policy->Close();
106 } 109 }
107 110
108 TEST_F(StreamWithoutArgsUIPolicyTest, LogAndFetchActions) { 111 TEST_F(StreamWithoutArgsUIPolicyTest, LogAndFetchActions) {
109 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); 112 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get());
110 scoped_refptr<const Extension> extension = 113 scoped_refptr<const Extension> extension =
111 ExtensionBuilder() 114 ExtensionBuilder()
112 .SetManifest(DictionaryBuilder() 115 .SetManifest(DictionaryBuilder()
113 .Set("name", "Test extension") 116 .Set("name", "Test extension")
114 .Set("version", "1.0.0") 117 .Set("version", "1.0.0")
115 .Set("manifest_version", 2)) 118 .Set("manifest_version", 2))
116 .Build(); 119 .Build();
117 extension_service_->AddExtension(extension.get()); 120 extension_service_->AddExtension(extension.get());
118 scoped_ptr<base::ListValue> args(new base::ListValue());
119 GURL gurl("http://www.google.com"); 121 GURL gurl("http://www.google.com");
120 122
121 // Write some API calls 123 // Write some API calls
122 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), 124 scoped_refptr<Action> action_api =
123 std::string("tabs.testMethod"), GURL(), args.get(), NULL); 125 new Action(extension->id(), base::Time::Now(), Action::ACTION_API_CALL);
124 policy->ProcessAction(ActivityLogPolicy::ACTION_DOM, 126 action_api->set_api_name("tabs.testMethod");
125 extension->id(), std::string("document.write"), 127 action_api->set_args(make_scoped_ptr(new base::ListValue()));
126 gurl, args.get(), NULL); 128 policy->ProcessAction(action_api);
129
130 scoped_refptr<Action> action_dom =
131 new Action(extension->id(), base::Time::Now(), Action::ACTION_DOM_ACCESS);
132 action_dom->set_api_name("document.write");
133 action_dom->set_args(make_scoped_ptr(new base::ListValue()));
134 action_dom->set_page_url(gurl);
135 policy->ProcessAction(action_dom);
136
127 policy->ReadData(extension->id(), 0, 137 policy->ReadData(extension->id(), 0,
128 base::Bind( 138 base::Bind(
129 StreamWithoutArgsUIPolicyTest::RetrieveActions_LogAndFetchActions)); 139 StreamWithoutArgsUIPolicyTest::RetrieveActions_LogAndFetchActions));
130 140
131 policy->Close(); 141 policy->Close();
132 } 142 }
133 143
134 TEST_F(StreamWithoutArgsUIPolicyTest, LogWithoutArguments) { 144 TEST_F(StreamWithoutArgsUIPolicyTest, LogWithoutArguments) {
135 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); 145 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get());
136 scoped_refptr<const Extension> extension = 146 scoped_refptr<const Extension> extension =
137 ExtensionBuilder() 147 ExtensionBuilder()
138 .SetManifest(DictionaryBuilder() 148 .SetManifest(DictionaryBuilder()
139 .Set("name", "Test extension") 149 .Set("name", "Test extension")
140 .Set("version", "1.0.0") 150 .Set("version", "1.0.0")
141 .Set("manifest_version", 2)) 151 .Set("manifest_version", 2))
142 .Build(); 152 .Build();
143 extension_service_->AddExtension(extension.get()); 153 extension_service_->AddExtension(extension.get());
154
144 scoped_ptr<base::ListValue> args(new base::ListValue()); 155 scoped_ptr<base::ListValue> args(new base::ListValue());
145 args->Set(0, new base::StringValue("hello")); 156 args->Set(0, new base::StringValue("hello"));
146 args->Set(1, new base::StringValue("world")); 157 args->Set(1, new base::StringValue("world"));
147 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), 158 scoped_refptr<Action> action =
148 std::string("tabs.testMethod"), GURL(), args.get(), NULL); 159 new Action(extension->id(), base::Time::Now(), Action::ACTION_API_CALL);
160 action->set_api_name("tabs.testMethod");
161 action->set_args(args.Pass());
162
163 policy->ProcessAction(action);
149 policy->ReadData(extension->id(), 0, 164 policy->ReadData(extension->id(), 0,
150 base::Bind(StreamWithoutArgsUIPolicyTest::Arguments_Missing)); 165 base::Bind(StreamWithoutArgsUIPolicyTest::Arguments_Missing));
151 policy->Close(); 166 policy->Close();
152 } 167 }
153 168
154 } // namespace extensions 169 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698