| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/util/extensions_activity_monitor.h" | 5 #include "chrome/browser/sync/util/extensions_activity_monitor.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 BookmarkAPIEventGenerator() {} | 66 BookmarkAPIEventGenerator() {} |
| 67 virtual ~BookmarkAPIEventGenerator() {} | 67 virtual ~BookmarkAPIEventGenerator() {} |
| 68 template <class T> | 68 template <class T> |
| 69 void NewEvent(const FilePath::StringType& extension_path, | 69 void NewEvent(const FilePath::StringType& extension_path, |
| 70 T* bookmarks_function, size_t repeats) { | 70 T* bookmarks_function, size_t repeats) { |
| 71 std::string error; | 71 std::string error; |
| 72 DictionaryValue input; | 72 DictionaryValue input; |
| 73 input.SetString(keys::kVersion, kTestExtensionVersion); | 73 input.SetString(keys::kVersion, kTestExtensionVersion); |
| 74 input.SetString(keys::kName, kTestExtensionName); | 74 input.SetString(keys::kName, kTestExtensionName); |
| 75 scoped_refptr<Extension> extension(Extension::Create( | 75 scoped_refptr<Extension> extension(Extension::Create( |
| 76 FilePath(extension_path), Extension::INVALID, input, false, true, | 76 FilePath(extension_path), Extension::INVALID, input, |
| 77 &error)); | 77 Extension::STRICT_ERROR_CHECKS, &error)); |
| 78 bookmarks_function->set_name(T::function_name()); | 78 bookmarks_function->set_name(T::function_name()); |
| 79 base::WaitableEvent done_event(false, false); | 79 base::WaitableEvent done_event(false, false); |
| 80 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 80 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 81 new BookmarkAPIEventTask<T>(bookmarks_function, extension, | 81 new BookmarkAPIEventTask<T>(bookmarks_function, extension, |
| 82 repeats, &done_event)); | 82 repeats, &done_event)); |
| 83 done_event.Wait(); | 83 done_event.Wait(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 DISALLOW_COPY_AND_ASSIGN(BookmarkAPIEventGenerator); | 87 DISALLOW_COPY_AND_ASSIGN(BookmarkAPIEventGenerator); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 MessageLoop* ui_loop() { return ui_thread_.message_loop(); } | 126 MessageLoop* ui_loop() { return ui_thread_.message_loop(); } |
| 127 | 127 |
| 128 static std::string GetExtensionIdForPath( | 128 static std::string GetExtensionIdForPath( |
| 129 const FilePath::StringType& extension_path) { | 129 const FilePath::StringType& extension_path) { |
| 130 std::string error; | 130 std::string error; |
| 131 DictionaryValue input; | 131 DictionaryValue input; |
| 132 input.SetString(keys::kVersion, kTestExtensionVersion); | 132 input.SetString(keys::kVersion, kTestExtensionVersion); |
| 133 input.SetString(keys::kName, kTestExtensionName); | 133 input.SetString(keys::kName, kTestExtensionName); |
| 134 scoped_refptr<Extension> extension(Extension::Create( | 134 scoped_refptr<Extension> extension(Extension::Create( |
| 135 FilePath(extension_path), Extension::INVALID, input, false, true, | 135 FilePath(extension_path), Extension::INVALID, input, |
| 136 &error)); | 136 Extension::STRICT_ERROR_CHECKS, &error)); |
| 137 EXPECT_EQ("", error); | 137 EXPECT_EQ("", error); |
| 138 return extension->id(); | 138 return extension->id(); |
| 139 } | 139 } |
| 140 private: | 140 private: |
| 141 NotificationService* service_; | 141 NotificationService* service_; |
| 142 BrowserThread ui_thread_; | 142 BrowserThread ui_thread_; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 TEST_F(ExtensionsActivityMonitorTest, Basic) { | 145 TEST_F(ExtensionsActivityMonitorTest, Basic) { |
| 146 ExtensionsActivityMonitor* monitor = new ExtensionsActivityMonitor(); | 146 ExtensionsActivityMonitor* monitor = new ExtensionsActivityMonitor(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 239 |
| 240 generator.NewEvent<CreateBookmarkFunction>(kTestExtensionPath1, | 240 generator.NewEvent<CreateBookmarkFunction>(kTestExtensionPath1, |
| 241 new CreateBookmarkFunction(), 3); | 241 new CreateBookmarkFunction(), 3); |
| 242 monitor->GetAndClearRecords(&results); | 242 monitor->GetAndClearRecords(&results); |
| 243 | 243 |
| 244 EXPECT_EQ(1U, results.size()); | 244 EXPECT_EQ(1U, results.size()); |
| 245 EXPECT_EQ(3U, results[id1].bookmark_write_count); | 245 EXPECT_EQ(3U, results[id1].bookmark_write_count); |
| 246 | 246 |
| 247 ui_loop()->DeleteSoon(FROM_HERE, monitor); | 247 ui_loop()->DeleteSoon(FROM_HERE, monitor); |
| 248 } | 248 } |
| OLD | NEW |