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

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

Issue 2576843002: [win] Create ModuleDatabase and ModuleEventSinkImpl. (Closed)
Patch Set: Address grt's comments. Created 4 years 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
(Empty)
1 // Copyright 2016 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_(new base::MessageLoop),
30 module_database_(new ::ModuleDatabase(message_loop_->task_runner())) {}
31
32 void CreateModuleSinkImpl() {
33 module_event_sink_impl_ = base::MakeUnique<ModuleEventSinkImpl>(
34 ::GetCurrentProcess(), content::PROCESS_TYPE_BROWSER,
35 module_database_.get());
36 }
37
38 ModuleDatabase* module_database() {
39 return module_event_sink_impl_->module_database_;
40 }
41
42 const ModuleDatabase::ModuleSet& modules() {
43 return module_database_->modules_;
44 }
45
46 const ModuleDatabase::ProcessSet& processes() {
47 return module_database_->processes_;
48 }
49
50 uint32_t process_id() { return module_event_sink_impl_->process_id_; }
51
52 std::unique_ptr<base::MessageLoop> message_loop_;
53 std::unique_ptr<ModuleDatabase> module_database_;
54 std::unique_ptr<ModuleEventSinkImpl> module_event_sink_impl_;
55
56 private:
57 DISALLOW_COPY_AND_ASSIGN(ModuleEventSinkImplTest);
58 };
59
60 TEST_F(ModuleEventSinkImplTest, CallsForwardedAsExpected) {
61 const uintptr_t kValidLoadAddress = reinterpret_cast<uintptr_t>(&__ImageBase);
62
63 EXPECT_EQ(0u, modules().size());
64 EXPECT_EQ(0u, processes().size());
65
66 // Construction should immediately fire off a call to OnProcessStarted and
67 // create a process entry in the module database.
68 CreateModuleSinkImpl();
69 EXPECT_EQ(module_database_.get(), module_database());
70 EXPECT_EQ(::GetCurrentProcessId(), process_id());
71 EXPECT_EQ(0u, modules().size());
72 EXPECT_EQ(1u, processes().size());
73
74 // An invalid load event should not cause a module entry.
75 module_event_sink_impl_->OnModuleEvent(
76 mojom::ModuleEventType::MODULE_ALREADY_LOADED, kInvalidLoadAddress);
77 EXPECT_EQ(0u, modules().size());
78 EXPECT_EQ(1u, processes().size());
79
80 // A valid load event should cause a module entry.
81 module_event_sink_impl_->OnModuleEvent(mojom::ModuleEventType::MODULE_LOADED,
82 kValidLoadAddress);
83 EXPECT_EQ(1u, modules().size());
84 EXPECT_EQ(1u, processes().size());
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698