Chromium Code Reviews| OLD | NEW |
|---|---|
| (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" | |
|
Sam McNally
2016/12/22 02:45:49
Remove.
Noel Gordon
2016/12/22 05:06:34
Kept.
| |
| 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" | |
|
Sam McNally
2016/12/22 02:45:49
Remove these.
Noel Gordon
2016/12/22 05:06:33
Yes, good spot, done.
Sam McNally
2016/12/22 05:12:48
They're still there.
| |
| 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) { | |
|
Sam McNally
2016/12/22 02:45:49
Prefer passing these as base::StringPiece.
Noel Gordon
2016/12/22 05:06:33
This code came from the update_client unit tests.
| |
| 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 PatchTest(const std::string& operation, | |
|
Sam McNally
2016/12/22 02:45:49
How about RunPatchTest?
Noel Gordon
2016/12/22 05:06:34
Done.
| |
| 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_; | |
|
Sam McNally
2016/12/22 02:45:49
What do these names mean? Could this test use a si
Noel Gordon
2016/12/22 05:06:34
Great question (had the same question myself about
| |
| 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 // Verify that a 'courgette' delta update operation works correctly. | |
| 116 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, CheckCourgetteOperation) { | |
| 117 const int kExpectedResult = courgette::C_OK; | |
| 118 | |
| 119 base::FilePath input_file = InputFilePath("binary_input.bin"); | |
| 120 base::FilePath patch_file = PatchFilePath("binary_courgette_patch.bin"); | |
| 121 base::FilePath output_file = OutputFilePath("output.bin"); | |
| 122 | |
| 123 PatchTest("courgette", input_file, patch_file, output_file, kExpectedResult); | |
|
Sam McNally
2016/12/22 02:45:49
Use the constants for the operation argument.
Noel Gordon
2016/12/22 05:06:33
Yes, done here and in CheckBsdiffOperation below.
| |
| 124 | |
| 125 EXPECT_TRUE(base::ContentsEqual(test_file("binary_output.bin"), output_file)); | |
| 126 } | |
| 127 | |
| 128 // Verify that a 'bsdiff' delta update operation works correctly. | |
| 129 IN_PROC_BROWSER_TEST_F(OutOfProcessPatchTest, CheckBsdiffOperation) { | |
| 130 const int kExpectedResult = bsdiff::OK; | |
| 131 | |
| 132 base::FilePath input_file = InputFilePath("binary_input.bin"); | |
| 133 base::FilePath patch_file = PatchFilePath("binary_bsdiff_patch.bin"); | |
| 134 base::FilePath output_file = OutputFilePath("output.bin"); | |
| 135 | |
| 136 PatchTest("bsdiff", input_file, patch_file, output_file, kExpectedResult); | |
| 137 | |
| 138 EXPECT_TRUE(base::ContentsEqual(test_file("binary_output.bin"), output_file)); | |
| 139 } | |
|
Sam McNally
2016/12/22 02:45:49
How about adding tests where opening input or outp
Noel Gordon
2016/12/22 05:06:33
Added a TODO about this.
| |
| OLD | NEW |