| 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/fullstream_ui_policy.h" | 10 #include "chrome/browser/extensions/activity_log/fullstream_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_Present( | 66 static void Arguments_Present( |
| 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 args = | 69 std::string args = |
| 70 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " | 70 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " |
| 71 "API=extension.connect ARGS=[\"hello\",\"world\"] OTHER={}"; | 71 "API=extension.connect ARGS=[\"hello\",\"world\"]"; |
| 72 ASSERT_EQ(args, last->PrintForDebug()); | 72 ASSERT_EQ(args, 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 FullStreamUIPolicy(profile_.get()); | 93 ActivityLogPolicy* policy = new FullStreamUIPolicy(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 = |
| 104 std::string("tabs.testMethod"), GURL(), args.get(), NULL); | 104 new Action(extension->id(), base::Time::Now(), Action::ACTION_API_CALL); |
| 105 action->set_api_name("tabs.testMethod"); |
| 106 action->set_args(args.Pass()); |
| 107 policy->ProcessAction(action); |
| 105 policy->Close(); | 108 policy->Close(); |
| 106 } | 109 } |
| 107 | 110 |
| 108 TEST_F(FullStreamUIPolicyTest, LogAndFetchActions) { | 111 TEST_F(FullStreamUIPolicyTest, LogAndFetchActions) { |
| 109 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); | 112 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); |
| 110 scoped_refptr<const Extension> extension = | 113 scoped_refptr<const Extension> extension = |
| 111 ExtensionBuilder() | 114 ExtensionBuilder() |
| 112 .SetManifest(DictionaryBuilder() | 115 .SetManifest(DictionaryBuilder() |
| 113 .Set("name", "Test extension") | 116 .Set("name", "Test extension") |
| 114 .Set("version", "1.0.0") | 117 .Set("version", "1.0.0") |
| 115 .Set("manifest_version", 2)) | 118 .Set("manifest_version", 2)) |
| 116 .Build(); | 119 .Build(); |
| 117 extension_service_->AddExtension(extension.get()); | 120 extension_service_->AddExtension(extension.get()); |
| 118 scoped_ptr<base::ListValue> args(new base::ListValue()); | |
| 119 GURL gurl("http://www.google.com"); | 121 GURL gurl("http://www.google.com"); |
| 120 | 122 |
| 121 // Write some API calls | 123 // Write some API calls |
| 122 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), | 124 scoped_refptr<Action> action_api = |
| 123 std::string("tabs.testMethod"), GURL(), args.get(), NULL); | 125 new Action(extension->id(), base::Time::Now(), Action::ACTION_API_CALL); |
| 124 policy->ProcessAction(ActivityLogPolicy::ACTION_DOM, | 126 action_api->set_api_name("tabs.testMethod"); |
| 125 extension->id(), std::string("document.write"), | 127 action_api->set_args(make_scoped_ptr(new base::ListValue())); |
| 126 gurl, args.get(), NULL); | 128 policy->ProcessAction(action_api); |
| 129 |
| 130 scoped_refptr<Action> action_dom = |
| 131 new Action(extension->id(), base::Time::Now(), Action::ACTION_DOM_ACCESS); |
| 132 action_dom->set_api_name("document.write"); |
| 133 action_dom->set_args(make_scoped_ptr(new base::ListValue())); |
| 134 action_dom->set_page_url(gurl); |
| 135 policy->ProcessAction(action_dom); |
| 136 |
| 127 policy->ReadData(extension->id(), 0, | 137 policy->ReadData(extension->id(), 0, |
| 128 base::Bind(FullStreamUIPolicyTest::RetrieveActions_LogAndFetchActions)); | 138 base::Bind(FullStreamUIPolicyTest::RetrieveActions_LogAndFetchActions)); |
| 129 | 139 |
| 130 policy->Close(); | 140 policy->Close(); |
| 131 } | 141 } |
| 132 | 142 |
| 133 TEST_F(FullStreamUIPolicyTest, LogWithArguments) { | 143 TEST_F(FullStreamUIPolicyTest, LogWithArguments) { |
| 134 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); | 144 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); |
| 135 scoped_refptr<const Extension> extension = | 145 scoped_refptr<const Extension> extension = |
| 136 ExtensionBuilder() | 146 ExtensionBuilder() |
| 137 .SetManifest(DictionaryBuilder() | 147 .SetManifest(DictionaryBuilder() |
| 138 .Set("name", "Test extension") | 148 .Set("name", "Test extension") |
| 139 .Set("version", "1.0.0") | 149 .Set("version", "1.0.0") |
| 140 .Set("manifest_version", 2)) | 150 .Set("manifest_version", 2)) |
| 141 .Build(); | 151 .Build(); |
| 142 extension_service_->AddExtension(extension.get()); | 152 extension_service_->AddExtension(extension.get()); |
| 153 |
| 143 scoped_ptr<base::ListValue> args(new base::ListValue()); | 154 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 144 args->Set(0, new base::StringValue("hello")); | 155 args->Set(0, new base::StringValue("hello")); |
| 145 args->Set(1, new base::StringValue("world")); | 156 args->Set(1, new base::StringValue("world")); |
| 146 policy->ProcessAction(ActivityLogPolicy::ACTION_API, extension->id(), | 157 scoped_refptr<Action> action = |
| 147 std::string("extension.connect"), GURL(), args.get(), NULL); | 158 new Action(extension->id(), base::Time::Now(), Action::ACTION_API_CALL); |
| 159 action->set_api_name("extension.connect"); |
| 160 action->set_args(args.Pass()); |
| 161 |
| 162 policy->ProcessAction(action); |
| 148 policy->ReadData(extension->id(), 0, | 163 policy->ReadData(extension->id(), 0, |
| 149 base::Bind(FullStreamUIPolicyTest::Arguments_Present)); | 164 base::Bind(FullStreamUIPolicyTest::Arguments_Present)); |
| 150 policy->Close(); | 165 policy->Close(); |
| 151 } | 166 } |
| 152 | 167 |
| 153 } // namespace extensions | 168 } // namespace extensions |
| OLD | NEW |