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_action_constants.h" | 10 #include "chrome/browser/extensions/activity_log/activity_action_constants.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
28 #include "chrome/browser/chromeos/login/user_manager.h" | 28 #include "chrome/browser/chromeos/login/user_manager.h" |
29 #include "chrome/browser/chromeos/settings/cros_settings.h" | 29 #include "chrome/browser/chromeos/settings/cros_settings.h" |
30 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 30 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
31 #endif | 31 #endif |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const char kExtensionId[] = "abc"; | 35 const char kExtensionId[] = "abc"; |
36 | 36 |
| 37 const char* kUrlApiCalls[] = { |
| 38 "HTMLButtonElement.formAction", "HTMLEmbedElement.src", |
| 39 "HTMLFormElement.action", "HTMLFrameElement.src", |
| 40 "HTMLHtmlElement.manifest", "HTMLIFrameElement.src", |
| 41 "HTMLImageElement.longDesc", "HTMLImageElement.src", |
| 42 "HTMLImageElement.lowsrc", "HTMLInputElement.formAction", |
| 43 "HTMLInputElement.src", "HTMLLinkElement.href", |
| 44 "HTMLMediaElement.src", "HTMLMediaElement.currentSrc", |
| 45 "HTMLModElement.cite", "HTMLObjectElement.data", |
| 46 "HTMLQuoteElement.cite", "HTMLScriptElement.src", |
| 47 "HTMLSourceElement.src", "HTMLTrackElement.src", |
| 48 "HTMLVideoElement.poster"}; |
| 49 |
37 } // namespace | 50 } // namespace |
38 | 51 |
39 namespace extensions { | 52 namespace extensions { |
40 | 53 |
41 class ActivityLogTest : public ChromeRenderViewHostTestHarness { | 54 class ActivityLogTest : public ChromeRenderViewHostTestHarness { |
42 protected: | 55 protected: |
43 virtual void SetUp() OVERRIDE { | 56 virtual void SetUp() OVERRIDE { |
44 ChromeRenderViewHostTestHarness::SetUp(); | 57 ChromeRenderViewHostTestHarness::SetUp(); |
45 #if defined OS_CHROMEOS | 58 #if defined OS_CHROMEOS |
46 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 59 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 ActivityLogPolicy::Util::Serialize(action->args())); | 154 ActivityLogPolicy::Util::Serialize(action->args())); |
142 ASSERT_FALSE(action->arg_url().is_valid()); | 155 ASSERT_FALSE(action->arg_url().is_valid()); |
143 | 156 |
144 action = i->at(3); | 157 action = i->at(3); |
145 ASSERT_EQ("windows.create", action->api_name()); | 158 ASSERT_EQ("windows.create", action->api_name()); |
146 ASSERT_EQ("[{\"url\":\"\\u003Carg_url>\"}]", | 159 ASSERT_EQ("[{\"url\":\"\\u003Carg_url>\"}]", |
147 ActivityLogPolicy::Util::Serialize(action->args())); | 160 ActivityLogPolicy::Util::Serialize(action->args())); |
148 ASSERT_EQ("http://www.google.co.uk/", action->arg_url().spec()); | 161 ASSERT_EQ("http://www.google.co.uk/", action->arg_url().spec()); |
149 } | 162 } |
150 | 163 |
| 164 static void RetrieveActions_ArgUrlApiCalls( |
| 165 scoped_ptr<std::vector<scoped_refptr<Action> > > actions) { |
| 166 size_t api_calls_size = arraysize(kUrlApiCalls); |
| 167 const base::DictionaryValue* other = NULL; |
| 168 int dom_verb = -1; |
| 169 |
| 170 ASSERT_EQ(api_calls_size, actions->size()); |
| 171 |
| 172 for (size_t i = 0; i < actions->size(); i++) { |
| 173 scoped_refptr<Action> action = actions->at(i); |
| 174 ASSERT_EQ(kExtensionId, action->extension_id()); |
| 175 ASSERT_EQ(Action::ACTION_DOM_ACCESS, action->action_type()); |
| 176 ASSERT_EQ(kUrlApiCalls[i], action->api_name()); |
| 177 ASSERT_EQ("[\"\\u003Carg_url>\"]", |
| 178 ActivityLogPolicy::Util::Serialize(action->args())); |
| 179 ASSERT_EQ("http://www.google.co.uk/", action->arg_url().spec()); |
| 180 other = action->other(); |
| 181 ASSERT_TRUE(other); |
| 182 ASSERT_TRUE( |
| 183 other->GetInteger(activity_log_constants::kActionDomVerb, &dom_verb)); |
| 184 ASSERT_EQ(DomActionType::SETTER, dom_verb); |
| 185 } |
| 186 } |
| 187 |
151 ExtensionService* extension_service_; | 188 ExtensionService* extension_service_; |
152 | 189 |
153 #if defined OS_CHROMEOS | 190 #if defined OS_CHROMEOS |
154 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 191 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
155 chromeos::ScopedTestCrosSettings test_cros_settings_; | 192 chromeos::ScopedTestCrosSettings test_cros_settings_; |
156 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 193 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
157 #endif | 194 #endif |
158 }; | 195 }; |
159 | 196 |
160 TEST_F(ActivityLogTest, Construct) { | 197 TEST_F(ActivityLogTest, Construct) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 activity_log->GetFilteredActions( | 370 activity_log->GetFilteredActions( |
334 extension->id(), | 371 extension->id(), |
335 Action::ACTION_ANY, | 372 Action::ACTION_ANY, |
336 "", | 373 "", |
337 "", | 374 "", |
338 "", | 375 "", |
339 -1, | 376 -1, |
340 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions0)); | 377 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions0)); |
341 } | 378 } |
342 | 379 |
| 380 TEST_F(ActivityLogTest, ArgUrlApiCalls) { |
| 381 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 382 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 383 base::Time now = base::Time::Now(); |
| 384 int api_calls_size = arraysize(kUrlApiCalls); |
| 385 scoped_refptr<Action> action; |
| 386 |
| 387 for (int i = 0; i < api_calls_size; i++) { |
| 388 action = new Action(kExtensionId, |
| 389 now - base::TimeDelta::FromSeconds(i), |
| 390 Action::ACTION_DOM_ACCESS, |
| 391 kUrlApiCalls[i]); |
| 392 action->mutable_args()->AppendString("http://www.google.co.uk"); |
| 393 action->mutable_other()->SetInteger(activity_log_constants::kActionDomVerb, |
| 394 DomActionType::SETTER); |
| 395 activity_log->LogAction(action); |
| 396 } |
| 397 |
| 398 activity_log->GetFilteredActions( |
| 399 kExtensionId, |
| 400 Action::ACTION_ANY, |
| 401 "", |
| 402 "", |
| 403 "", |
| 404 -1, |
| 405 base::Bind(ActivityLogTest::RetrieveActions_ArgUrlApiCalls)); |
| 406 } |
| 407 |
343 } // namespace extensions | 408 } // namespace extensions |
OLD | NEW |