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

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

Issue 2634073002: Revert of [win] Create ModuleDatabase and ModuleEventSinkImpl. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « chrome/browser/conflicts/module_event_sink_impl_win.cc ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/conflicts/module_event_sink_impl_win.h"
6
7 #include <memory>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h"
11 #include "chrome/browser/conflicts/module_database_win.h"
12 #include "chrome/common/conflicts/module_watcher_win.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 // The address of this module in memory. The linker will take care of defining
18 // this symbol.
19 extern "C" IMAGE_DOS_HEADER __ImageBase;
20
21 // An invalid load address.
22 const uint64_t kInvalidLoadAddress = 0xDEADBEEF;
23
24 } // namespace
25
26 class ModuleEventSinkImplTest : public testing::Test {
27 protected:
28 ModuleEventSinkImplTest()
29 : message_loop_(base::MakeUnique<base::MessageLoop>()),
30 module_database_(
31 base::MakeUnique<ModuleDatabase>(message_loop_->task_runner())) {}
32
33 void CreateModuleSinkImpl() {
34 module_event_sink_impl_ = base::MakeUnique<ModuleEventSinkImpl>(
35 ::GetCurrentProcess(), content::PROCESS_TYPE_BROWSER,
36 module_database_.get());
37 }
38
39 ModuleDatabase* module_database() {
40 return module_event_sink_impl_->module_database_;
41 }
42
43 const ModuleDatabase::ModuleMap& modules() {
44 return module_database_->modules_;
45 }
46
47 const ModuleDatabase::ProcessMap& processes() {
48 return module_database_->processes_;
49 }
50
51 uint32_t process_id() { return module_event_sink_impl_->process_id_; }
52
53 std::unique_ptr<base::MessageLoop> message_loop_;
54 std::unique_ptr<ModuleDatabase> module_database_;
55 std::unique_ptr<ModuleEventSinkImpl> module_event_sink_impl_;
56
57 private:
58 DISALLOW_COPY_AND_ASSIGN(ModuleEventSinkImplTest);
59 };
60
61 TEST_F(ModuleEventSinkImplTest, CallsForwardedAsExpected) {
62 const uintptr_t kValidLoadAddress = reinterpret_cast<uintptr_t>(&__ImageBase);
63
64 EXPECT_EQ(0u, modules().size());
65 EXPECT_EQ(0u, processes().size());
66
67 // Construction should immediately fire off a call to OnProcessStarted and
68 // create a process entry in the module database.
69 CreateModuleSinkImpl();
70 EXPECT_EQ(module_database_.get(), module_database());
71 EXPECT_EQ(::GetCurrentProcessId(), process_id());
72 EXPECT_EQ(0u, modules().size());
73 EXPECT_EQ(1u, processes().size());
74
75 // An invalid load event should not cause a module entry.
76 module_event_sink_impl_->OnModuleEvent(
77 mojom::ModuleEventType::MODULE_ALREADY_LOADED, kInvalidLoadAddress);
78 EXPECT_EQ(0u, modules().size());
79 EXPECT_EQ(1u, processes().size());
80
81 // A valid load event should cause a module entry.
82 module_event_sink_impl_->OnModuleEvent(mojom::ModuleEventType::MODULE_LOADED,
83 kValidLoadAddress);
84 EXPECT_EQ(1u, modules().size());
85 EXPECT_EQ(1u, processes().size());
86 }
OLDNEW
« no previous file with comments | « chrome/browser/conflicts/module_event_sink_impl_win.cc ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698