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

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

Issue 2721503003: Add ModuleInspector (Closed)
Patch Set: 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
(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 <vector>
10
11 #include "base/environment.h"
12 #include "base/files/file_path.h"
13 #include "base/macros.h"
14 #include "base/run_loop.h"
15 #include "base/test/scoped_task_scheduler.h"
16 #include "base/test/test_simple_task_runner.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 namespace {
20
21 base::FilePath GetKernel32DllFilePath() {
22 std::unique_ptr<base::Environment> env = base::Environment::Create();
23 std::string sysroot;
24 EXPECT_TRUE(env->GetVar("SYSTEMROOT", &sysroot));
25
26 base::FilePath path =
27 base::FilePath::FromUTF8Unsafe(sysroot).Append(L"system32\\kernel32.dll");
28
29 return path;
30 }
31
32 class ModuleInspectorTest : public testing::Test,
33 public ModuleInspector::Delegate {
34 protected:
35 ModuleInspectorTest()
36 : scoped_task_scheduler_(base::MessageLoop::current()),
37 module_inspector_(this) {}
38
39 void AddModules(const std::vector<ModuleInfoKey>& modules) {
40 for (const auto& module : modules)
41 module_inspector_.AddModule(module);
42 }
43
44 // ModuleInspector::Delegate:
45 void OnModuleInspected(const ModuleInfoKey& module_key,
46 const ModuleInfoData& module_data) override {
47 inspected_modules_.push_back(module_data);
48 }
49
50 const std::vector<ModuleInfoData>& inspected_modules() {
51 return inspected_modules_;
52 }
53
54 private:
55 // Must be before the ModuleInspector.
56 base::test::ScopedTaskScheduler scoped_task_scheduler_;
57
58 ModuleInspector module_inspector_;
59
60 std::vector<ModuleInfoData> inspected_modules_;
61
62 DISALLOW_COPY_AND_ASSIGN(ModuleInspectorTest);
63 };
64
65 } // namespace
66
67 TEST_F(ModuleInspectorTest, OneModule) {
68 AddModules({
69 {GetKernel32DllFilePath(), 0, 0, 1},
70 });
71
72 base::RunLoop().RunUntilIdle();
73
74 EXPECT_EQ(inspected_modules().size(), 1);
75
76 const ModuleInfoData& module_data = inspected_modules()[0];
77 EXPECT_TRUE(module_data.inspected);
78 }
79
80 TEST_F(ModuleInspectorTest, MultipleModules) {
81 AddModules({
82 {base::FilePath(), 0, 0, 1},
83 {base::FilePath(), 0, 0, 2},
84 {base::FilePath(), 0, 0, 3},
85 {base::FilePath(), 0, 0, 4},
86 {base::FilePath(), 0, 0, 5},
87 });
88
89 base::RunLoop().RunUntilIdle();
90
91 EXPECT_EQ(inspected_modules().size(), 5);
92 for (const auto& module_data : inspected_modules())
93 EXPECT_TRUE(module_data.inspected);
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698