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/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
8 #include "chrome/browser/extensions/activity_log.h" | 8 #include "chrome/browser/extensions/activity_log.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/test_extension_system.h" | 10 #include "chrome/browser/extensions/test_extension_system.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 virtual ~ActivityLogTest() { | 43 virtual ~ActivityLogTest() { |
44 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 44 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
45 MessageLoop::current()->Run(); | 45 MessageLoop::current()->Run(); |
46 } | 46 } |
47 | 47 |
48 static void RetrieveActions_LogAndFetchActions( | 48 static void RetrieveActions_LogAndFetchActions( |
49 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 49 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
50 ASSERT_EQ(2, static_cast<int>(i->size())); | 50 ASSERT_EQ(2, static_cast<int>(i->size())); |
51 } | 51 } |
52 | 52 |
| 53 static void Arguments_Missing( |
| 54 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 55 scoped_refptr<Action> last = i->front(); |
| 56 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " |
| 57 "CALL, VERB: UNKNOWN_VERB, TARGET: TABS, API: tabs.testMethod, ARGS: "; |
| 58 ASSERT_EQ(noargs, last->PrettyPrintForDebug()); |
| 59 } |
| 60 |
| 61 static void Arguments_Present( |
| 62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 63 scoped_refptr<Action> last = i->front(); |
| 64 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " |
| 65 "CALL, VERB: UNKNOWN_VERB, TARGET: UNKNOWN_TARGET, API: " |
| 66 "extension.connect, ARGS: \"hello\", \"world\""; |
| 67 ASSERT_EQ(args, last->PrettyPrintForDebug()); |
| 68 } |
| 69 |
53 protected: | 70 protected: |
54 ExtensionService* extension_service_; | 71 ExtensionService* extension_service_; |
55 Profile* profile_; | 72 Profile* profile_; |
56 | 73 |
57 private: | 74 private: |
58 content::TestBrowserThread ui_thread_; | 75 content::TestBrowserThread ui_thread_; |
59 content::TestBrowserThread db_thread_; | 76 content::TestBrowserThread db_thread_; |
60 content::TestBrowserThread file_thread_; | 77 content::TestBrowserThread file_thread_; |
61 }; | 78 }; |
62 | 79 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 string16(), | 122 string16(), |
106 std::string("document.write"), | 123 std::string("document.write"), |
107 args.get(), | 124 args.get(), |
108 std::string("extra")); | 125 std::string("extra")); |
109 activity_log->GetActions( | 126 activity_log->GetActions( |
110 extension->id(), | 127 extension->id(), |
111 0, | 128 0, |
112 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions)); | 129 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions)); |
113 } | 130 } |
114 | 131 |
| 132 TEST_F(ActivityLogTest, LogWithoutArguments) { |
| 133 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); |
| 134 scoped_refptr<const Extension> extension = |
| 135 ExtensionBuilder() |
| 136 .SetManifest(DictionaryBuilder() |
| 137 .Set("name", "Test extension") |
| 138 .Set("version", "1.0.0") |
| 139 .Set("manifest_version", 2)) |
| 140 .Build(); |
| 141 extension_service_->AddExtension(extension); |
| 142 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
| 143 |
| 144 scoped_ptr<ListValue> args(new ListValue()); |
| 145 args->Set(0, new base::StringValue("hello")); |
| 146 args->Set(1, new base::StringValue("world")); |
| 147 activity_log->LogAPIAction(extension, |
| 148 std::string("tabs.testMethod"), |
| 149 args.get(), |
| 150 ""); |
| 151 activity_log->GetActions( |
| 152 extension->id(), |
| 153 0, |
| 154 base::Bind(ActivityLogTest::Arguments_Missing)); |
| 155 } |
| 156 |
| 157 TEST_F(ActivityLogTest, LogWithArguments) { |
| 158 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); |
| 159 scoped_refptr<const Extension> extension = |
| 160 ExtensionBuilder() |
| 161 .SetManifest(DictionaryBuilder() |
| 162 .Set("name", "Test extension") |
| 163 .Set("version", "1.0.0") |
| 164 .Set("manifest_version", 2)) |
| 165 .Build(); |
| 166 extension_service_->AddExtension(extension); |
| 167 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
| 168 |
| 169 scoped_ptr<ListValue> args(new ListValue()); |
| 170 args->Set(0, new base::StringValue("hello")); |
| 171 args->Set(1, new base::StringValue("world")); |
| 172 activity_log->LogAPIAction(extension, |
| 173 std::string("extension.connect"), |
| 174 args.get(), |
| 175 ""); |
| 176 activity_log->GetActions( |
| 177 extension->id(), |
| 178 0, |
| 179 base::Bind(ActivityLogTest::Arguments_Present)); |
| 180 } |
| 181 |
115 } // namespace extensions | 182 } // namespace extensions |
116 | 183 |
OLD | NEW |