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

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

Issue 23545012: [Activity log] Rework extraction of URLs from argument lists (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixes Created 7 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "chrome/browser/extensions/activity_log/activity_log.h" 10 #include "chrome/browser/extensions/activity_log/activity_log.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 90 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
91 ASSERT_EQ(1U, i->size()); 91 ASSERT_EQ(1U, i->size());
92 scoped_refptr<Action> last = i->front(); 92 scoped_refptr<Action> last = i->front();
93 std::string args = 93 std::string args =
94 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=content_script API= " 94 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=content_script API= "
95 "ARGS=[\"script\"] PAGE_URL=http://www.google.com/ " 95 "ARGS=[\"script\"] PAGE_URL=http://www.google.com/ "
96 "OTHER={\"prerender\":true}"; 96 "OTHER={\"prerender\":true}";
97 ASSERT_EQ(args, last->PrintForDebug()); 97 ASSERT_EQ(args, last->PrintForDebug());
98 } 98 }
99 99
100 static void RetrieveActions_ArgUrlExtraction(
101 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
102 ASSERT_EQ(2U, i->size());
103 scoped_refptr<Action> action = i->at(0);
104 ASSERT_EQ("[\"GET\",\"\\u003Carg_url\\u003E\"]",
105 ActivityLogPolicy::Util::Serialize(action->args()));
106 ASSERT_EQ("http://www.google.com/", action->arg_url().spec());
107
108 action = i->at(1);
109 ASSERT_EQ("[{\"url\":\"\\u003Carg_url\\u003E\"}]",
110 ActivityLogPolicy::Util::Serialize(action->args()));
111 ASSERT_EQ("http://www.google.co.uk/", action->arg_url().spec());
112 }
113
100 ExtensionService* extension_service_; 114 ExtensionService* extension_service_;
101 115
102 #if defined OS_CHROMEOS 116 #if defined OS_CHROMEOS
103 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 117 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
104 chromeos::ScopedTestCrosSettings test_cros_settings_; 118 chromeos::ScopedTestCrosSettings test_cros_settings_;
105 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; 119 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
106 #endif 120 #endif
107 }; 121 };
108 122
109 TEST_F(ActivityLogTest, Construct) { 123 TEST_F(ActivityLogTest, Construct) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 184
171 static_cast<TabHelper::ScriptExecutionObserver*>(activity_log)-> 185 static_cast<TabHelper::ScriptExecutionObserver*>(activity_log)->
172 OnScriptsExecuted(contents, executing_scripts, 0, url); 186 OnScriptsExecuted(contents, executing_scripts, 0, url);
173 187
174 activity_log->GetActions( 188 activity_log->GetActions(
175 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender)); 189 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender));
176 190
177 prerender_manager->CancelAllPrerenders(); 191 prerender_manager->CancelAllPrerenders();
178 } 192 }
179 193
194 TEST_F(ActivityLogTest, ArgUrlExtraction) {
195 ActivityLog* activity_log = ActivityLog::GetInstance(profile());
196 scoped_ptr<base::ListValue> args(new base::ListValue());
197
198 base::Time now = base::Time::Now();
199
200 // Submit a DOM API call which should have its URL extracted into the arg_url
201 // field.
202 scoped_refptr<Action> action = new Action(kExtensionId,
203 now,
204 Action::ACTION_DOM_ACCESS,
205 "XMLHttpRequest.open");
206 action->mutable_args()->AppendString("GET");
207 action->mutable_args()->AppendString("http://www.google.com/");
208 activity_log->LogAction(action);
209
210 // Submit an API call with an embedded URL.
211 action = new Action(kExtensionId,
212 now - base::TimeDelta::FromSeconds(1),
213 Action::ACTION_API_CALL,
214 "windows.create");
215 action->set_args(
216 ListBuilder()
217 .Append(DictionaryBuilder().Set("url", "http://www.google.co.uk"))
218 .Build());
219 activity_log->LogAction(action);
220
221 activity_log->GetActions(
222 kExtensionId,
223 0,
224 base::Bind(ActivityLogTest::RetrieveActions_ArgUrlExtraction));
225 }
226
180 } // namespace extensions 227 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698