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

Side by Side Diff: chrome/browser/extensions/activity_log/fullstream_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: Do not set bad BlockedChromeActivityDetail::Reason values Created 7 years, 4 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/fullstream_ui_policy.h" 10 #include "chrome/browser/extensions/activity_log/fullstream_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_Present( 66 static void Arguments_Present(
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 args = 69 std::string args =
70 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " 70 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call "
71 "API=extension.connect ARGS=[\"hello\",\"world\"] OTHER={}"; 71 "API=extension.connect ARGS=[\"hello\",\"world\"]";
72 ASSERT_EQ(args, last->PrintForDebug()); 72 ASSERT_EQ(args, 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 FullStreamUIPolicy(profile_.get()); 93 ActivityLogPolicy* policy = new FullStreamUIPolicy(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 = new Action(extension->id(),
104 std::string("tabs.testMethod"), GURL(), args.get(), NULL); 104 base::Time::Now(),
105 Action::ACTION_API_CALL,
106 "tabs.testMethod");
107 action->set_args(args.Pass());
108 policy->ProcessAction(action);
105 policy->Close(); 109 policy->Close();
106 } 110 }
107 111
108 TEST_F(FullStreamUIPolicyTest, LogAndFetchActions) { 112 TEST_F(FullStreamUIPolicyTest, LogAndFetchActions) {
109 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); 113 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get());
110 scoped_refptr<const Extension> extension = 114 scoped_refptr<const Extension> extension =
111 ExtensionBuilder() 115 ExtensionBuilder()
112 .SetManifest(DictionaryBuilder() 116 .SetManifest(DictionaryBuilder()
113 .Set("name", "Test extension") 117 .Set("name", "Test extension")
114 .Set("version", "1.0.0") 118 .Set("version", "1.0.0")
115 .Set("manifest_version", 2)) 119 .Set("manifest_version", 2))
116 .Build(); 120 .Build();
117 extension_service_->AddExtension(extension.get()); 121 extension_service_->AddExtension(extension.get());
118 scoped_ptr<base::ListValue> args(new base::ListValue());
119 GURL gurl("http://www.google.com"); 122 GURL gurl("http://www.google.com");
120 123
121 // Write some API calls 124 // Write some API calls
122 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), 125 scoped_refptr<Action> action_api = new Action(extension->id(),
123 std::string("tabs.testMethod"), GURL(), args.get(), NULL); 126 base::Time::Now(),
124 policy->ProcessAction(ActivityLogPolicy::ACTION_DOM, 127 Action::ACTION_API_CALL,
125 extension->id(), std::string("document.write"), 128 "tabs.testMethod");
126 gurl, args.get(), NULL); 129 action_api->set_args(make_scoped_ptr(new base::ListValue()));
130 policy->ProcessAction(action_api);
131
132 scoped_refptr<Action> action_dom = new Action(extension->id(),
133 base::Time::Now(),
134 Action::ACTION_DOM_ACCESS,
135 "document.write");
136 action_dom->set_args(make_scoped_ptr(new base::ListValue()));
137 action_dom->set_page_url(gurl);
138 policy->ProcessAction(action_dom);
139
127 policy->ReadData(extension->id(), 0, 140 policy->ReadData(extension->id(), 0,
128 base::Bind(FullStreamUIPolicyTest::RetrieveActions_LogAndFetchActions)); 141 base::Bind(FullStreamUIPolicyTest::RetrieveActions_LogAndFetchActions));
129 142
130 policy->Close(); 143 policy->Close();
131 } 144 }
132 145
133 TEST_F(FullStreamUIPolicyTest, LogWithArguments) { 146 TEST_F(FullStreamUIPolicyTest, LogWithArguments) {
134 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); 147 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get());
135 scoped_refptr<const Extension> extension = 148 scoped_refptr<const Extension> extension =
136 ExtensionBuilder() 149 ExtensionBuilder()
137 .SetManifest(DictionaryBuilder() 150 .SetManifest(DictionaryBuilder()
138 .Set("name", "Test extension") 151 .Set("name", "Test extension")
139 .Set("version", "1.0.0") 152 .Set("version", "1.0.0")
140 .Set("manifest_version", 2)) 153 .Set("manifest_version", 2))
141 .Build(); 154 .Build();
142 extension_service_->AddExtension(extension.get()); 155 extension_service_->AddExtension(extension.get());
156
143 scoped_ptr<base::ListValue> args(new base::ListValue()); 157 scoped_ptr<base::ListValue> args(new base::ListValue());
144 args->Set(0, new base::StringValue("hello")); 158 args->Set(0, new base::StringValue("hello"));
145 args->Set(1, new base::StringValue("world")); 159 args->Set(1, new base::StringValue("world"));
146 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), 160 scoped_refptr<Action> action = new Action(extension->id(),
147 std::string("extension.connect"), GURL(), args.get(), NULL); 161 base::Time::Now(),
162 Action::ACTION_API_CALL,
163 "extension.connect");
164 action->set_args(args.Pass());
165
166 policy->ProcessAction(action);
148 policy->ReadData(extension->id(), 0, 167 policy->ReadData(extension->id(), 0,
149 base::Bind(FullStreamUIPolicyTest::Arguments_Present)); 168 base::Bind(FullStreamUIPolicyTest::Arguments_Present));
150 policy->Close(); 169 policy->Close();
151 } 170 }
152 171
153 } // namespace extensions 172 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698