Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Side by Side Diff: chrome/browser/conflicts/module_event_sink_impl_win_unittest.cc

Issue 2721503003: Add ModuleInspector (Closed)
Patch Set: merge Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/message_loop/message_loop.h" 10 #include "base/test/scoped_task_scheduler.h"
11 #include "base/threading/sequenced_task_runner_handle.h"
11 #include "chrome/browser/conflicts/module_database_win.h" 12 #include "chrome/browser/conflicts/module_database_win.h"
12 #include "chrome/common/conflicts/module_watcher_win.h" 13 #include "chrome/common/conflicts/module_watcher_win.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace { 16 namespace {
16 17
17 // 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
18 // this symbol. 19 // this symbol.
19 extern "C" IMAGE_DOS_HEADER __ImageBase; 20 extern "C" IMAGE_DOS_HEADER __ImageBase;
20 21
21 // An invalid load address. 22 // An invalid load address.
22 const uint64_t kInvalidLoadAddress = 0xDEADBEEF; 23 const uint64_t kInvalidLoadAddress = 0xDEADBEEF;
23 24
24 } // namespace 25 } // namespace
25 26
26 class ModuleEventSinkImplTest : public testing::Test { 27 class ModuleEventSinkImplTest : public testing::Test {
27 protected: 28 protected:
28 ModuleEventSinkImplTest() 29 ModuleEventSinkImplTest()
29 : message_loop_(base::MakeUnique<base::MessageLoop>()), 30 : module_database_(base::MakeUnique<ModuleDatabase>(
30 module_database_( 31 base::SequencedTaskRunnerHandle::Get())) {}
31 base::MakeUnique<ModuleDatabase>(message_loop_->task_runner())) {}
32 32
33 void CreateModuleSinkImpl() { 33 void CreateModuleSinkImpl() {
34 module_event_sink_impl_ = base::MakeUnique<ModuleEventSinkImpl>( 34 module_event_sink_impl_ = base::MakeUnique<ModuleEventSinkImpl>(
35 ::GetCurrentProcess(), content::PROCESS_TYPE_BROWSER, 35 ::GetCurrentProcess(), content::PROCESS_TYPE_BROWSER,
36 module_database_.get()); 36 module_database_.get());
37 } 37 }
38 38
39 ModuleDatabase* module_database() {
40 return module_event_sink_impl_->module_database_;
41 }
42
43 const ModuleDatabase::ModuleMap& modules() { 39 const ModuleDatabase::ModuleMap& modules() {
44 return module_database_->modules_; 40 return module_database_->modules_;
45 } 41 }
46 42
47 const ModuleDatabase::ProcessMap& processes() { 43 const ModuleDatabase::ProcessMap& processes() {
48 return module_database_->processes_; 44 return module_database_->processes_;
49 } 45 }
50 46
51 uint32_t process_id() { return module_event_sink_impl_->process_id_; } 47 uint32_t process_id() { return module_event_sink_impl_->process_id_; }
52 48
53 std::unique_ptr<base::MessageLoop> message_loop_; 49 // Must be before |module_database_|.
50 base::test::ScopedTaskScheduler scoped_task_scheduler_;
54 std::unique_ptr<ModuleDatabase> module_database_; 51 std::unique_ptr<ModuleDatabase> module_database_;
55 std::unique_ptr<ModuleEventSinkImpl> module_event_sink_impl_; 52 std::unique_ptr<ModuleEventSinkImpl> module_event_sink_impl_;
56 53
57 private: 54 private:
58 DISALLOW_COPY_AND_ASSIGN(ModuleEventSinkImplTest); 55 DISALLOW_COPY_AND_ASSIGN(ModuleEventSinkImplTest);
59 }; 56 };
60 57
61 TEST_F(ModuleEventSinkImplTest, CallsForwardedAsExpected) { 58 TEST_F(ModuleEventSinkImplTest, CallsForwardedAsExpected) {
62 const uintptr_t kValidLoadAddress = reinterpret_cast<uintptr_t>(&__ImageBase); 59 const uintptr_t kValidLoadAddress = reinterpret_cast<uintptr_t>(&__ImageBase);
63 60
64 EXPECT_EQ(0u, modules().size()); 61 EXPECT_EQ(0u, modules().size());
65 EXPECT_EQ(0u, processes().size()); 62 EXPECT_EQ(0u, processes().size());
66 63
67 // Construction should immediately fire off a call to OnProcessStarted and 64 // Construction should immediately fire off a call to OnProcessStarted and
68 // create a process entry in the module database. 65 // create a process entry in the module database.
69 CreateModuleSinkImpl(); 66 CreateModuleSinkImpl();
70 EXPECT_EQ(module_database_.get(), module_database());
71 EXPECT_EQ(::GetCurrentProcessId(), process_id()); 67 EXPECT_EQ(::GetCurrentProcessId(), process_id());
72 EXPECT_EQ(0u, modules().size()); 68 EXPECT_EQ(0u, modules().size());
73 EXPECT_EQ(1u, processes().size()); 69 EXPECT_EQ(1u, processes().size());
74 70
75 // An invalid load event should not cause a module entry. 71 // An invalid load event should not cause a module entry.
76 module_event_sink_impl_->OnModuleEvent( 72 module_event_sink_impl_->OnModuleEvent(
77 mojom::ModuleEventType::MODULE_ALREADY_LOADED, kInvalidLoadAddress); 73 mojom::ModuleEventType::MODULE_ALREADY_LOADED, kInvalidLoadAddress);
78 EXPECT_EQ(0u, modules().size()); 74 EXPECT_EQ(0u, modules().size());
79 EXPECT_EQ(1u, processes().size()); 75 EXPECT_EQ(1u, processes().size());
80 76
81 // A valid load event should cause a module entry. 77 // A valid load event should cause a module entry.
82 module_event_sink_impl_->OnModuleEvent(mojom::ModuleEventType::MODULE_LOADED, 78 module_event_sink_impl_->OnModuleEvent(mojom::ModuleEventType::MODULE_LOADED,
83 kValidLoadAddress); 79 kValidLoadAddress);
84 EXPECT_EQ(1u, modules().size()); 80 EXPECT_EQ(1u, modules().size());
85 EXPECT_EQ(1u, processes().size()); 81 EXPECT_EQ(1u, processes().size());
86 } 82 }
OLDNEW
« no previous file with comments | « chrome/browser/conflicts/module_database_win_unittest.cc ('k') | chrome/browser/conflicts/module_info_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698