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

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

Issue 2566053002: Convert utility process out-of-process file patching to mojo (Closed)
Patch Set: Address review 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 "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/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h"
17 #include "chrome/browser/component_updater/component_patcher_operation_out_of_pr ocess.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "components/update_client/component_patcher_operation.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "courgette/courgette.h"
22 #include "courgette/third_party/bsdiff/bsdiff.h"
23
24 class OutOfProcessPatchTest : public InProcessBrowserTest {
25 public:
26 OutOfProcessPatchTest() {
27 EXPECT_TRUE(installed_dir_.CreateUniqueTempDir());
28 EXPECT_TRUE(input_dir_.CreateUniqueTempDir());
29 EXPECT_TRUE(unpack_dir_.CreateUniqueTempDir());
30 }
31
32 static base::FilePath test_file(const char* name) {
33 base::FilePath path;
34 PathService::Get(base::DIR_SOURCE_ROOT, &path);
35 return path.AppendASCII("components")
36 .AppendASCII("test")
37 .AppendASCII("data")
38 .AppendASCII("update_client")
39 .AppendASCII(name);
40 }
41
42 base::FilePath InputFilePath(const char* name) {
43 base::FilePath file = installed_dir_.GetPath().AppendASCII(name);
44
45 base::RunLoop run_loop;
46 content::BrowserThread::PostBlockingPoolTaskAndReply(
47 FROM_HERE,
48 base::Bind(&OutOfProcessPatchTest::CopyFile, test_file(name), file),
49 run_loop.QuitClosure());
50
51 run_loop.Run();
52 return file;
53 }
54
55 base::FilePath PatchFilePath(const char* name) {
56 base::FilePath file = input_dir_.GetPath().AppendASCII(name);
57
58 base::RunLoop run_loop;
59 content::BrowserThread::PostBlockingPoolTaskAndReply(
60 FROM_HERE,
61 base::Bind(&OutOfProcessPatchTest::CopyFile, test_file(name), file),
62 run_loop.QuitClosure());
63
64 run_loop.Run();
65 return file;
66 }
67
68 base::FilePath OutputFilePath(const char* name) {
69 base::FilePath file = unpack_dir_.GetPath().AppendASCII(name);
70 return file;
71 }
72
73 void RunPatchTest(const std::string& operation,
74 const base::FilePath& input_file,
75 const base::FilePath& patch_file,
76 const base::FilePath& output_file,
77 int expected_result) {
78 scoped_refptr<base::SequencedTaskRunner> task_runner =
79 base::ThreadTaskRunnerHandle::Get();
80
81 scoped_refptr<update_client::OutOfProcessPatcher> patcher =
82 make_scoped_refptr(new component_updater::ChromeOutOfProcessPatcher);
83
84 base::RunLoop run_loop;
85 patch_done_called_ = false;
86 patcher->Patch(
87 operation, task_runner, input_file, patch_file, output_file,
88 base::Bind(&OutOfProcessPatchTest::PatchDone, base::Unretained(this),
89 run_loop.QuitClosure(), expected_result));
90
91 run_loop.Run();
92 EXPECT_TRUE(patch_done_called_);
93 }
94
95 private:
96 void PatchDone(const base::Closure& quit_closure, int expected, int result) {
97 EXPECT_EQ(expected, result);
98 patch_done_called_ = true;
99 quit_closure.Run();
100 }
101
102 static void CopyFile(const base::FilePath& source,
103 const base::FilePath& target) {
104 EXPECT_TRUE(base::CopyFile(source, target));
105 }
106
107 base::ScopedTempDir installed_dir_;
108 base::ScopedTempDir input_dir_;
109 base::ScopedTempDir unpack_dir_;
110 bool patch_done_called_;
111
112 DISALLOW_COPY_AND_ASSIGN(OutOfProcessPatchTest);
113 };
114
115 // TODO(noel): Add a test where one or more of the files can't be opened.
116
117 // Verify that a 'courgette' delta update operation works correctly.
118 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, CheckCourgetteOperation) {
119 const int kExpectedResult = courgette::C_OK;
120
121 base::FilePath input_file = InputFilePath("binary_input.bin");
122 base::FilePath patch_file = PatchFilePath("binary_courgette_patch.bin");
123 base::FilePath output_file = OutputFilePath("output.bin");
124
125 RunPatchTest(update_client::kCourgette, input_file, patch_file, output_file,
126 kExpectedResult);
127
128 EXPECT_TRUE(base::ContentsEqual(test_file("binary_output.bin"), output_file));
129 }
130
131 // Verify that a 'bsdiff' delta update operation works correctly.
132 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, CheckBsdiffOperation) {
133 const int kExpectedResult = bsdiff::OK;
134
135 base::FilePath input_file = InputFilePath("binary_input.bin");
136 base::FilePath patch_file = PatchFilePath("binary_bsdiff_patch.bin");
137 base::FilePath output_file = OutputFilePath("output.bin");
138
139 RunPatchTest(update_client::kBsdiff, input_file, patch_file, output_file,
140 kExpectedResult);
141
142 EXPECT_TRUE(base::ContentsEqual(test_file("binary_output.bin"), output_file));
143 }
OLDNEW
« no previous file with comments | « chrome/browser/component_updater/component_patcher_operation_out_of_process.cc ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698