| 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" |
| 11 #include "chrome/browser/extensions/extension_bookmarks_module.h" | 11 #include "chrome/browser/extensions/extension_bookmarks_module.h" |
| 12 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_constants.h" | 14 #include "chrome/common/extensions/extension_constants.h" |
| 15 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
| 16 #include "content/common/notification_service.h" | 16 #include "content/browser/notification_service_impl.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using browser_sync::ExtensionsActivityMonitor; | 19 using browser_sync::ExtensionsActivityMonitor; |
| 20 namespace keys = extension_manifest_keys; | 20 namespace keys = extension_manifest_keys; |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const FilePath::CharType kTestExtensionPath1[] = | 24 const FilePath::CharType kTestExtensionPath1[] = |
| 25 #if defined(OS_POSIX) | 25 #if defined(OS_POSIX) |
| 26 FILE_PATH_LITERAL("/testextension1"); | 26 FILE_PATH_LITERAL("/testextension1"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 const char* kTestExtensionName = "foo extension"; | 39 const char* kTestExtensionName = "foo extension"; |
| 40 | 40 |
| 41 template <class FunctionType> | 41 template <class FunctionType> |
| 42 class BookmarkAPIEventTask : public Task { | 42 class BookmarkAPIEventTask : public Task { |
| 43 public: | 43 public: |
| 44 BookmarkAPIEventTask(FunctionType* t, Extension* e, size_t repeats, | 44 BookmarkAPIEventTask(FunctionType* t, Extension* e, size_t repeats, |
| 45 base::WaitableEvent* done) : | 45 base::WaitableEvent* done) : |
| 46 extension_(e), function_(t), repeats_(repeats), done_(done) {} | 46 extension_(e), function_(t), repeats_(repeats), done_(done) {} |
| 47 virtual void Run() { | 47 virtual void Run() { |
| 48 for (size_t i = 0; i < repeats_; i++) { | 48 for (size_t i = 0; i < repeats_; i++) { |
| 49 NotificationService::current()->Notify( | 49 content::NotificationService::current()->Notify( |
| 50 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, | 50 chrome::NOTIFICATION_EXTENSION_BOOKMARKS_API_INVOKED, |
| 51 content::Source<Extension>(extension_.get()), | 51 content::Source<Extension>(extension_.get()), |
| 52 content::Details<const BookmarksFunction>(function_.get())); | 52 content::Details<const BookmarksFunction>(function_.get())); |
| 53 } | 53 } |
| 54 done_->Signal(); | 54 done_->Signal(); |
| 55 } | 55 } |
| 56 private: | 56 private: |
| 57 scoped_refptr<Extension> extension_; | 57 scoped_refptr<Extension> extension_; |
| 58 scoped_refptr<FunctionType> function_; | 58 scoped_refptr<FunctionType> function_; |
| 59 size_t repeats_; | 59 size_t repeats_; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 84 done_event.Wait(); | 84 done_event.Wait(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(BookmarkAPIEventGenerator); | 88 DISALLOW_COPY_AND_ASSIGN(BookmarkAPIEventGenerator); |
| 89 }; | 89 }; |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 class DoUIThreadSetupTask : public Task { | 92 class DoUIThreadSetupTask : public Task { |
| 93 public: | 93 public: |
| 94 DoUIThreadSetupTask(NotificationService** service, | 94 DoUIThreadSetupTask(content::NotificationService** service, |
| 95 base::WaitableEvent* done) | 95 base::WaitableEvent* done) |
| 96 : service_(service), signal_when_done_(done) {} | 96 : service_(service), signal_when_done_(done) {} |
| 97 virtual ~DoUIThreadSetupTask() {} | 97 virtual ~DoUIThreadSetupTask() {} |
| 98 virtual void Run() { | 98 virtual void Run() { |
| 99 *service_ = new NotificationService(); | 99 *service_ = new NotificationServiceImpl(); |
| 100 signal_when_done_->Signal(); | 100 signal_when_done_->Signal(); |
| 101 } | 101 } |
| 102 private: | 102 private: |
| 103 NotificationService** service_; | 103 content::NotificationService** service_; |
| 104 base::WaitableEvent* signal_when_done_; | 104 base::WaitableEvent* signal_when_done_; |
| 105 DISALLOW_COPY_AND_ASSIGN(DoUIThreadSetupTask); | 105 DISALLOW_COPY_AND_ASSIGN(DoUIThreadSetupTask); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 class ExtensionsActivityMonitorTest : public testing::Test { | 108 class ExtensionsActivityMonitorTest : public testing::Test { |
| 109 public: | 109 public: |
| 110 ExtensionsActivityMonitorTest() : service_(NULL), | 110 ExtensionsActivityMonitorTest() : service_(NULL), |
| 111 ui_thread_(BrowserThread::UI) { } | 111 ui_thread_(BrowserThread::UI) { } |
| 112 virtual ~ExtensionsActivityMonitorTest() {} | 112 virtual ~ExtensionsActivityMonitorTest() {} |
| 113 | 113 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 132 DictionaryValue input; | 132 DictionaryValue input; |
| 133 input.SetString(keys::kVersion, kTestExtensionVersion); | 133 input.SetString(keys::kVersion, kTestExtensionVersion); |
| 134 input.SetString(keys::kName, kTestExtensionName); | 134 input.SetString(keys::kName, kTestExtensionName); |
| 135 scoped_refptr<Extension> extension(Extension::Create( | 135 scoped_refptr<Extension> extension(Extension::Create( |
| 136 FilePath(extension_path), Extension::INVALID, input, | 136 FilePath(extension_path), Extension::INVALID, input, |
| 137 Extension::STRICT_ERROR_CHECKS, &error)); | 137 Extension::STRICT_ERROR_CHECKS, &error)); |
| 138 EXPECT_EQ("", error); | 138 EXPECT_EQ("", error); |
| 139 return extension->id(); | 139 return extension->id(); |
| 140 } | 140 } |
| 141 private: | 141 private: |
| 142 NotificationService* service_; | 142 content::NotificationService* service_; |
| 143 BrowserThread ui_thread_; | 143 BrowserThread ui_thread_; |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 TEST_F(ExtensionsActivityMonitorTest, Basic) { | 146 TEST_F(ExtensionsActivityMonitorTest, Basic) { |
| 147 ExtensionsActivityMonitor* monitor = new ExtensionsActivityMonitor(); | 147 ExtensionsActivityMonitor* monitor = new ExtensionsActivityMonitor(); |
| 148 BookmarkAPIEventGenerator generator; | 148 BookmarkAPIEventGenerator generator; |
| 149 | 149 |
| 150 generator.NewEvent<RemoveBookmarkFunction>(kTestExtensionPath1, | 150 generator.NewEvent<RemoveBookmarkFunction>(kTestExtensionPath1, |
| 151 new RemoveBookmarkFunction(), 1); | 151 new RemoveBookmarkFunction(), 1); |
| 152 generator.NewEvent<MoveBookmarkFunction>(kTestExtensionPath1, | 152 generator.NewEvent<MoveBookmarkFunction>(kTestExtensionPath1, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 240 |
| 241 generator.NewEvent<CreateBookmarkFunction>(kTestExtensionPath1, | 241 generator.NewEvent<CreateBookmarkFunction>(kTestExtensionPath1, |
| 242 new CreateBookmarkFunction(), 3); | 242 new CreateBookmarkFunction(), 3); |
| 243 monitor->GetAndClearRecords(&results); | 243 monitor->GetAndClearRecords(&results); |
| 244 | 244 |
| 245 EXPECT_EQ(1U, results.size()); | 245 EXPECT_EQ(1U, results.size()); |
| 246 EXPECT_EQ(3U, results[id1].bookmark_write_count); | 246 EXPECT_EQ(3U, results[id1].bookmark_write_count); |
| 247 | 247 |
| 248 ui_loop()->DeleteSoon(FROM_HERE, monitor); | 248 ui_loop()->DeleteSoon(FROM_HERE, monitor); |
| 249 } | 249 } |
| OLD | NEW |