| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/goopdate/offline_utils.h" | |
| 17 #include <atlpath.h> | |
| 18 #include "omaha/base/app_util.h" | |
| 19 #include "omaha/base/debug.h" | |
| 20 #include "omaha/base/error.h" | |
| 21 #include "omaha/base/file.h" | |
| 22 #include "omaha/base/logging.h" | |
| 23 #include "omaha/base/path.h" | |
| 24 #include "omaha/base/utils.h" | |
| 25 #include "omaha/goopdate/update_response_utils.h" | |
| 26 #include "omaha/testing/resource.h" | |
| 27 #include "omaha/testing/unit_test.h" | |
| 28 | |
| 29 namespace omaha { | |
| 30 | |
| 31 namespace { | |
| 32 | |
| 33 const TCHAR* kAppId1 = _T("{CDABE316-39CD-43BA-8440-6D1E0547AEE6}"); | |
| 34 | |
| 35 void CheckResponse(const xml::response::Response& xml_response, | |
| 36 const TCHAR* expected_protocol_version) { | |
| 37 EXPECT_STREQ(expected_protocol_version, xml_response.protocol); | |
| 38 EXPECT_EQ(1, xml_response.apps.size()); | |
| 39 | |
| 40 const xml::response::App& app(xml_response.apps[0]); | |
| 41 EXPECT_STREQ(kAppId1, app.appid); | |
| 42 EXPECT_STREQ(_T("ok"), app.status); | |
| 43 | |
| 44 const xml::response::UpdateCheck& update_check(app.update_check); | |
| 45 EXPECT_STREQ(_T("ok"), update_check.status); | |
| 46 EXPECT_EQ(1, update_check.urls.size()); | |
| 47 EXPECT_STREQ(_T("http://dl.google.com/foo/install/1.2.3.4/"), | |
| 48 update_check.urls[0]); | |
| 49 | |
| 50 const xml::InstallManifest& install_manifest(update_check.install_manifest); | |
| 51 EXPECT_STREQ(_T("1.2.3.4"), install_manifest.version); | |
| 52 EXPECT_EQ(1, install_manifest.packages.size()); | |
| 53 | |
| 54 const xml::InstallPackage& install_package(install_manifest.packages[0]); | |
| 55 EXPECT_STREQ(_T("foo_installer.exe"), install_package.name); | |
| 56 EXPECT_TRUE(install_package.is_required); | |
| 57 EXPECT_EQ(12345678, install_package.size); | |
| 58 EXPECT_STREQ(_T("abcdef"), install_package.hash); | |
| 59 | |
| 60 EXPECT_EQ(2, install_manifest.install_actions.size()); | |
| 61 | |
| 62 const xml::InstallAction* install_action( | |
| 63 &install_manifest.install_actions[0]); | |
| 64 EXPECT_EQ(xml::InstallAction::kInstall, install_action->install_event); | |
| 65 EXPECT_EQ(NEEDS_ADMIN_NO, install_action->needs_admin); | |
| 66 EXPECT_STREQ(_T("foo_installer.exe"), install_action->program_to_run); | |
| 67 EXPECT_STREQ(_T("-baz"), install_action->program_arguments); | |
| 68 EXPECT_FALSE(install_action->terminate_all_browsers); | |
| 69 EXPECT_EQ(SUCCESS_ACTION_DEFAULT, install_action->success_action); | |
| 70 | |
| 71 install_action = &install_manifest.install_actions[1]; | |
| 72 EXPECT_EQ(xml::InstallAction::kPostInstall, install_action->install_event); | |
| 73 EXPECT_EQ(NEEDS_ADMIN_NO, install_action->needs_admin); | |
| 74 EXPECT_FALSE(install_action->terminate_all_browsers); | |
| 75 EXPECT_EQ(SUCCESS_ACTION_EXIT_SILENTLY_ON_LAUNCH_CMD, | |
| 76 install_action->success_action); | |
| 77 | |
| 78 EXPECT_EQ(0, app.events.size()); | |
| 79 | |
| 80 CString value; | |
| 81 CString verboselogging_install_data(_T("\n {\n \"distribution\": {
\n \"verbose_logging\": true\n }\n }\n ")); // NOLINT | |
| 82 EXPECT_SUCCEEDED(update_response_utils::GetInstallData(app.data, | |
| 83 _T("verboselogging"), | |
| 84 &value)); | |
| 85 EXPECT_STREQ(verboselogging_install_data, value); | |
| 86 | |
| 87 CString foobarapp_install_data(_T("\n {\n \"distribution\": {\n
\"skip_first_run_ui\": true,\n \"show_welcome_page\": true,\n
\"import_search_engine\": true,\n \"import_history\": false,\n
\"create_all_shortcuts\": true,\n \"do_not_launch_foo\": true,\
n \"make_foo_default\": false,\n \"verbose_logging\": false\n
}\n }\n ")); // NOLINT | |
| 88 EXPECT_SUCCEEDED(update_response_utils::GetInstallData(app.data, | |
| 89 _T("foobarapp"), | |
| 90 &value)); | |
| 91 EXPECT_STREQ(foobarapp_install_data, value); | |
| 92 | |
| 93 EXPECT_EQ(GOOPDATE_E_INVALID_INSTALL_DATA_INDEX, | |
| 94 update_response_utils::GetInstallData(app.data, _T("foo"), &value)); | |
| 95 } | |
| 96 | |
| 97 void ParseAndCheck(const TCHAR* source_manifest_extension, | |
| 98 const TCHAR* target_manifest_filename, | |
| 99 const TCHAR* expected_protocol_version) { | |
| 100 CString source_manifest_path = ConcatenatePath( | |
| 101 app_util::GetCurrentModuleDirectory(), _T("unittest_support")); | |
| 102 source_manifest_path = ConcatenatePath(source_manifest_path, kAppId1); | |
| 103 source_manifest_path += source_manifest_extension; | |
| 104 | |
| 105 CString target_manifest_path = ConcatenatePath( | |
| 106 app_util::GetCurrentModuleDirectory(), target_manifest_filename); | |
| 107 | |
| 108 EXPECT_SUCCEEDED(File::Copy(source_manifest_path, target_manifest_path, | |
| 109 true)); | |
| 110 | |
| 111 scoped_ptr<xml::UpdateResponse> update_response( | |
| 112 xml::UpdateResponse::Create()); | |
| 113 EXPECT_SUCCEEDED(offline_utils::ParseOfflineManifest( | |
| 114 kAppId1, | |
| 115 app_util::GetCurrentModuleDirectory(), | |
| 116 update_response.get())); | |
| 117 | |
| 118 CheckResponse(update_response->response(), expected_protocol_version); | |
| 119 | |
| 120 EXPECT_SUCCEEDED(File::Remove(target_manifest_path)); | |
| 121 } | |
| 122 | |
| 123 } // namespace | |
| 124 | |
| 125 namespace offline_utils { | |
| 126 | |
| 127 TEST(OfflineUtilsTest, GetV2OfflineManifest) { | |
| 128 CString manifest_path = offline_utils::GetV2OfflineManifest( | |
| 129 kAppId1, app_util::GetCurrentModuleDirectory()); | |
| 130 | |
| 131 EXPECT_STREQ(ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
| 132 CString(kAppId1) + _T(".gup")), | |
| 133 manifest_path); | |
| 134 } | |
| 135 | |
| 136 TEST(OfflineUtilsTest, FindV2OfflinePackagePath_Success) { | |
| 137 CString installer_exe = _T("foo_installer.exe"); | |
| 138 CString installer_path = ConcatenatePath( | |
| 139 app_util::GetCurrentModuleDirectory(), | |
| 140 kAppId1); | |
| 141 EXPECT_SUCCEEDED(CreateDir(installer_path, NULL)); | |
| 142 EXPECT_SUCCEEDED(File::Copy( | |
| 143 ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
| 144 _T("unittest_support\\SaveArguments.exe")), | |
| 145 ConcatenatePath(installer_path, installer_exe), | |
| 146 true)); | |
| 147 | |
| 148 CString package_path; | |
| 149 EXPECT_SUCCEEDED(offline_utils::FindV2OfflinePackagePath(installer_path, | |
| 150 &package_path)); | |
| 151 EXPECT_STREQ(ConcatenatePath(installer_path, installer_exe), package_path); | |
| 152 | |
| 153 EXPECT_SUCCEEDED(DeleteDirectory(installer_path)); | |
| 154 } | |
| 155 | |
| 156 TEST(OfflineUtilsTest, FindV2OfflinePackagePath_Failure) { | |
| 157 CString package_path; | |
| 158 EXPECT_EQ(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), | |
| 159 offline_utils::FindV2OfflinePackagePath( | |
| 160 ConcatenatePath(app_util::GetCurrentModuleDirectory(), | |
| 161 kAppId1), | |
| 162 &package_path)); | |
| 163 EXPECT_TRUE(package_path.IsEmpty()); | |
| 164 } | |
| 165 | |
| 166 TEST(OfflineUtilsTest, ParseOfflineManifest_v3_Success) { | |
| 167 ParseAndCheck(_T(".v3.gup"), kOfflineManifestFileName, _T("3.0")); | |
| 168 } | |
| 169 | |
| 170 TEST(OfflineUtilsTest, ParseOfflineManifest_v2_Success) { | |
| 171 CString target_manifest_filename = CString(kAppId1) + _T(".gup"); | |
| 172 ParseAndCheck(_T(".v2.gup"), target_manifest_filename, _T("2.0")); | |
| 173 } | |
| 174 | |
| 175 TEST(OfflineUtilsTest, ParseOfflineManifest_FileDoesNotExist) { | |
| 176 scoped_ptr<xml::UpdateResponse> update_response( | |
| 177 xml::UpdateResponse::Create()); | |
| 178 EXPECT_EQ(HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), | |
| 179 offline_utils::ParseOfflineManifest( | |
| 180 kAppId1, | |
| 181 app_util::GetCurrentModuleDirectory(), | |
| 182 update_response.get())); | |
| 183 } | |
| 184 | |
| 185 } // namespace offline_utils | |
| 186 | |
| 187 } // namespace omaha | |
| OLD | NEW |