adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 1 | // Copyright (c) 2009 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 <string> |
| 6 | #include <gtest/gtest.h> |
| 7 | #include "update_engine/omaha_response_handler_action.h" |
| 8 | #include "update_engine/test_utils.h" |
| 9 | #include "update_engine/utils.h" |
| 10 | |
| 11 | using std::string; |
| 12 | |
| 13 | namespace chromeos_update_engine { |
| 14 | |
| 15 | class OmahaResponseHandlerActionTest : public ::testing::Test { |
| 16 | public: |
| 17 | // Return true iff the OmahaResponseHandlerAction succeeded. |
| 18 | // If out is non-NULL, it's set w/ the response from the action. |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 19 | bool DoTest(const OmahaResponse& in, |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 20 | const string& boot_dev, |
| 21 | InstallPlan* out); |
| 22 | }; |
| 23 | |
| 24 | class OmahaResponseHandlerActionProcessorDelegate |
| 25 | : public ActionProcessorDelegate { |
| 26 | public: |
| 27 | OmahaResponseHandlerActionProcessorDelegate() |
| 28 | : success_(false), |
| 29 | success_set_(false) {} |
| 30 | void ActionCompleted(ActionProcessor* processor, |
| 31 | AbstractAction* action, |
| 32 | bool success) { |
| 33 | if (action->Type() == OmahaResponseHandlerAction::StaticType()) { |
| 34 | success_ = success; |
| 35 | success_set_ = true; |
| 36 | } |
| 37 | } |
| 38 | bool success_; |
| 39 | bool success_set_; |
| 40 | }; |
| 41 | |
| 42 | namespace { |
| 43 | const string kLongName = |
| 44 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 45 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 46 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 47 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 48 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 49 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 50 | "very_long_name_and_no_slashes-very_long_name_and_no_slashes" |
| 51 | "-the_update_a.b.c.d_DELTA_.tgz"; |
| 52 | } // namespace {} |
| 53 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 54 | bool OmahaResponseHandlerActionTest::DoTest(const OmahaResponse& in, |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 55 | const string& boot_dev, |
| 56 | InstallPlan* out) { |
| 57 | ActionProcessor processor; |
| 58 | OmahaResponseHandlerActionProcessorDelegate delegate; |
| 59 | processor.set_delegate(&delegate); |
| 60 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 61 | ObjectFeederAction<OmahaResponse> feeder_action; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 62 | feeder_action.set_obj(in); |
| 63 | OmahaResponseHandlerAction response_handler_action; |
| 64 | response_handler_action.set_boot_device(boot_dev); |
| 65 | BondActions(&feeder_action, &response_handler_action); |
| 66 | ObjectCollectorAction<InstallPlan> collector_action; |
| 67 | BondActions(&response_handler_action, &collector_action); |
| 68 | processor.EnqueueAction(&feeder_action); |
| 69 | processor.EnqueueAction(&response_handler_action); |
| 70 | processor.EnqueueAction(&collector_action); |
| 71 | processor.StartProcessing(); |
| 72 | EXPECT_TRUE(!processor.IsRunning()) |
| 73 | << "Update test to handle non-asynch actions"; |
| 74 | if (out) |
| 75 | *out = collector_action.object(); |
| 76 | EXPECT_TRUE(delegate.success_set_); |
| 77 | return delegate.success_; |
| 78 | } |
| 79 | |
| 80 | TEST_F(OmahaResponseHandlerActionTest, SimpleTest) { |
| 81 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 82 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 83 | in.update_exists = true; |
| 84 | in.display_version = "a.b.c.d"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 85 | in.codebase = "http://foo/the_update_a.b.c.d.tgz"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 86 | in.more_info_url = "http://more/info"; |
| 87 | in.hash = "HASH+"; |
| 88 | in.size = 12; |
| 89 | in.needs_admin = true; |
| 90 | in.prompt = false; |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame^] | 91 | in.is_delta = false; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 92 | InstallPlan install_plan; |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 93 | EXPECT_TRUE(DoTest(in, "/dev/sda3", &install_plan)); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 94 | EXPECT_TRUE(install_plan.is_full_update); |
| 95 | EXPECT_EQ(in.codebase, install_plan.download_url); |
| 96 | EXPECT_EQ(in.hash, install_plan.download_hash); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 97 | EXPECT_EQ("/dev/sda5", install_plan.install_path); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 98 | } |
| 99 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 100 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 101 | in.update_exists = true; |
| 102 | in.display_version = "a.b.c.d"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 103 | in.codebase = "http://foo/the_update_a.b.c.d.tgz"; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 104 | in.more_info_url = "http://more/info"; |
| 105 | in.hash = "HASHj+"; |
| 106 | in.size = 12; |
| 107 | in.needs_admin = true; |
| 108 | in.prompt = true; |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame^] | 109 | in.is_delta = true; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 110 | InstallPlan install_plan; |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 111 | EXPECT_TRUE(DoTest(in, "/dev/sda5", &install_plan)); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame^] | 112 | EXPECT_FALSE(install_plan.is_full_update); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 113 | EXPECT_EQ(in.codebase, install_plan.download_url); |
| 114 | EXPECT_EQ(in.hash, install_plan.download_hash); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 115 | EXPECT_EQ("/dev/sda3", install_plan.install_path); |
| 116 | } |
| 117 | { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 118 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 119 | in.update_exists = true; |
| 120 | in.display_version = "a.b.c.d"; |
| 121 | in.codebase = kLongName; |
| 122 | in.more_info_url = "http://more/info"; |
| 123 | in.hash = "HASHj+"; |
| 124 | in.size = 12; |
| 125 | in.needs_admin = true; |
| 126 | in.prompt = true; |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame^] | 127 | in.is_delta = false; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 128 | InstallPlan install_plan; |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 129 | EXPECT_TRUE(DoTest(in, "/dev/sda3", &install_plan)); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 130 | EXPECT_TRUE(install_plan.is_full_update); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 131 | EXPECT_EQ(in.codebase, install_plan.download_url); |
| 132 | EXPECT_EQ(in.hash, install_plan.download_hash); |
Andrew de los Reyes | f98bff8 | 2010-05-06 13:33:25 -0700 | [diff] [blame] | 133 | EXPECT_EQ("/dev/sda5", install_plan.install_path); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | TEST_F(OmahaResponseHandlerActionTest, NoUpdatesTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 138 | OmahaResponse in; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 139 | in.update_exists = false; |
| 140 | InstallPlan install_plan; |
| 141 | EXPECT_FALSE(DoTest(in, "/dev/sda1", &install_plan)); |
| 142 | EXPECT_FALSE(install_plan.is_full_update); |
| 143 | EXPECT_EQ("", install_plan.download_url); |
| 144 | EXPECT_EQ("", install_plan.download_hash); |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 145 | EXPECT_EQ("", install_plan.install_path); |
| 146 | } |
| 147 | |
| 148 | } // namespace chromeos_update_engine |