OLD | NEW |
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 ASSERT_EQ("[\"script\"]", | 96 ASSERT_EQ("[\"script\"]", |
97 ActivityLogPolicy::Util::Serialize(last->args())); | 97 ActivityLogPolicy::Util::Serialize(last->args())); |
98 ASSERT_EQ("http://www.google.com/", last->SerializePageUrl()); | 98 ASSERT_EQ("http://www.google.com/", last->SerializePageUrl()); |
99 ASSERT_EQ("{\"prerender\":true}", | 99 ASSERT_EQ("{\"prerender\":true}", |
100 ActivityLogPolicy::Util::Serialize(last->other())); | 100 ActivityLogPolicy::Util::Serialize(last->other())); |
101 ASSERT_EQ("", last->api_name()); | 101 ASSERT_EQ("", last->api_name()); |
102 ASSERT_EQ("", last->page_title()); | 102 ASSERT_EQ("", last->page_title()); |
103 ASSERT_EQ("", last->SerializeArgUrl()); | 103 ASSERT_EQ("", last->SerializeArgUrl()); |
104 } | 104 } |
105 | 105 |
| 106 static void RetrieveActions_ArgUrlExtraction( |
| 107 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 108 ASSERT_EQ(2U, i->size()); |
| 109 scoped_refptr<Action> action = i->at(0); |
| 110 ASSERT_EQ("[\"GET\",\"\\u003Carg_url\\u003E\"]", |
| 111 ActivityLogPolicy::Util::Serialize(action->args())); |
| 112 ASSERT_EQ("http://www.google.com/", action->arg_url().spec()); |
| 113 |
| 114 action = i->at(1); |
| 115 ASSERT_EQ("[{\"url\":\"\\u003Carg_url\\u003E\"}]", |
| 116 ActivityLogPolicy::Util::Serialize(action->args())); |
| 117 ASSERT_EQ("http://www.google.co.uk/", action->arg_url().spec()); |
| 118 } |
| 119 |
106 ExtensionService* extension_service_; | 120 ExtensionService* extension_service_; |
107 | 121 |
108 #if defined OS_CHROMEOS | 122 #if defined OS_CHROMEOS |
109 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 123 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
110 chromeos::ScopedTestCrosSettings test_cros_settings_; | 124 chromeos::ScopedTestCrosSettings test_cros_settings_; |
111 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 125 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
112 #endif | 126 #endif |
113 }; | 127 }; |
114 | 128 |
115 TEST_F(ActivityLogTest, Construct) { | 129 TEST_F(ActivityLogTest, Construct) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 Action::ACTION_ANY, | 200 Action::ACTION_ANY, |
187 "", | 201 "", |
188 "", | 202 "", |
189 "", | 203 "", |
190 0, | 204 0, |
191 base::Bind(ActivityLogTest::Arguments_Prerender)); | 205 base::Bind(ActivityLogTest::Arguments_Prerender)); |
192 | 206 |
193 prerender_manager->CancelAllPrerenders(); | 207 prerender_manager->CancelAllPrerenders(); |
194 } | 208 } |
195 | 209 |
| 210 TEST_F(ActivityLogTest, ArgUrlExtraction) { |
| 211 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 212 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 213 |
| 214 base::Time now = base::Time::Now(); |
| 215 |
| 216 // Submit a DOM API call which should have its URL extracted into the arg_url |
| 217 // field. |
| 218 scoped_refptr<Action> action = new Action(kExtensionId, |
| 219 now, |
| 220 Action::ACTION_DOM_ACCESS, |
| 221 "XMLHttpRequest.open"); |
| 222 action->mutable_args()->AppendString("GET"); |
| 223 action->mutable_args()->AppendString("http://www.google.com/"); |
| 224 activity_log->LogAction(action); |
| 225 |
| 226 // Submit an API call with an embedded URL. |
| 227 action = new Action(kExtensionId, |
| 228 now - base::TimeDelta::FromSeconds(1), |
| 229 Action::ACTION_API_CALL, |
| 230 "windows.create"); |
| 231 action->set_args( |
| 232 ListBuilder() |
| 233 .Append(DictionaryBuilder().Set("url", "http://www.google.co.uk")) |
| 234 .Build()); |
| 235 activity_log->LogAction(action); |
| 236 |
| 237 activity_log->GetFilteredActions( |
| 238 kExtensionId, |
| 239 Action::ACTION_ANY, |
| 240 "", |
| 241 "", |
| 242 "", |
| 243 0, |
| 244 base::Bind(ActivityLogTest::RetrieveActions_ArgUrlExtraction)); |
| 245 } |
| 246 |
196 } // namespace extensions | 247 } // namespace extensions |
OLD | NEW |