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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 190 |
177 static_cast<TabHelper::ScriptExecutionObserver*>(activity_log)-> | 191 static_cast<TabHelper::ScriptExecutionObserver*>(activity_log)-> |
178 OnScriptsExecuted(contents, executing_scripts, 0, url); | 192 OnScriptsExecuted(contents, executing_scripts, 0, url); |
179 | 193 |
180 activity_log->GetActions( | 194 activity_log->GetActions( |
181 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender)); | 195 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender)); |
182 | 196 |
183 prerender_manager->CancelAllPrerenders(); | 197 prerender_manager->CancelAllPrerenders(); |
184 } | 198 } |
185 | 199 |
| 200 TEST_F(ActivityLogTest, ArgUrlExtraction) { |
| 201 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 202 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 203 |
| 204 base::Time now = base::Time::Now(); |
| 205 |
| 206 // Submit a DOM API call which should have its URL extracted into the arg_url |
| 207 // field. |
| 208 scoped_refptr<Action> action = new Action(kExtensionId, |
| 209 now, |
| 210 Action::ACTION_DOM_ACCESS, |
| 211 "XMLHttpRequest.open"); |
| 212 action->mutable_args()->AppendString("GET"); |
| 213 action->mutable_args()->AppendString("http://www.google.com/"); |
| 214 activity_log->LogAction(action); |
| 215 |
| 216 // Submit an API call with an embedded URL. |
| 217 action = new Action(kExtensionId, |
| 218 now - base::TimeDelta::FromSeconds(1), |
| 219 Action::ACTION_API_CALL, |
| 220 "windows.create"); |
| 221 action->set_args( |
| 222 ListBuilder() |
| 223 .Append(DictionaryBuilder().Set("url", "http://www.google.co.uk")) |
| 224 .Build()); |
| 225 activity_log->LogAction(action); |
| 226 |
| 227 activity_log->GetActions( |
| 228 kExtensionId, |
| 229 0, |
| 230 base::Bind(ActivityLogTest::RetrieveActions_ArgUrlExtraction)); |
| 231 } |
| 232 |
186 } // namespace extensions | 233 } // namespace extensions |
OLD | NEW |