| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // A test application for the RLZ library. | 5 // A test application for the RLZ library. |
| 6 // | 6 // |
| 7 // These tests should not be executed on the build server: | 7 // These tests should not be executed on the build server: |
| 8 // - They assert for the failed cases. | 8 // - They assert for the failed cases. |
| 9 // - They modify machine state (registry). | 9 // - They modify machine state (registry). |
| 10 // | 10 // |
| 11 // These tests require write access to HKLM and HKCU. | 11 // These tests require write access to HKLM and HKCU. |
| 12 // | 12 // |
| 13 // The "GGLA" brand is used to test the normal code flow of the code, and the | 13 // The "GGLA" brand is used to test the normal code flow of the code, and the |
| 14 // "TEST" brand is used to test the supplementary brand code code flow. | 14 // "TEST" brand is used to test the supplementary brand code code flow. |
| 15 | 15 |
| 16 #include "base/posix/eintr_wrapper.h" | 16 #include "base/posix/eintr_wrapper.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 #include "rlz/lib/financial_ping.h" |
| 22 #include "rlz/lib/rlz_lib.h" | 23 #include "rlz/lib/rlz_lib.h" |
| 23 #include "rlz/lib/rlz_value_store.h" | 24 #include "rlz/lib/rlz_value_store.h" |
| 24 #include "rlz/test/rlz_test_helpers.h" | 25 #include "rlz/test/rlz_test_helpers.h" |
| 25 | 26 |
| 26 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 27 #include <Windows.h> | 28 #include <Windows.h> |
| 28 #include "rlz/win/lib/machine_deal.h" | 29 #include "rlz/win/lib/machine_deal.h" |
| 29 #endif | 30 #endif |
| 30 | 31 |
| 31 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) | 32 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // calling it, trying to record a stateful again should result in it being | 410 // calling it, trying to record a stateful again should result in it being |
| 410 // recorded again. | 411 // recorded again. |
| 411 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | 412 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); |
| 412 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 413 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
| 413 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | 414 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); |
| 414 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, | 415 EXPECT_TRUE(rlz_lib::GetProductEventsAsCgi(rlz_lib::TOOLBAR_NOTIFIER, |
| 415 value, 50)); | 416 value, 50)); |
| 416 EXPECT_STREQ("events=W1I", value); | 417 EXPECT_STREQ("events=W1I", value); |
| 417 } | 418 } |
| 418 | 419 |
| 420 class URLRequestRAII { |
| 421 public: |
| 422 URLRequestRAII(net::URLRequestContextGetter* context) { |
| 423 rlz_lib::SetURLRequestContext(context); |
| 424 } |
| 425 ~URLRequestRAII() { |
| 426 rlz_lib::SetURLRequestContext(NULL); |
| 427 } |
| 428 }; |
| 429 |
| 419 TEST_F(RlzLibTest, SendFinancialPing) { | 430 TEST_F(RlzLibTest, SendFinancialPing) { |
| 420 // We don't really check a value or result in this test. All this does is | 431 // We don't really check a value or result in this test. All this does is |
| 421 // attempt to ping the financial server, which you can verify in Fiddler. | 432 // attempt to ping the financial server, which you can verify in Fiddler. |
| 422 // TODO: Make this a measurable test. | 433 // TODO: Make this a measurable test. |
| 423 | 434 |
| 424 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) | 435 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) |
| 425 #if defined(OS_MACOSX) | 436 #if defined(OS_MACOSX) |
| 426 base::mac::ScopedNSAutoreleasePool pool; | 437 base::mac::ScopedNSAutoreleasePool pool; |
| 427 #endif | 438 #endif |
| 428 | 439 |
| 429 base::Thread::Options options; | 440 base::Thread::Options options; |
| 430 options.message_loop_type = base::MessageLoop::TYPE_IO; | 441 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 431 | 442 |
| 432 base::Thread io_thread("rlz_unittest_io_thread"); | 443 base::Thread io_thread("rlz_unittest_io_thread"); |
| 433 ASSERT_TRUE(io_thread.StartWithOptions(options)); | 444 ASSERT_TRUE(io_thread.StartWithOptions(options)); |
| 434 | 445 |
| 435 scoped_refptr<net::TestURLRequestContextGetter> context = | 446 scoped_refptr<net::TestURLRequestContextGetter> context = |
| 436 new net::TestURLRequestContextGetter( | 447 new net::TestURLRequestContextGetter( |
| 437 io_thread.message_loop()->message_loop_proxy()); | 448 io_thread.message_loop()->message_loop_proxy()); |
| 438 rlz_lib::SetURLRequestContext(context.get()); | 449 rlz_lib::SetURLRequestContext(context.get()); |
| 439 | 450 |
| 440 class URLRequestRAII { | |
| 441 public: | |
| 442 URLRequestRAII(net::URLRequestContextGetter* context) { | |
| 443 rlz_lib::SetURLRequestContext(context); | |
| 444 } | |
| 445 ~URLRequestRAII() { | |
| 446 rlz_lib::SetURLRequestContext(NULL); | |
| 447 } | |
| 448 }; | |
| 449 | |
| 450 URLRequestRAII set_context(context.get()); | 451 URLRequestRAII set_context(context.get()); |
| 451 #endif | 452 #endif |
| 452 | 453 |
| 453 MachineDealCodeHelper::Clear(); | 454 MachineDealCodeHelper::Clear(); |
| 454 #if defined(OS_WIN) | 455 #if defined(OS_WIN) |
| 455 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value")); | 456 EXPECT_TRUE(rlz_lib::MachineDealCode::Set("dcc_value")); |
| 456 #endif | 457 #endif |
| 457 | 458 |
| 458 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, | 459 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, |
| 459 "TbRlzValue")); | 460 "TbRlzValue")); |
| 460 | 461 |
| 461 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | 462 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); |
| 462 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 463 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
| 463 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | 464 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); |
| 464 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 465 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
| 465 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); | 466 rlz_lib::IE_HOME_PAGE, rlz_lib::INSTALL)); |
| 466 | 467 |
| 467 rlz_lib::AccessPoint points[] = | 468 rlz_lib::AccessPoint points[] = |
| 468 {rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT, | 469 {rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT, |
| 469 rlz_lib::NO_ACCESS_POINT}; | 470 rlz_lib::NO_ACCESS_POINT}; |
| 470 | 471 |
| 471 std::string request; | 472 std::string request; |
| 472 rlz_lib::SendFinancialPing(rlz_lib::TOOLBAR_NOTIFIER, points, | 473 rlz_lib::SendFinancialPing(rlz_lib::TOOLBAR_NOTIFIER, points, |
| 473 "swg", "GGLA", "SwgProductId1234", "en-UK", false, | 474 "swg", "GGLA", "SwgProductId1234", "en-UK", false, |
| 474 /*skip_time_check=*/true); | 475 /*skip_time_check=*/true); |
| 475 } | 476 } |
| 476 | 477 |
| 478 #if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET) |
| 479 |
| 480 void ResetContext() { |
| 481 rlz_lib::SetURLRequestContext(NULL); |
| 482 } |
| 483 |
| 484 TEST_F(RlzLibTest, SendFinancialPingDuringShutdown) { |
| 485 // rlz_lib::SendFinancialPing fails when this is set. |
| 486 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) |
| 487 return; |
| 488 |
| 489 #if defined(OS_MACOSX) |
| 490 base::mac::ScopedNSAutoreleasePool pool; |
| 491 #endif |
| 492 |
| 493 base::Thread::Options options; |
| 494 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 495 |
| 496 base::Thread io_thread("rlz_unittest_io_thread"); |
| 497 ASSERT_TRUE(io_thread.StartWithOptions(options)); |
| 498 |
| 499 scoped_refptr<net::TestURLRequestContextGetter> context = |
| 500 new net::TestURLRequestContextGetter( |
| 501 io_thread.message_loop()->message_loop_proxy()); |
| 502 rlz_lib::SetURLRequestContext(context.get()); |
| 503 |
| 504 URLRequestRAII set_context(context.get()); |
| 505 |
| 506 rlz_lib::AccessPoint points[] = |
| 507 {rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT, |
| 508 rlz_lib::NO_ACCESS_POINT}; |
| 509 rlz_lib::test::ResetSendFinancialPingInterrupted(); |
| 510 EXPECT_FALSE(rlz_lib::test::WasSendFinancialPingInterrupted()); |
| 511 |
| 512 base::MessageLoop loop; |
| 513 loop.PostTask(FROM_HERE, base::Bind(&ResetContext)); |
| 514 std::string request; |
| 515 EXPECT_FALSE(rlz_lib::SendFinancialPing(rlz_lib::TOOLBAR_NOTIFIER, points, |
| 516 "swg", "GGLA", "SwgProductId1234", "en-UK", false, |
| 517 /*skip_time_check=*/true)); |
| 518 |
| 519 EXPECT_TRUE(rlz_lib::test::WasSendFinancialPingInterrupted()); |
| 520 rlz_lib::test::ResetSendFinancialPingInterrupted(); |
| 521 } |
| 522 #endif |
| 523 |
| 477 TEST_F(RlzLibTest, ClearProductState) { | 524 TEST_F(RlzLibTest, ClearProductState) { |
| 478 MachineDealCodeHelper::Clear(); | 525 MachineDealCodeHelper::Clear(); |
| 479 | 526 |
| 480 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, | 527 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::IETB_SEARCH_BOX, |
| 481 "TbRlzValue")); | 528 "TbRlzValue")); |
| 482 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::GD_DESKBAND, | 529 EXPECT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::GD_DESKBAND, |
| 483 "GdbRlzValue")); | 530 "GdbRlzValue")); |
| 484 | 531 |
| 485 rlz_lib::AccessPoint points[] = | 532 rlz_lib::AccessPoint points[] = |
| 486 { rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT }; | 533 { rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT }; |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 int mkdir_result = mkdir(rlz_lib::testing::RlzStoreFilenameStr().c_str(), | 930 int mkdir_result = mkdir(rlz_lib::testing::RlzStoreFilenameStr().c_str(), |
| 884 0500); | 931 0500); |
| 885 ASSERT_EQ(0, mkdir_result); | 932 ASSERT_EQ(0, mkdir_result); |
| 886 | 933 |
| 887 rlz_lib::SupplementaryBranding branding("TEST"); | 934 rlz_lib::SupplementaryBranding branding("TEST"); |
| 888 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 935 EXPECT_FALSE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
| 889 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL)); | 936 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::INSTALL)); |
| 890 } | 937 } |
| 891 | 938 |
| 892 #endif | 939 #endif |
| OLD | NEW |