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 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 ASSERT_TRUE(valid); | 647 ASSERT_TRUE(valid); |
648 Study_Experiment* repeated_group = study.add_experiment(); | 648 Study_Experiment* repeated_group = study.add_experiment(); |
649 repeated_group->set_name("abc"); | 649 repeated_group->set_name("abc"); |
650 repeated_group->set_probability_weight(1); | 650 repeated_group->set_probability_weight(1); |
651 valid = VariationsService::ValidateStudyAndComputeTotalProbability(study, | 651 valid = VariationsService::ValidateStudyAndComputeTotalProbability(study, |
652 &total_probability); | 652 &total_probability); |
653 EXPECT_FALSE(valid); | 653 EXPECT_FALSE(valid); |
654 } | 654 } |
655 | 655 |
656 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { | 656 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { |
657 MessageLoopForUI message_loop; | 657 base::MessageLoopForUI message_loop; |
658 content::TestBrowserThread ui_thread(content::BrowserThread::UI, | 658 content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
659 &message_loop); | 659 &message_loop); |
660 TestingPrefServiceSimple prefs; | 660 TestingPrefServiceSimple prefs; |
661 VariationsService::RegisterPrefs(prefs.registry()); | 661 VariationsService::RegisterPrefs(prefs.registry()); |
662 | 662 |
663 // Pass ownership to TestVariationsService, but keep a weak pointer to | 663 // Pass ownership to TestVariationsService, but keep a weak pointer to |
664 // manipulate it for this test. | 664 // manipulate it for this test. |
665 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; | 665 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; |
666 TestVariationsService test_service(test_notifier, &prefs); | 666 TestVariationsService test_service(test_notifier, &prefs); |
667 | 667 |
668 // Force the notifier to initially disallow requests. | 668 // Force the notifier to initially disallow requests. |
669 test_notifier->SetRequestsAllowedOverride(false); | 669 test_notifier->SetRequestsAllowedOverride(false); |
670 test_service.StartRepeatedVariationsSeedFetch(); | 670 test_service.StartRepeatedVariationsSeedFetch(); |
671 EXPECT_FALSE(test_service.fetch_attempted()); | 671 EXPECT_FALSE(test_service.fetch_attempted()); |
672 | 672 |
673 test_notifier->NotifyObserver(); | 673 test_notifier->NotifyObserver(); |
674 EXPECT_TRUE(test_service.fetch_attempted()); | 674 EXPECT_TRUE(test_service.fetch_attempted()); |
675 } | 675 } |
676 | 676 |
677 TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) { | 677 TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) { |
678 MessageLoopForUI message_loop; | 678 base::MessageLoopForUI message_loop; |
679 content::TestBrowserThread ui_thread(content::BrowserThread::UI, | 679 content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
680 &message_loop); | 680 &message_loop); |
681 TestingPrefServiceSimple prefs; | 681 TestingPrefServiceSimple prefs; |
682 VariationsService::RegisterPrefs(prefs.registry()); | 682 VariationsService::RegisterPrefs(prefs.registry()); |
683 | 683 |
684 // Pass ownership to TestVariationsService, but keep a weak pointer to | 684 // Pass ownership to TestVariationsService, but keep a weak pointer to |
685 // manipulate it for this test. | 685 // manipulate it for this test. |
686 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; | 686 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; |
687 TestVariationsService test_service(test_notifier, &prefs); | 687 TestVariationsService test_service(test_notifier, &prefs); |
688 | 688 |
689 test_notifier->SetRequestsAllowedOverride(true); | 689 test_notifier->SetRequestsAllowedOverride(true); |
690 test_service.StartRepeatedVariationsSeedFetch(); | 690 test_service.StartRepeatedVariationsSeedFetch(); |
691 EXPECT_TRUE(test_service.fetch_attempted()); | 691 EXPECT_TRUE(test_service.fetch_attempted()); |
692 } | 692 } |
693 | 693 |
694 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) { | 694 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) { |
695 MessageLoop message_loop; | 695 base::MessageLoop message_loop; |
696 content::TestBrowserThread io_thread(content::BrowserThread::IO, | 696 content::TestBrowserThread io_thread(content::BrowserThread::IO, |
697 &message_loop); | 697 &message_loop); |
698 TestingPrefServiceSimple prefs; | 698 TestingPrefServiceSimple prefs; |
699 VariationsService::RegisterPrefs(prefs.registry()); | 699 VariationsService::RegisterPrefs(prefs.registry()); |
700 | 700 |
701 VariationsService variations_service(new TestRequestAllowedNotifier, &prefs); | 701 VariationsService variations_service(new TestRequestAllowedNotifier, &prefs); |
702 | 702 |
703 net::TestURLFetcherFactory factory; | 703 net::TestURLFetcherFactory factory; |
704 variations_service.DoActualFetch(); | 704 variations_service.DoActualFetch(); |
705 | 705 |
(...skipping 10 matching lines...) Expand all Loading... |
716 | 716 |
717 TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) { | 717 TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) { |
718 const int non_ok_status_codes[] = { | 718 const int non_ok_status_codes[] = { |
719 net::HTTP_NO_CONTENT, | 719 net::HTTP_NO_CONTENT, |
720 net::HTTP_NOT_MODIFIED, | 720 net::HTTP_NOT_MODIFIED, |
721 net::HTTP_NOT_FOUND, | 721 net::HTTP_NOT_FOUND, |
722 net::HTTP_INTERNAL_SERVER_ERROR, | 722 net::HTTP_INTERNAL_SERVER_ERROR, |
723 net::HTTP_SERVICE_UNAVAILABLE, | 723 net::HTTP_SERVICE_UNAVAILABLE, |
724 }; | 724 }; |
725 | 725 |
726 MessageLoop message_loop; | 726 base::MessageLoop message_loop; |
727 content::TestBrowserThread io_thread(content::BrowserThread::IO, | 727 content::TestBrowserThread io_thread(content::BrowserThread::IO, |
728 &message_loop); | 728 &message_loop); |
729 TestingPrefServiceSimple prefs; | 729 TestingPrefServiceSimple prefs; |
730 VariationsService::RegisterPrefs(prefs.registry()); | 730 VariationsService::RegisterPrefs(prefs.registry()); |
731 | 731 |
732 VariationsService variations_service(new TestRequestAllowedNotifier, &prefs); | 732 VariationsService variations_service(new TestRequestAllowedNotifier, &prefs); |
733 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { | 733 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { |
734 net::TestURLFetcherFactory factory; | 734 net::TestURLFetcherFactory factory; |
735 variations_service.DoActualFetch(); | 735 variations_service.DoActualFetch(); |
736 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 736 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 // The two flag groups are given high probability, which would normaly make | 801 // The two flag groups are given high probability, which would normaly make |
802 // them very likely to be choosen. They won't be chosen since flag groups are | 802 // them very likely to be choosen. They won't be chosen since flag groups are |
803 // never chosen when their flag isn't preasent. | 803 // never chosen when their flag isn't preasent. |
804 Study study = CreateStudyWithFlagGroups(1, 999, 999); | 804 Study study = CreateStudyWithFlagGroups(1, 999, 999); |
805 variations_service.CreateTrialFromStudy(study, kReferenceTime); | 805 variations_service.CreateTrialFromStudy(study, kReferenceTime); |
806 EXPECT_EQ(kNonFlagGroupName, | 806 EXPECT_EQ(kNonFlagGroupName, |
807 base::FieldTrialList::FindFullName(kFlagStudyName)); | 807 base::FieldTrialList::FindFullName(kFlagStudyName)); |
808 } | 808 } |
809 | 809 |
810 } // namespace chrome_variations | 810 } // namespace chrome_variations |
OLD | NEW |