| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-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 // Test app for the Google Update recovery mechanism. | |
| 17 #include <windows.h> | |
| 18 #include <atlstr.h> | |
| 19 #include "omaha/base/const_addresses.h" | |
| 20 #include "omaha/base/constants.h" | |
| 21 #include "omaha/base/debug.h" | |
| 22 #include "omaha/base/logging.h" | |
| 23 #include "omaha/net/network_config.h" | |
| 24 #include "omaha/net/network_request.h" | |
| 25 #include "omaha/recovery/client/google_update_recovery.h" | |
| 26 | |
| 27 using omaha::UpdateDevProxyDetector; | |
| 28 using omaha::FirefoxProxyDetector; | |
| 29 using omaha::IEProxyDetector; | |
| 30 using omaha::NetworkRequest; | |
| 31 using omaha::NetworkConfig; | |
| 32 using omaha::NetworkConfigManager; | |
| 33 | |
| 34 namespace { | |
| 35 | |
| 36 // Implements the DownloadFileMethod signature. | |
| 37 HRESULT DownloadFile(const TCHAR* url, const TCHAR* file_path, void*) { | |
| 38 UTIL_LOG(L2, (_T("[DownloadFile][%s][%s]"), url, file_path)); | |
| 39 | |
| 40 ASSERT1(url); | |
| 41 ASSERT1(file_path); | |
| 42 | |
| 43 CString test_url(url); | |
| 44 CString test_file_path(file_path); | |
| 45 | |
| 46 // Include this code to override the address portion of the URL. | |
| 47 #if 1 | |
| 48 // Change the URL below to point to a test repair exe of your own. | |
| 49 const TCHAR* const kTestAddress = | |
| 50 _T("http://dl.google.com/insert_your_file_here?"); | |
| 51 | |
| 52 VERIFY1(1 == test_url.Replace(omaha::kUrlCodeRedCheck, kTestAddress)); | |
| 53 #endif | |
| 54 | |
| 55 // Initialize the network for user with no impersonation required. | |
| 56 NetworkConfigManager::set_is_machine(false); | |
| 57 NetworkConfig* network_config = NULL; | |
| 58 HRESULT hr = S_OK; | |
| 59 hr = NetworkConfigManager::Instance().GetUserNetworkConfig(&network_config); | |
| 60 if (FAILED(hr)) { | |
| 61 UTIL_LOG(LE, (_T("[GetUserNetworkConfig failed][0x%08x]"), hr)); | |
| 62 return hr; | |
| 63 } | |
| 64 network_config->Clear(); | |
| 65 network_config->Add(new UpdateDevProxyDetector); | |
| 66 network_config->Add(new FirefoxProxyDetector); | |
| 67 network_config->Add(new IEProxyDetector); | |
| 68 | |
| 69 NetworkRequest network_request(network_config->session()); | |
| 70 hr = network_request.DownloadFile(test_url, CString(file_path)); | |
| 71 | |
| 72 hr = network_request.DownloadFile(test_url, CString(file_path)); | |
| 73 if (FAILED(hr)) { | |
| 74 UTIL_LOG(LE, (_T("[DownloadFile failed][%s][0x%08x]"), test_url, hr)); | |
| 75 return hr; | |
| 76 } | |
| 77 | |
| 78 int status_code = network_request.http_status_code(); | |
| 79 UTIL_LOG(L2, (_T("[HTTP status][%u]"), status_code)); | |
| 80 | |
| 81 return (HTTP_STATUS_OK == status_code) ? S_OK : E_FAIL; | |
| 82 } | |
| 83 | |
| 84 } // namespace | |
| 85 | |
| 86 int main() { | |
| 87 const TCHAR* const kDummyGuid = _T("{20F8FA32-8E16-4046-834B-88661E021AFC}"); | |
| 88 | |
| 89 HRESULT hr = FixGoogleUpdate(kDummyGuid, | |
| 90 _T("1.0.555.0"), | |
| 91 _T("en-us"), | |
| 92 true, | |
| 93 DownloadFile, | |
| 94 NULL); | |
| 95 | |
| 96 return hr; | |
| 97 } | |
| OLD | NEW |