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

Side by Side Diff: chrome/browser/component_updater/component_patcher_operation_out_of_process_browsertest.cc

Issue 2632143002: Convert utility process out-of-process file patching IPC to mojo (Closed)
Patch Set: Or move just the mojo work to the IO thread. 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
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 "base/base_paths.h"
6 #include "base/bind.h"
7 #include "base/callback.h"
8 #include "base/files/file.h"
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h"
13 #include "base/path_service.h"
14 #include "base/run_loop.h"
15 #include "base/threading/sequenced_task_runner_handle.h"
16 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "components/update_client/component_patcher_operation.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "courgette/courgette.h"
21 #include "courgette/third_party/bsdiff/bsdiff.h"
22
23 class OutOfProcessPatchTest : public InProcessBrowserTest {
24 public:
25 OutOfProcessPatchTest() {
26 EXPECT_TRUE(installed_dir_.CreateUniqueTempDir());
27 EXPECT_TRUE(input_dir_.CreateUniqueTempDir());
28 EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir());
29 }
30
31 static base::FilePath test_file(const char* name) {
32 base::FilePath path;
33 PathService::Get(base::DIR_SOURCE_ROOT, &path);
34 return path.AppendASCII("components")
35 .AppendASCII("test")
36 .AppendASCII("data")
37 .AppendASCII("update_client")
38 .AppendASCII(name);
39 }
40
41 base::FilePath InputFilePath(const char* name) {
42 base::FilePath path = installed_dir_.GetPath().AppendASCII(name);
43
44 base::RunLoop run_loop;
45 content::BrowserThread::PostBlockingPoolTaskAndReply(
46 FROM_HERE,
47 base::Bind(&OutOfProcessPatchTest::CopyFile, test_file(name), path),
48 run_loop.QuitClosure());
49
50 run_loop.Run();
51 return path;
52 }
53
54 base::FilePath PatchFilePath(const char* name) {
55 base::FilePath path = input_dir_.GetPath().AppendASCII(name);
56
57 base::RunLoop run_loop;
58 content::BrowserThread::PostBlockingPoolTaskAndReply(
59 FROM_HERE,
60 base::Bind(&OutOfProcessPatchTest::CopyFile, test_file(name), path),
61 run_loop.QuitClosure());
62
63 run_loop.Run();
64 return path;
65 }
66
67 base::FilePath OutputFilePath(const char* name) {
68 return unpack_dir_.GetPath().AppendASCII(name);
69 }
70
71 base::FilePath InvalidPath(const char* name) {
72 return input_dir_.GetPath().AppendASCII("non-existant").AppendASCII(name);
73 }
74
75 void RunPatchTest(const std::string& operation,
76 const base::FilePath& input,
77 const base::FilePath& patch,
78 const base::FilePath& output,
79 int expected_result) {
80 base::RunLoop run_loop;
81 quit_closure_ = run_loop.QuitClosure();
82 done_called_ = false;
83
84 content::BrowserThread::PostBlockingPoolSequencedTask(
85 "OutOfProcessPatchTest::PatchOnBlockingPoolSequencedTaskRunner",
86 FROM_HERE,
87 base::Bind(
88 &OutOfProcessPatchTest::PatchOnBlockingPoolSequencedTaskRunner,
89 base::Unretained(this), operation, input, patch, output,
90 expected_result));
91
92 run_loop.Run();
93 EXPECT_TRUE(done_called_);
94 }
95
96 private:
97 void PatchOnBlockingPoolSequencedTaskRunner(const std::string& operation,
98 const base::FilePath& input,
99 const base::FilePath& patch,
100 const base::FilePath& output,
101 int expected_result) {
102 scoped_refptr<base::SequencedTaskRunner> task_runner =
103 base::SequencedTaskRunnerHandle::Get();
104
105 scoped_refptr<update_client::OutOfProcessPatcher> patcher =
106 make_scoped_refptr(new component_updater::ChromeOutOfProcessPatcher);
107
108 patcher->Patch(operation, task_runner, input, patch, output,
109 base::Bind(&OutOfProcessPatchTest::PatchDone,
110 base::Unretained(this), expected_result));
111 }
112
113 void PatchDone(int expected, int result) {
114 EXPECT_EQ(expected, result);
115 done_called_ = true;
116 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
117 quit_closure_);
118 }
119
120 static void CopyFile(const base::FilePath& source,
121 const base::FilePath& target) {
122 EXPECT_TRUE(base::CopyFile(source, target));
123 }
124
125 base::ScopedTempDir installed_dir_;
126 base::ScopedTempDir input_dir_;
127 base::ScopedTempDir unpack_dir_;
128 base::Closure quit_closure_;
129 bool done_called_;
130
131 DISALLOW_COPY_AND_ASSIGN(OutOfProcessPatchTest);
132 };
133
134 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, CheckBsdiffOperation) {
135 constexpr int kExpectedResult = bsdiff::OK;
136
137 base::FilePath input_file = InputFilePath("binary_input.bin");
138 base::FilePath patch_file = PatchFilePath("binary_bsdiff_patch.bin");
139 base::FilePath output_file = OutputFilePath("output.bin");
140
141 RunPatchTest(update_client::kBsdiff, input_file, patch_file, output_file,
142 kExpectedResult);
143
144 EXPECT_TRUE(base::ContentsEqual(test_file("binary_output.bin"), output_file));
145 }
146
147 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, CheckCourgetteOperation) {
148 constexpr int kExpectedResult = courgette::C_OK;
149
150 base::FilePath input_file = InputFilePath("binary_input.bin");
151 base::FilePath patch_file = PatchFilePath("binary_courgette_patch.bin");
152 base::FilePath output_file = OutputFilePath("output.bin");
153
154 RunPatchTest(update_client::kCourgette, input_file, patch_file, output_file,
155 kExpectedResult);
156
157 EXPECT_TRUE(base::ContentsEqual(test_file("binary_output.bin"), output_file));
158 }
159
160 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, InvalidInputFile) {
161 constexpr int kInvalidInputFile = -1;
162
163 base::FilePath invalid = InvalidPath("binary_input.bin");
164 base::FilePath patch_file = PatchFilePath("binary_courgette_patch.bin");
165 base::FilePath output_file = OutputFilePath("output.bin");
166
167 RunPatchTest(update_client::kBsdiff, invalid, patch_file, output_file,
Noel Gordon 2017/01/19 13:25:29 Since the patch file is courgette, it would be bet
168 kInvalidInputFile);
169 }
170
171 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, InvalidPatchFile) {
172 constexpr int kInvalidPatchFile = -1;
173
174 base::FilePath input_file = InputFilePath("binary_input.bin");
175 base::FilePath invalid = InvalidPath("binary_courgette_patch.bin");
176 base::FilePath output_file = OutputFilePath("output.bin");
177
178 RunPatchTest(update_client::kBsdiff, input_file, invalid, output_file,
179 kInvalidPatchFile);
180 }
181
182 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, InvalidOutputFile) {
183 constexpr int kInvalidOutputFile = -1;
184
185 base::FilePath input_file = InputFilePath("binary_input.bin");
186 base::FilePath patch_file = PatchFilePath("binary_courgette_patch.bin");
187 base::FilePath invalid = InvalidPath("output.bin");
188
189 RunPatchTest(update_client::kBsdiff, input_file, patch_file, invalid,
190 kInvalidOutputFile);
191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698