| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "chrome/browser/extensions/activity_log/activity_log.h" | 9 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 10 #include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h" | 10 #include "chrome/browser/extensions/activity_log/stream_noargs_ui_policy.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 static void RetrieveActions_LogAndFetchActions( | 61 static void RetrieveActions_LogAndFetchActions( |
| 62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 63 ASSERT_EQ(2, static_cast<int>(i->size())); | 63 ASSERT_EQ(2, static_cast<int>(i->size())); |
| 64 } | 64 } |
| 65 | 65 |
| 66 static void Arguments_Missing( | 66 static void Arguments_Missing( |
| 67 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 67 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 68 scoped_refptr<Action> last = i->front(); | 68 scoped_refptr<Action> last = i->front(); |
| 69 std::string noargs = | 69 std::string noargs = |
| 70 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " | 70 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " |
| 71 "API=tabs.testMethod ARGS=[] OTHER={}"; | 71 "API=tabs.testMethod"; |
| 72 ASSERT_EQ(noargs, last->PrintForDebug()); | 72 ASSERT_EQ(noargs, last->PrintForDebug()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 protected: | 75 protected: |
| 76 ExtensionService* extension_service_; | 76 ExtensionService* extension_service_; |
| 77 scoped_ptr<TestingProfile> profile_; | 77 scoped_ptr<TestingProfile> profile_; |
| 78 content::TestBrowserThreadBundle thread_bundle_; | 78 content::TestBrowserThreadBundle thread_bundle_; |
| 79 // Used to preserve a copy of the original command line. | 79 // Used to preserve a copy of the original command line. |
| 80 // The test framework will do this itself as well. However, by then, | 80 // The test framework will do this itself as well. However, by then, |
| 81 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | 81 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); | 93 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); |
| 94 scoped_refptr<const Extension> extension = | 94 scoped_refptr<const Extension> extension = |
| 95 ExtensionBuilder() | 95 ExtensionBuilder() |
| 96 .SetManifest(DictionaryBuilder() | 96 .SetManifest(DictionaryBuilder() |
| 97 .Set("name", "Test extension") | 97 .Set("name", "Test extension") |
| 98 .Set("version", "1.0.0") | 98 .Set("version", "1.0.0") |
| 99 .Set("manifest_version", 2)) | 99 .Set("manifest_version", 2)) |
| 100 .Build(); | 100 .Build(); |
| 101 extension_service_->AddExtension(extension.get()); | 101 extension_service_->AddExtension(extension.get()); |
| 102 scoped_ptr<base::ListValue> args(new base::ListValue()); | 102 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 103 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), | 103 scoped_refptr<Action> action = new Action(extension->id(), |
| 104 std::string("tabs.testMethod"), GURL(), args.get(), NULL); | 104 base::Time::Now(), |
| 105 Action::ACTION_API_CALL, |
| 106 "tabs.testMethod"); |
| 107 action->set_args(args.Pass()); |
| 108 policy->ProcessAction(action); |
| 105 policy->Close(); | 109 policy->Close(); |
| 106 } | 110 } |
| 107 | 111 |
| 108 TEST_F(StreamWithoutArgsUIPolicyTest, LogAndFetchActions) { | 112 TEST_F(StreamWithoutArgsUIPolicyTest, LogAndFetchActions) { |
| 109 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); | 113 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); |
| 110 scoped_refptr<const Extension> extension = | 114 scoped_refptr<const Extension> extension = |
| 111 ExtensionBuilder() | 115 ExtensionBuilder() |
| 112 .SetManifest(DictionaryBuilder() | 116 .SetManifest(DictionaryBuilder() |
| 113 .Set("name", "Test extension") | 117 .Set("name", "Test extension") |
| 114 .Set("version", "1.0.0") | 118 .Set("version", "1.0.0") |
| 115 .Set("manifest_version", 2)) | 119 .Set("manifest_version", 2)) |
| 116 .Build(); | 120 .Build(); |
| 117 extension_service_->AddExtension(extension.get()); | 121 extension_service_->AddExtension(extension.get()); |
| 118 scoped_ptr<base::ListValue> args(new base::ListValue()); | |
| 119 GURL gurl("http://www.google.com"); | 122 GURL gurl("http://www.google.com"); |
| 120 | 123 |
| 121 // Write some API calls | 124 // Write some API calls |
| 122 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), | 125 scoped_refptr<Action> action_api = new Action(extension->id(), |
| 123 std::string("tabs.testMethod"), GURL(), args.get(), NULL); | 126 base::Time::Now(), |
| 124 policy->ProcessAction(ActivityLogPolicy::ACTION_DOM, | 127 Action::ACTION_API_CALL, |
| 125 extension->id(), std::string("document.write"), | 128 "tabs.testMethod"); |
| 126 gurl, args.get(), NULL); | 129 action_api->set_args(make_scoped_ptr(new base::ListValue())); |
| 130 policy->ProcessAction(action_api); |
| 131 |
| 132 scoped_refptr<Action> action_dom = new Action(extension->id(), |
| 133 base::Time::Now(), |
| 134 Action::ACTION_DOM_ACCESS, |
| 135 "document.write"); |
| 136 action_dom->set_args(make_scoped_ptr(new base::ListValue())); |
| 137 action_dom->set_page_url(gurl); |
| 138 policy->ProcessAction(action_dom); |
| 139 |
| 127 policy->ReadData(extension->id(), 0, | 140 policy->ReadData(extension->id(), 0, |
| 128 base::Bind( | 141 base::Bind( |
| 129 StreamWithoutArgsUIPolicyTest::RetrieveActions_LogAndFetchActions)); | 142 StreamWithoutArgsUIPolicyTest::RetrieveActions_LogAndFetchActions)); |
| 130 | 143 |
| 131 policy->Close(); | 144 policy->Close(); |
| 132 } | 145 } |
| 133 | 146 |
| 134 TEST_F(StreamWithoutArgsUIPolicyTest, LogWithoutArguments) { | 147 TEST_F(StreamWithoutArgsUIPolicyTest, LogWithoutArguments) { |
| 135 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); | 148 ActivityLogPolicy* policy = new StreamWithoutArgsUIPolicy(profile_.get()); |
| 136 scoped_refptr<const Extension> extension = | 149 scoped_refptr<const Extension> extension = |
| 137 ExtensionBuilder() | 150 ExtensionBuilder() |
| 138 .SetManifest(DictionaryBuilder() | 151 .SetManifest(DictionaryBuilder() |
| 139 .Set("name", "Test extension") | 152 .Set("name", "Test extension") |
| 140 .Set("version", "1.0.0") | 153 .Set("version", "1.0.0") |
| 141 .Set("manifest_version", 2)) | 154 .Set("manifest_version", 2)) |
| 142 .Build(); | 155 .Build(); |
| 143 extension_service_->AddExtension(extension.get()); | 156 extension_service_->AddExtension(extension.get()); |
| 157 |
| 144 scoped_ptr<base::ListValue> args(new base::ListValue()); | 158 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 145 args->Set(0, new base::StringValue("hello")); | 159 args->Set(0, new base::StringValue("hello")); |
| 146 args->Set(1, new base::StringValue("world")); | 160 args->Set(1, new base::StringValue("world")); |
| 147 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), | 161 scoped_refptr<Action> action = new Action(extension->id(), |
| 148 std::string("tabs.testMethod"), GURL(), args.get(), NULL); | 162 base::Time::Now(), |
| 163 Action::ACTION_API_CALL, |
| 164 "tabs.testMethod"); |
| 165 action->set_args(args.Pass()); |
| 166 |
| 167 policy->ProcessAction(action); |
| 149 policy->ReadData(extension->id(), 0, | 168 policy->ReadData(extension->id(), 0, |
| 150 base::Bind(StreamWithoutArgsUIPolicyTest::Arguments_Missing)); | 169 base::Bind(StreamWithoutArgsUIPolicyTest::Arguments_Missing)); |
| 151 policy->Close(); | 170 policy->Close(); |
| 152 } | 171 } |
| 153 | 172 |
| 154 } // namespace extensions | 173 } // namespace extensions |
| OLD | NEW |