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