| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 ASSERT_EQ(2, static_cast<int>(i->size())); | 77 ASSERT_EQ(2, static_cast<int>(i->size())); |
| 78 } | 78 } |
| 79 | 79 |
| 80 static void RetrieveActions_LogAndFetchPathActions( | 80 static void RetrieveActions_LogAndFetchPathActions( |
| 81 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 81 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 82 std::string args; | 82 std::string args; |
| 83 ASSERT_EQ(1U, i->size()); | 83 ASSERT_EQ(1U, i->size()); |
| 84 scoped_refptr<Action> last = i->front(); | 84 scoped_refptr<Action> last = i->front(); |
| 85 if (CommandLine::ForCurrentProcess()->HasSwitch( | 85 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 86 switches::kEnableExtensionActivityLogTesting)) | 86 switches::kEnableExtensionActivityLogTesting)) |
| 87 args = "Injected scripts () onto " | 87 args = |
| 88 "http://www.google.com/foo?bar extra"; | 88 "ID=abc CATEGORY=content_script API=document.write ARGS=[\"\"] " |
| 89 "PAGE_URL=http://www.google.com/foo?bar " |
| 90 "OTHER={\"dom_verb\":3,\"extra\":\"extra\",\"page_title\":\"\"}"; |
| 89 else | 91 else |
| 90 args = "Injected scripts () onto " | 92 args = |
| 91 "http://www.google.com/foo extra"; | 93 "ID=abc CATEGORY=content_script API=document.write ARGS=[\"\"] " |
| 94 "PAGE_URL=http://www.google.com/foo " |
| 95 "OTHER={\"dom_verb\":3,\"extra\":\"extra\",\"page_title\":\"\"}"; |
| 92 ASSERT_EQ(args, last->PrintForDebug()); | 96 ASSERT_EQ(args, last->PrintForDebug()); |
| 93 } | 97 } |
| 94 | 98 |
| 95 static void Arguments_Missing( | 99 static void Arguments_Missing( |
| 96 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 100 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 97 scoped_refptr<Action> last = i->front(); | 101 scoped_refptr<Action> last = i->front(); |
| 98 std::string id(kExtensionId); | 102 std::string id(kExtensionId); |
| 99 std::string noargs = "ID: " + id + ", CATEGORY: " | 103 std::string noargs = |
| 100 "call, API: tabs.testMethod, ARGS: "; | 104 "ID=" + id + " CATEGORY=api_call API=tabs.testMethod ARGS=[] OTHER={}"; |
| 101 ASSERT_EQ(noargs, last->PrintForDebug()); | 105 ASSERT_EQ(noargs, last->PrintForDebug()); |
| 102 } | 106 } |
| 103 | 107 |
| 104 static void Arguments_Present( | 108 static void Arguments_Present( |
| 105 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 109 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 106 scoped_refptr<Action> last = i->front(); | 110 scoped_refptr<Action> last = i->front(); |
| 107 std::string id(kExtensionId); | 111 std::string id(kExtensionId); |
| 108 std::string args = "ID: " + id + ", CATEGORY: " | 112 std::string args = "ID=" + id + |
| 109 "call, API: extension.connect, ARGS: \"hello\", \"world\""; | 113 " CATEGORY=api_call API=extension.connect " |
| 114 "ARGS=[\"hello\",\"world\"] OTHER={}"; |
| 110 ASSERT_EQ(args, last->PrintForDebug()); | 115 ASSERT_EQ(args, last->PrintForDebug()); |
| 111 } | 116 } |
| 112 | 117 |
| 113 void SetPolicy(bool log_arguments) { | 118 void SetPolicy(bool log_arguments) { |
| 114 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); | 119 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 115 if (log_arguments) | 120 if (log_arguments) |
| 116 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); | 121 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); |
| 117 else | 122 else |
| 118 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_NOARGS); | 123 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_NOARGS); |
| 119 } | 124 } |
| 120 | 125 |
| 121 static void Arguments_Prerender( | 126 static void Arguments_Prerender( |
| 122 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 127 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 123 ASSERT_EQ(1U, i->size()); | 128 ASSERT_EQ(1U, i->size()); |
| 124 scoped_refptr<Action> last = i->front(); | 129 scoped_refptr<Action> last = i->front(); |
| 125 std::string args = "Injected scripts (\"script \") " | 130 std::string args = |
| 126 "onto http://www.google.com/ (prerender)"; | 131 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=content_script API= " |
| 132 "ARGS=[\"\\\"script \\\"\"] PAGE_URL=http://www.google.com/ " |
| 133 "OTHER={\"dom_verb\":3,\"extra\":\"(prerender)\",\"page_title\":\"\"}"; |
| 127 ASSERT_EQ(args, last->PrintForDebug()); | 134 ASSERT_EQ(args, last->PrintForDebug()); |
| 128 } | 135 } |
| 129 | 136 |
| 130 ExtensionService* extension_service_; | 137 ExtensionService* extension_service_; |
| 131 // Used to preserve a copy of the original command line. | 138 // Used to preserve a copy of the original command line. |
| 132 // The test framework will do this itself as well. However, by then, | 139 // The test framework will do this itself as well. However, by then, |
| 133 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | 140 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in |
| 134 // TearDown(). | 141 // TearDown(). |
| 135 CommandLine saved_cmdline_; | 142 CommandLine saved_cmdline_; |
| 136 | 143 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 static_cast<TabHelper::ScriptExecutionObserver*>(activity_log)-> | 264 static_cast<TabHelper::ScriptExecutionObserver*>(activity_log)-> |
| 258 OnScriptsExecuted(contents, executing_scripts, 0, url); | 265 OnScriptsExecuted(contents, executing_scripts, 0, url); |
| 259 | 266 |
| 260 activity_log->GetActions( | 267 activity_log->GetActions( |
| 261 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender)); | 268 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Prerender)); |
| 262 | 269 |
| 263 prerender_manager->CancelAllPrerenders(); | 270 prerender_manager->CancelAllPrerenders(); |
| 264 } | 271 } |
| 265 | 272 |
| 266 } // namespace extensions | 273 } // namespace extensions |
| OLD | NEW |