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

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

Issue 2576843002: [win] Create ModuleDatabase and ModuleEventSinkImpl. (Closed)
Patch Set: Rework OnProcessStarted. 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 "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "chrome/browser/conflicts/module_database_win.h"
10 #include "chrome/common/conflicts/module_watcher_win.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 // The address of this module in memory. The linker will take care of defining
16 // this symbol.
17 extern "C" IMAGE_DOS_HEADER __ImageBase;
18
19 // An invalid load address.
20 const uint64_t kInvalidLoadAddress = 0xDEADBEEF;
21
22 } // namespace
23
24 class ModuleEventSinkImplTest : public testing::Test {
25 protected:
26 ModuleEventSinkImplTest()
27 : message_loop_(new base::MessageLoop),
grt (UTC plus 2) 2016/12/20 11:11:35 base::MakeUnique?
chrisha 2016/12/20 19:46:24 See previous response.
chrisha 2016/12/21 20:15:00 (Done.)
28 module_database_(new ::ModuleDatabase(message_loop_->task_runner())) {}
29
30 void CreateModuleSinkImpl() {
31 module_event_sink_impl_ = base::MakeUnique<ModuleEventSinkImpl>(
32 ::GetCurrentProcess(), content::PROCESS_TYPE_BROWSER,
33 module_database_.get());
34 }
35
36 ModuleDatabase* module_database() {
37 return module_event_sink_impl_->module_database_;
38 }
39
40 const ModuleDatabase::ModuleSet& modules() {
41 return module_database_->modules_;
42 }
43
44 const ModuleDatabase::ProcessSet& processes() {
45 return module_database_->processes_;
46 }
47
48 uint32_t process_id() { return module_event_sink_impl_->process_id_; }
49
50 std::unique_ptr<base::MessageLoop> message_loop_;
grt (UTC plus 2) 2016/12/20 11:11:35 #include <memory>
chrisha 2016/12/20 19:46:24 Done.
51 std::unique_ptr<ModuleDatabase> module_database_;
52 std::unique_ptr<ModuleEventSinkImpl> module_event_sink_impl_;
53
54 private:
55 DISALLOW_COPY_AND_ASSIGN(ModuleEventSinkImplTest);
56 };
57
58 TEST_F(ModuleEventSinkImplTest, CallsForwardedAsExpected) {
59 const uintptr_t kValidLoadAddress = reinterpret_cast<uintptr_t>(&__ImageBase);
60
61 EXPECT_EQ(0u, modules().size());
62 EXPECT_EQ(0u, processes().size());
63
64 // Construction should immediately fire off a call to OnProcessStarted and
65 // create a process entry in the module database.
66 CreateModuleSinkImpl();
67 EXPECT_EQ(module_database_.get(), module_database());
68 EXPECT_EQ(::GetCurrentProcessId(), process_id());
69 EXPECT_EQ(0u, modules().size());
70 EXPECT_EQ(1u, processes().size());
71
72 // An invalid load event should not cause a module entry.
73 module_event_sink_impl_->OnModuleEvent(
74 mojom::ModuleEventType::MODULE_ALREADY_LOADED, kInvalidLoadAddress);
75 EXPECT_EQ(0u, modules().size());
76 EXPECT_EQ(1u, processes().size());
77
78 // A valid load event should cause a module entry.
79 module_event_sink_impl_->OnModuleEvent(mojom::ModuleEventType::MODULE_LOADED,
80 kValidLoadAddress);
81 EXPECT_EQ(1u, modules().size());
82 EXPECT_EQ(1u, processes().size());
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698