| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/conflicts/module_event_sink_impl_win.h" | 5 #include "chrome/browser/conflicts/module_event_sink_impl_win.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/test/scoped_task_scheduler.h" | 10 #include "base/test/scoped_task_environment.h" |
| 11 #include "base/threading/sequenced_task_runner_handle.h" | 11 #include "base/threading/sequenced_task_runner_handle.h" |
| 12 #include "chrome/browser/conflicts/module_database_win.h" | 12 #include "chrome/browser/conflicts/module_database_win.h" |
| 13 #include "chrome/common/conflicts/module_watcher_win.h" | 13 #include "chrome/common/conflicts/module_watcher_win.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // The address of this module in memory. The linker will take care of defining | 18 // The address of this module in memory. The linker will take care of defining |
| 19 // this symbol. | 19 // this symbol. |
| 20 extern "C" IMAGE_DOS_HEADER __ImageBase; | 20 extern "C" IMAGE_DOS_HEADER __ImageBase; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 40 return module_database_->modules_; | 40 return module_database_->modules_; |
| 41 } | 41 } |
| 42 | 42 |
| 43 const ModuleDatabase::ProcessMap& processes() { | 43 const ModuleDatabase::ProcessMap& processes() { |
| 44 return module_database_->processes_; | 44 return module_database_->processes_; |
| 45 } | 45 } |
| 46 | 46 |
| 47 uint32_t process_id() { return module_event_sink_impl_->process_id_; } | 47 uint32_t process_id() { return module_event_sink_impl_->process_id_; } |
| 48 | 48 |
| 49 // Must be before |module_database_|. | 49 // Must be before |module_database_|. |
| 50 base::test::ScopedTaskScheduler scoped_task_scheduler_; | 50 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 51 std::unique_ptr<ModuleDatabase> module_database_; | 51 std::unique_ptr<ModuleDatabase> module_database_; |
| 52 std::unique_ptr<ModuleEventSinkImpl> module_event_sink_impl_; | 52 std::unique_ptr<ModuleEventSinkImpl> module_event_sink_impl_; |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(ModuleEventSinkImplTest); | 55 DISALLOW_COPY_AND_ASSIGN(ModuleEventSinkImplTest); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 TEST_F(ModuleEventSinkImplTest, CallsForwardedAsExpected) { | 58 TEST_F(ModuleEventSinkImplTest, CallsForwardedAsExpected) { |
| 59 const uintptr_t kValidLoadAddress = reinterpret_cast<uintptr_t>(&__ImageBase); | 59 const uintptr_t kValidLoadAddress = reinterpret_cast<uintptr_t>(&__ImageBase); |
| 60 | 60 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 73 mojom::ModuleEventType::MODULE_ALREADY_LOADED, kInvalidLoadAddress); | 73 mojom::ModuleEventType::MODULE_ALREADY_LOADED, kInvalidLoadAddress); |
| 74 EXPECT_EQ(0u, modules().size()); | 74 EXPECT_EQ(0u, modules().size()); |
| 75 EXPECT_EQ(1u, processes().size()); | 75 EXPECT_EQ(1u, processes().size()); |
| 76 | 76 |
| 77 // A valid load event should cause a module entry. | 77 // A valid load event should cause a module entry. |
| 78 module_event_sink_impl_->OnModuleEvent(mojom::ModuleEventType::MODULE_LOADED, | 78 module_event_sink_impl_->OnModuleEvent(mojom::ModuleEventType::MODULE_LOADED, |
| 79 kValidLoadAddress); | 79 kValidLoadAddress); |
| 80 EXPECT_EQ(1u, modules().size()); | 80 EXPECT_EQ(1u, modules().size()); |
| 81 EXPECT_EQ(1u, processes().size()); | 81 EXPECT_EQ(1u, processes().size()); |
| 82 } | 82 } |
| OLD | NEW |