| 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 <windows.h> | |
| 17 #include <atlpath.h> | |
| 18 #include <atlsecurity.h> | |
| 19 #include <atlstr.h> | |
| 20 #include <vector> | |
| 21 #include "omaha/base/error.h" | |
| 22 #include "omaha/base/omaha_version.h" | |
| 23 #include "omaha/base/reg_key.h" | |
| 24 #include "omaha/base/string.h" | |
| 25 #include "omaha/base/utils.h" | |
| 26 #include "omaha/base/vistautil.h" | |
| 27 #include "omaha/client/help_url_builder.h" | |
| 28 #include "omaha/common/config_manager.h" | |
| 29 #include "omaha/common/goopdate_utils.h" | |
| 30 #include "omaha/net/http_client.h" | |
| 31 #include "omaha/testing/unit_test.h" | |
| 32 | |
| 33 namespace omaha { | |
| 34 | |
| 35 namespace { | |
| 36 | |
| 37 #define APP_GUID _T("{B7BAF788-9D64-49c3-AFDC-B336AB12F332}") | |
| 38 #define APP_GUID2 _T("{6D2DF75B-11F0-41CA-9874-79DE4568527C}") | |
| 39 const TCHAR* const kAppGuid = APP_GUID; | |
| 40 const TCHAR* const kAppGuid2 = APP_GUID2; | |
| 41 | |
| 42 const TCHAR kStringAlmostTooLongForUrl[] = | |
| 43 _T("000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000"); // NOLINT | |
| 44 | |
| 45 // Verifies that one of the expected OS strings was found in the url. | |
| 46 // Returns the position along with the length of the OS string. | |
| 47 int VerifyOSInUrl(const CString& url, int* length) { | |
| 48 ASSERT1(length); | |
| 49 *length = 0; | |
| 50 | |
| 51 // The strings are in descending version order to avoid breaking on a | |
| 52 // substring of the version we are looking for. | |
| 53 // TODO(omaha): This is a maintenance problem. Consider eliminating the | |
| 54 // "&sp=" at the very least. | |
| 55 const TCHAR* kExpectedOsStrings[] = {_T("6.1&sp=Service%20Pack%201"), | |
| 56 _T("6.1&sp="), | |
| 57 _T("6.0&sp=Service%20Pack%201"), | |
| 58 _T("6.0&sp="), | |
| 59 _T("5.2&sp=Service%20Pack%202"), | |
| 60 _T("5.2&sp=Service%20Pack%201"), | |
| 61 _T("5.1&sp=Service%20Pack%203"), | |
| 62 _T("5.1&sp=Service%20Pack%202"), | |
| 63 }; | |
| 64 | |
| 65 bool found = false; | |
| 66 int this_pos = 0; | |
| 67 | |
| 68 for (int i = 0; i < arraysize(kExpectedOsStrings); ++i) { | |
| 69 this_pos = url.Find(kExpectedOsStrings[i]); | |
| 70 if (-1 != this_pos) { | |
| 71 found = true; | |
| 72 *length = _tcslen(kExpectedOsStrings[i]); | |
| 73 break; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 EXPECT_TRUE(found); | |
| 78 return this_pos; | |
| 79 } | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 class HelpUrlBuilderTest : public testing::Test { | |
| 84 protected: | |
| 85 HRESULT BuildHttpGetString( | |
| 86 const CString& base_url, | |
| 87 const std::vector<HelpUrlBuilder::AppResult>& app_results, | |
| 88 const CString& goopdate_version, | |
| 89 bool is_machine, | |
| 90 const CString& language, | |
| 91 const GUID& iid, | |
| 92 const CString& brand_code, | |
| 93 const CString& source_id, | |
| 94 CString* get_request) const { | |
| 95 HelpUrlBuilder url_builder(is_machine, language, iid, brand_code); | |
| 96 return url_builder.BuildHttpGetString(base_url, | |
| 97 app_results, | |
| 98 goopdate_version, | |
| 99 source_id, | |
| 100 get_request); | |
| 101 } | |
| 102 | |
| 103 HelpUrlBuilderTest() : hive_override_key_name_(kRegistryHiveOverrideRoot), | |
| 104 module_version_(GetVersion()) { | |
| 105 } | |
| 106 | |
| 107 virtual void SetUp() { | |
| 108 RegKey::DeleteKey(hive_override_key_name_, true); | |
| 109 OverrideRegistryHives(hive_override_key_name_); | |
| 110 InitializeVersion(kFakeVersion); | |
| 111 } | |
| 112 | |
| 113 virtual void TearDown() { | |
| 114 InitializeVersion(module_version_); | |
| 115 RestoreRegistryHives(); | |
| 116 ASSERT_SUCCEEDED(RegKey::DeleteKey(hive_override_key_name_, true)); | |
| 117 } | |
| 118 | |
| 119 CString hive_override_key_name_; | |
| 120 const ULONGLONG module_version_; | |
| 121 | |
| 122 static const ULONGLONG kFakeVersion = 0x0005000600070008; | |
| 123 }; | |
| 124 | |
| 125 TEST_F(HelpUrlBuilderTest, BuildHttpGetString_MachineNoTestSource) { | |
| 126 CString expected_str_before_os( | |
| 127 _T("http://www.google.com/hello.py?code=123&hl=en&") | |
| 128 _T("app.0=%7BB7BAF788-9D64-49c3-AFDC-B336AB12F332%7D&") | |
| 129 _T("ec.0=0xa&ex.0=22&") | |
| 130 _T("guver=1.0.51.0&m=1&os=")); | |
| 131 CString expected_str_after_os( | |
| 132 _T("&iid=%7B0F973A20-C484-462B-952C-5D9A459E3326%7D") // Upper case 'B'. | |
| 133 _T("&brand=GoOG&source=click")); | |
| 134 bool expected_test_source = false; | |
| 135 | |
| 136 #if defined(DEBUG) || !OFFICIAL_BUILD | |
| 137 // TestSource is always set for these builds. It may be set for opt official | |
| 138 // builds but this is not guaranteed. | |
| 139 expected_str_after_os.Append(_T("&testsource=")); | |
| 140 expected_test_source = true; | |
| 141 #endif | |
| 142 | |
| 143 CString url_req; | |
| 144 std::vector<HelpUrlBuilder::AppResult> app_results; | |
| 145 app_results.push_back(HelpUrlBuilder::AppResult(kAppGuid, 10, 22)); | |
| 146 EXPECT_SUCCEEDED(BuildHttpGetString( | |
| 147 _T("http://www.google.com/hello.py?code=123&"), | |
| 148 app_results, | |
| 149 _T("1.0.51.0"), | |
| 150 true, | |
| 151 _T("en"), | |
| 152 StringToGuid(_T("{0F973A20-C484-462b-952C-5D9A459E3326}")), | |
| 153 _T("GoOG"), | |
| 154 _T("click"), | |
| 155 &url_req)); | |
| 156 | |
| 157 EXPECT_EQ(-1, url_req.FindOneOf(_T("{}"))); | |
| 158 | |
| 159 EXPECT_LE(expected_str_before_os.GetLength(), url_req.GetLength()); | |
| 160 EXPECT_EQ(0, url_req.Find(expected_str_before_os)) << | |
| 161 _T("Expected: ") << expected_str_before_os.GetString() << std::endl << | |
| 162 _T("At beginning of: ") << url_req.GetString(); | |
| 163 int os_fragment_len = 0; | |
| 164 EXPECT_EQ(expected_str_before_os.GetLength(), | |
| 165 VerifyOSInUrl(url_req, &os_fragment_len)) << | |
| 166 _T("Expected OS string not found in: ") << url_req.GetString(); | |
| 167 | |
| 168 EXPECT_EQ(expected_str_before_os.GetLength() + os_fragment_len, | |
| 169 url_req.Find(expected_str_after_os)) << | |
| 170 _T("Expected: ") << expected_str_after_os.GetString() << std::endl << | |
| 171 _T("At end of: ") << url_req.GetString(); | |
| 172 | |
| 173 if (expected_test_source) { | |
| 174 CString expected_testsource_str = | |
| 175 ConfigManager::Instance()->GetTestSource(); | |
| 176 int expected_testsource_start = expected_str_before_os.GetLength() + | |
| 177 os_fragment_len + | |
| 178 expected_str_after_os.GetLength(); | |
| 179 EXPECT_EQ(expected_testsource_start, url_req.Find(expected_testsource_str)); | |
| 180 EXPECT_EQ(expected_testsource_start + expected_testsource_str.GetLength(), | |
| 181 url_req.GetLength()); | |
| 182 } else { | |
| 183 EXPECT_EQ(expected_str_before_os.GetLength() + | |
| 184 os_fragment_len + | |
| 185 expected_str_after_os.GetLength(), | |
| 186 url_req.GetLength()); | |
| 187 | |
| 188 EXPECT_EQ(-1, url_req.Find(_T("testsource"))); | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 TEST_F(HelpUrlBuilderTest, BuildHttpGetString_UserWithTestSource) { | |
| 193 ASSERT_SUCCEEDED(RegKey::SetValue(MACHINE_REG_UPDATE_DEV, | |
| 194 kRegValueTestSource, | |
| 195 _T("dev"))); | |
| 196 | |
| 197 const CString expected_str_before_os( | |
| 198 _T("http://www.google.com/hello.py?hl=de&") | |
| 199 _T("app.0=%7BB7BAF788-9D64-49c3-AFDC-B336AB12F332%7D&") | |
| 200 _T("ec.0=0xffffffff&ex.0=99&") | |
| 201 _T("guver=foo%20bar&m=0&os=")); | |
| 202 const CString expected_str_after_os( | |
| 203 _T("&iid=%7B0F973A20-C484-462B-952C-5D9A459E3326%7D") // Upper case 'B'. | |
| 204 _T("&brand=GGLE&source=clack") | |
| 205 _T("&testsource=")); | |
| 206 | |
| 207 CString url_req; | |
| 208 std::vector<HelpUrlBuilder::AppResult> app_results; | |
| 209 app_results.push_back(HelpUrlBuilder::AppResult(kAppGuid, 0xffffffff, 99)); | |
| 210 EXPECT_SUCCEEDED(BuildHttpGetString( | |
| 211 _T("http://www.google.com/hello.py?"), | |
| 212 app_results, | |
| 213 _T("foo bar"), | |
| 214 false, | |
| 215 _T("de"), | |
| 216 StringToGuid(_T("{0F973A20-C484-462b-952C-5D9A459E3326}")), | |
| 217 _T("GGLE"), | |
| 218 _T("clack"), | |
| 219 &url_req)); | |
| 220 EXPECT_LE(expected_str_before_os.GetLength(), url_req.GetLength()); | |
| 221 EXPECT_EQ(0, url_req.Find(expected_str_before_os)); | |
| 222 | |
| 223 int os_fragment_len = 0; | |
| 224 EXPECT_EQ(expected_str_before_os.GetLength(), | |
| 225 VerifyOSInUrl(url_req, &os_fragment_len)) << | |
| 226 _T("Expected: ") << expected_str_before_os.GetString() << std::endl << | |
| 227 _T("At beginning of: ") << url_req.GetString(); | |
| 228 | |
| 229 EXPECT_EQ(expected_str_before_os.GetLength() + os_fragment_len, | |
| 230 url_req.Find(expected_str_after_os)) << | |
| 231 _T("Expected OS string not found in: ") << url_req.GetString(); | |
| 232 | |
| 233 const CString expected_testsource_str = _T("dev"); | |
| 234 | |
| 235 int expected_testsource_start = expected_str_before_os.GetLength() + | |
| 236 os_fragment_len + | |
| 237 expected_str_after_os.GetLength(); | |
| 238 EXPECT_EQ(expected_testsource_start, url_req.Find(expected_testsource_str)); | |
| 239 EXPECT_EQ(expected_testsource_start + expected_testsource_str.GetLength(), | |
| 240 url_req.GetLength()); | |
| 241 } | |
| 242 | |
| 243 // IID and brand code are emtpy if not present. | |
| 244 TEST_F(HelpUrlBuilderTest, BuildHttpGetString_NoIidOrBrandCode) { | |
| 245 const CString expected_str_before_os( | |
| 246 _T("http://www.google.com/hello.py?hl=en&") | |
| 247 _T("app.0=%7BB7BAF788-9D64-49c3-AFDC-B336AB12F332%7D&") | |
| 248 _T("ec.0=0xffffffff&ex.0=99&") | |
| 249 _T("guver=foo%20bar&m=1&os=")); | |
| 250 const CString expected_str_after_os(_T("&iid=&brand=&source=cluck")); | |
| 251 | |
| 252 CString url_req; | |
| 253 std::vector<HelpUrlBuilder::AppResult> app_results; | |
| 254 app_results.push_back(HelpUrlBuilder::AppResult( | |
| 255 _T("{B7BAF788-9D64-49c3-AFDC-B336AB12F332}"), 0xffffffff, 99)); | |
| 256 EXPECT_SUCCEEDED(BuildHttpGetString( | |
| 257 _T("http://www.google.com/hello.py?"), | |
| 258 app_results, | |
| 259 _T("foo bar"), | |
| 260 true, | |
| 261 _T("en"), | |
| 262 GUID_NULL, | |
| 263 _T(""), | |
| 264 _T("cluck"), | |
| 265 &url_req)); | |
| 266 | |
| 267 EXPECT_EQ(0, url_req.Find(expected_str_before_os)) << | |
| 268 _T("Expected: ") << expected_str_before_os.GetString() << std::endl << | |
| 269 _T("At beginning of: ") << url_req.GetString(); | |
| 270 | |
| 271 EXPECT_LT(0, url_req.Find(expected_str_after_os)); | |
| 272 | |
| 273 CString expected_test_src; | |
| 274 #if defined(DEBUG) || !OFFICIAL_BUILD | |
| 275 expected_test_src = _T("&testsource=auto"); | |
| 276 #endif | |
| 277 const CString expected_iid_str(_T("&iid=&brand=&source=cluck")); | |
| 278 EXPECT_EQ(url_req.GetLength() - | |
| 279 expected_iid_str.GetLength() - | |
| 280 expected_test_src.GetLength(), | |
| 281 url_req.Find(expected_iid_str)); | |
| 282 } | |
| 283 | |
| 284 TEST_F(HelpUrlBuilderTest, BuildHttpGetString_UrlTooLong) { | |
| 285 EXPECT_LT(INTERNET_MAX_URL_LENGTH, arraysize(kStringAlmostTooLongForUrl) + 5); | |
| 286 | |
| 287 ExpectAsserts expect_asserts; // BuildHttpGetString asserts on URL length. | |
| 288 CString url_req; | |
| 289 std::vector<HelpUrlBuilder::AppResult> app_results; | |
| 290 app_results.push_back(HelpUrlBuilder::AppResult( | |
| 291 _T("{B7BAF788-9D64-49c3-AFDC-B336AB12F332}"), 0xffffffff, 99)); | |
| 292 EXPECT_EQ(E_FAIL, BuildHttpGetString( | |
| 293 _T("http://www.google.com/hello.py?"), | |
| 294 app_results, | |
| 295 _T("foo bar"), | |
| 296 true, | |
| 297 _T("en"), | |
| 298 GUID_NULL, | |
| 299 _T(""), | |
| 300 kStringAlmostTooLongForUrl, | |
| 301 &url_req)); | |
| 302 } | |
| 303 | |
| 304 TEST_F(HelpUrlBuilderTest, BuildHttpGetString_MultipleApps) { | |
| 305 CString expected_str_before_os( | |
| 306 _T("http://www.google.com/hello.py?code=123&hl=en&") | |
| 307 _T("app.0=%7BB7BAF788-9D64-49c3-AFDC-B336AB12F332%7D&") | |
| 308 _T("ec.0=0x80000001&ex.0=1000&") | |
| 309 _T("app.1=%7B6D2DF75B-11F0-41CA-9874-79DE4568527C%7D&") | |
| 310 _T("ec.1=0x0&ex.1=0&") | |
| 311 _T("guver=1.0.51.22&m=1&os=")); | |
| 312 CString expected_str_after_os( | |
| 313 _T("&iid=%7B0F973A20-C484-462B-952C-5D9A459E3326%7D") // Upper case 'B'. | |
| 314 _T("&brand=TEST&source=click")); | |
| 315 bool expected_test_source = false; | |
| 316 | |
| 317 #if defined(DEBUG) || !OFFICIAL_BUILD | |
| 318 // TestSource is always set for these builds. It may be set for opt official | |
| 319 // builds but this is not guaranteed. | |
| 320 expected_str_after_os.Append(_T("&testsource=")); | |
| 321 expected_test_source = true; | |
| 322 #endif | |
| 323 | |
| 324 CString url_req; | |
| 325 std::vector<HelpUrlBuilder::AppResult> app_results; | |
| 326 app_results.push_back(HelpUrlBuilder::AppResult(kAppGuid, 0x80000001, 1000)); | |
| 327 app_results.push_back(HelpUrlBuilder::AppResult(kAppGuid2, 0, 0)); | |
| 328 EXPECT_SUCCEEDED(BuildHttpGetString( | |
| 329 _T("http://www.google.com/hello.py?code=123&"), | |
| 330 app_results, | |
| 331 _T("1.0.51.22"), | |
| 332 true, | |
| 333 _T("en"), | |
| 334 StringToGuid(_T("{0F973A20-C484-462b-952C-5D9A459E3326}")), | |
| 335 _T("TEST"), | |
| 336 _T("click"), | |
| 337 &url_req)); | |
| 338 | |
| 339 EXPECT_EQ(-1, url_req.FindOneOf(_T("{}"))); | |
| 340 | |
| 341 EXPECT_LE(expected_str_before_os.GetLength(), url_req.GetLength()); | |
| 342 EXPECT_EQ(0, url_req.Find(expected_str_before_os)) << | |
| 343 _T("Expected: ") << expected_str_before_os.GetString() << std::endl << | |
| 344 _T("At beginning of: ") << url_req.GetString(); | |
| 345 int os_fragment_len = 0; | |
| 346 EXPECT_EQ(expected_str_before_os.GetLength(), | |
| 347 VerifyOSInUrl(url_req, &os_fragment_len)) << | |
| 348 _T("Expected OS string not found in: ") << url_req.GetString(); | |
| 349 | |
| 350 EXPECT_EQ(expected_str_before_os.GetLength() + os_fragment_len, | |
| 351 url_req.Find(expected_str_after_os)) << | |
| 352 _T("Expected: ") << expected_str_after_os.GetString() << std::endl << | |
| 353 _T("At end of: ") << url_req.GetString(); | |
| 354 | |
| 355 if (expected_test_source) { | |
| 356 CString expected_testsource_str = | |
| 357 ConfigManager::Instance()->GetTestSource(); | |
| 358 int expected_testsource_start = expected_str_before_os.GetLength() + | |
| 359 os_fragment_len + | |
| 360 expected_str_after_os.GetLength(); | |
| 361 EXPECT_EQ(expected_testsource_start, url_req.Find(expected_testsource_str)); | |
| 362 EXPECT_EQ(expected_testsource_start + expected_testsource_str.GetLength(), | |
| 363 url_req.GetLength()); | |
| 364 } else { | |
| 365 EXPECT_EQ(expected_str_before_os.GetLength() + | |
| 366 os_fragment_len + | |
| 367 expected_str_after_os.GetLength(), | |
| 368 url_req.GetLength()); | |
| 369 | |
| 370 EXPECT_EQ(-1, url_req.Find(_T("testsource"))); | |
| 371 } | |
| 372 } | |
| 373 | |
| 374 // Machine ID must be set or it will be randomly generated in some cases. | |
| 375 TEST_F(HelpUrlBuilderTest, BuildGetHelpUrl_User) { | |
| 376 // The URL has a begin, middle which is OS-specific and not checked, and end. | |
| 377 const CString kExpetedUrlBegin = | |
| 378 _T("http://www.google.com/support/installer/?hl=en-GB&") | |
| 379 _T("app.0=%7Btest-user-app-id%7D&ec.0=0x80004005&ex.0=-2147418113&") | |
| 380 _T("guver=5.6.7.8&m=0&os="); | |
| 381 const CString kExpectedUrlAfterOs = _T("iid=&brand=&source=gethelp") | |
| 382 #if defined(DEBUG) || !OFFICIAL_BUILD | |
| 383 // TestSource is always set for these builds. | |
| 384 _T("&testsource="); | |
| 385 #else | |
| 386 // TestSource never set for other builds because registry is overridden. | |
| 387 ; // NOLINT | |
| 388 #endif | |
| 389 | |
| 390 CString url; | |
| 391 HelpUrlBuilder url_builder(false, _T("en-GB"), GUID_NULL, _T("")); | |
| 392 std::vector<HelpUrlBuilder::AppResult> app_results; | |
| 393 app_results.push_back( | |
| 394 HelpUrlBuilder::AppResult(_T("{test-user-app-id}"), | |
| 395 E_FAIL, | |
| 396 static_cast<DWORD>(E_UNEXPECTED))); | |
| 397 EXPECT_SUCCEEDED(url_builder.BuildUrl(app_results, &url)); | |
| 398 | |
| 399 EXPECT_STREQ(kExpetedUrlBegin, url.Left(kExpetedUrlBegin.GetLength())); | |
| 400 EXPECT_NE(-1, url.Find(kExpectedUrlAfterOs)) | |
| 401 << kExpectedUrlAfterOs.GetString() << std::endl | |
| 402 << _T(" not found in ") << std::endl << url.GetString(); | |
| 403 } | |
| 404 | |
| 405 TEST_F(HelpUrlBuilderTest, BuildGetHelpUrl_Machine) { | |
| 406 // The URL has a begin, middle which is OS-specific and not checked, and end. | |
| 407 const CString kExpetedUrlBegin = | |
| 408 _T("http://www.google.com/support/installer/?hl=en-GB&") | |
| 409 _T("app.0=%7Btest-machine-app-id%7D&ec.0=0x80004004&ex.0=99&") | |
| 410 _T("guver=5.6.7.8&m=1&os="); | |
| 411 const CString kExpectedUrlAfterOs = | |
| 412 _T("iid=%7B326ADA1D-06AA-4C16-8101-5FC3FEBC852A%7D&") // Upper case 'C'. | |
| 413 _T("brand=GOOG&source=gethelp") | |
| 414 #if defined(DEBUG) || !OFFICIAL_BUILD | |
| 415 // TestSource is always set for these builds. | |
| 416 _T("&testsource="); | |
| 417 #else | |
| 418 // TestSource never set for other builds because registry is overridden. | |
| 419 ; // NOLINT | |
| 420 #endif | |
| 421 | |
| 422 const GUID kIid = StringToGuid(_T("{326ADA1D-06AA-4c16-8101-5FC3FEBC852A}")); | |
| 423 CString url; | |
| 424 HelpUrlBuilder url_builder(true, _T("en-GB"), kIid, _T("GOOG")); | |
| 425 std::vector<HelpUrlBuilder::AppResult> app_results; | |
| 426 app_results.push_back(HelpUrlBuilder::AppResult(_T("{test-machine-app-id}"), | |
| 427 E_ABORT, | |
| 428 99)); | |
| 429 EXPECT_SUCCEEDED(url_builder.BuildUrl(app_results, &url)); | |
| 430 | |
| 431 EXPECT_STREQ(kExpetedUrlBegin, url.Left(kExpetedUrlBegin.GetLength())); | |
| 432 EXPECT_NE(-1, url.Find(kExpectedUrlAfterOs)) | |
| 433 << kExpectedUrlAfterOs.GetString() << std::endl | |
| 434 << _T(" not found in ") << std::endl << url.GetString(); | |
| 435 } | |
| 436 | |
| 437 // Makes BuildHttpGetString fail by making the URL too long. | |
| 438 // The call succeeds, but the url is empty. | |
| 439 TEST_F(HelpUrlBuilderTest, BuildGetHelpUrl_BuildFails) { | |
| 440 EXPECT_LT(INTERNET_MAX_URL_LENGTH, arraysize(kStringAlmostTooLongForUrl) + 5); | |
| 441 | |
| 442 ExpectAsserts expect_asserts; // BuildHttpGetString asserts on URL length. | |
| 443 CString url; | |
| 444 HelpUrlBuilder url_builder(false, _T("en-GB"), GUID_NULL, _T("")); | |
| 445 std::vector<HelpUrlBuilder::AppResult> app_results; | |
| 446 app_results.push_back( | |
| 447 HelpUrlBuilder::AppResult(kStringAlmostTooLongForUrl, | |
| 448 E_FAIL, | |
| 449 static_cast<DWORD>(E_UNEXPECTED))); | |
| 450 EXPECT_EQ(E_FAIL, url_builder.BuildUrl(app_results, &url)); | |
| 451 EXPECT_TRUE(url.IsEmpty()); | |
| 452 } | |
| 453 | |
| 454 } // namespace omaha | |
| OLD | NEW |