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

Side by Side Diff: chrome/browser/conflicts/module_inspector_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
« no previous file with comments | « chrome/browser/conflicts/module_inspector_win.cc ('k') | chrome/test/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_inspector_win.h"
6
7 #include <memory>
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "base/bind.h"
13 #include "base/environment.h"
14 #include "base/files/file_path.h"
15 #include "base/macros.h"
16 #include "base/run_loop.h"
17 #include "base/test/scoped_task_scheduler.h"
18 #include "base/test/test_simple_task_runner.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 namespace {
22
23 base::FilePath GetKernel32DllFilePath() {
24 std::unique_ptr<base::Environment> env = base::Environment::Create();
25 std::string sysroot;
26 EXPECT_TRUE(env->GetVar("SYSTEMROOT", &sysroot));
27
28 base::FilePath path =
29 base::FilePath::FromUTF8Unsafe(sysroot).Append(L"system32\\kernel32.dll");
30
31 return path;
32 }
33
34 class ModuleInspectorTest : public testing::Test {
35 protected:
36 ModuleInspectorTest()
37 : scoped_task_scheduler_(base::MessageLoop::current()),
38 module_inspector_(base::Bind(&ModuleInspectorTest::OnModuleInspected,
39 base::Unretained(this))) {}
40
41 void AddModules(const std::vector<ModuleInfoKey>& modules) {
42 for (const auto& module : modules)
43 module_inspector_.AddModule(module);
44 }
45
46 // Callback for ModuleInspector.
47 void OnModuleInspected(
48 const ModuleInfoKey& module_key,
49 std::unique_ptr<ModuleInspectionResult> inspection_result) {
50 inspected_modules_.push_back(std::move(inspection_result));
51 }
52
53 const std::vector<std::unique_ptr<ModuleInspectionResult>>&
54 inspected_modules() {
55 return inspected_modules_;
56 }
57
58 private:
59 // Must be before the ModuleInspector.
60 base::test::ScopedTaskScheduler scoped_task_scheduler_;
61
62 ModuleInspector module_inspector_;
63
64 std::vector<std::unique_ptr<ModuleInspectionResult>> inspected_modules_;
65
66 DISALLOW_COPY_AND_ASSIGN(ModuleInspectorTest);
67 };
68
69 } // namespace
70
71 TEST_F(ModuleInspectorTest, OneModule) {
72 AddModules({
73 {GetKernel32DllFilePath(), 0, 0, 1},
74 });
75
76 base::RunLoop().RunUntilIdle();
77
78 EXPECT_EQ(1u, inspected_modules().size());
79
80 EXPECT_TRUE(inspected_modules().front());
81 }
82
83 TEST_F(ModuleInspectorTest, MultipleModules) {
84 AddModules({
85 {base::FilePath(), 0, 0, 1},
86 {base::FilePath(), 0, 0, 2},
87 {base::FilePath(), 0, 0, 3},
88 {base::FilePath(), 0, 0, 4},
89 {base::FilePath(), 0, 0, 5},
90 });
91
92 base::RunLoop().RunUntilIdle();
93
94 EXPECT_EQ(5u, inspected_modules().size());
95 for (const auto& inspection_result : inspected_modules())
96 EXPECT_TRUE(inspection_result);
97 }
OLDNEW
« no previous file with comments | « chrome/browser/conflicts/module_inspector_win.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698