| 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/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "chrome/browser/metrics/proto/study.pb.h" | 10 #include "chrome/browser/metrics/proto/study.pb.h" |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 ASSERT_TRUE(valid); | 583 ASSERT_TRUE(valid); |
| 584 Study_Experiment* repeated_group = study.add_experiment(); | 584 Study_Experiment* repeated_group = study.add_experiment(); |
| 585 repeated_group->set_name("abc"); | 585 repeated_group->set_name("abc"); |
| 586 repeated_group->set_probability_weight(1); | 586 repeated_group->set_probability_weight(1); |
| 587 valid = VariationsService::ValidateStudyAndComputeTotalProbability(study, | 587 valid = VariationsService::ValidateStudyAndComputeTotalProbability(study, |
| 588 &total_probability); | 588 &total_probability); |
| 589 EXPECT_FALSE(valid); | 589 EXPECT_FALSE(valid); |
| 590 } | 590 } |
| 591 | 591 |
| 592 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { | 592 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { |
| 593 MessageLoopForUI message_loop; | 593 base::MessageLoopForUI message_loop; |
| 594 content::TestBrowserThread ui_thread(content::BrowserThread::UI, | 594 content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
| 595 &message_loop); | 595 &message_loop); |
| 596 TestingPrefServiceSimple prefs; | 596 TestingPrefServiceSimple prefs; |
| 597 VariationsService::RegisterPrefs(prefs.registry()); | 597 VariationsService::RegisterPrefs(prefs.registry()); |
| 598 | 598 |
| 599 // Pass ownership to TestVariationsService, but keep a weak pointer to | 599 // Pass ownership to TestVariationsService, but keep a weak pointer to |
| 600 // manipulate it for this test. | 600 // manipulate it for this test. |
| 601 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; | 601 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; |
| 602 TestVariationsService test_service(test_notifier, &prefs); | 602 TestVariationsService test_service(test_notifier, &prefs); |
| 603 | 603 |
| 604 // Force the notifier to initially disallow requests. | 604 // Force the notifier to initially disallow requests. |
| 605 test_notifier->SetRequestsAllowedOverride(false); | 605 test_notifier->SetRequestsAllowedOverride(false); |
| 606 test_service.StartRepeatedVariationsSeedFetch(); | 606 test_service.StartRepeatedVariationsSeedFetch(); |
| 607 EXPECT_FALSE(test_service.fetch_attempted()); | 607 EXPECT_FALSE(test_service.fetch_attempted()); |
| 608 | 608 |
| 609 test_notifier->NotifyObserver(); | 609 test_notifier->NotifyObserver(); |
| 610 EXPECT_TRUE(test_service.fetch_attempted()); | 610 EXPECT_TRUE(test_service.fetch_attempted()); |
| 611 } | 611 } |
| 612 | 612 |
| 613 TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) { | 613 TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) { |
| 614 MessageLoopForUI message_loop; | 614 base::MessageLoopForUI message_loop; |
| 615 content::TestBrowserThread ui_thread(content::BrowserThread::UI, | 615 content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
| 616 &message_loop); | 616 &message_loop); |
| 617 TestingPrefServiceSimple prefs; | 617 TestingPrefServiceSimple prefs; |
| 618 VariationsService::RegisterPrefs(prefs.registry()); | 618 VariationsService::RegisterPrefs(prefs.registry()); |
| 619 | 619 |
| 620 // Pass ownership to TestVariationsService, but keep a weak pointer to | 620 // Pass ownership to TestVariationsService, but keep a weak pointer to |
| 621 // manipulate it for this test. | 621 // manipulate it for this test. |
| 622 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; | 622 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; |
| 623 TestVariationsService test_service(test_notifier, &prefs); | 623 TestVariationsService test_service(test_notifier, &prefs); |
| 624 | 624 |
| 625 test_notifier->SetRequestsAllowedOverride(true); | 625 test_notifier->SetRequestsAllowedOverride(true); |
| 626 test_service.StartRepeatedVariationsSeedFetch(); | 626 test_service.StartRepeatedVariationsSeedFetch(); |
| 627 EXPECT_TRUE(test_service.fetch_attempted()); | 627 EXPECT_TRUE(test_service.fetch_attempted()); |
| 628 } | 628 } |
| 629 | 629 |
| 630 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) { | 630 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) { |
| 631 MessageLoop message_loop; | 631 base::MessageLoop message_loop; |
| 632 content::TestBrowserThread io_thread(content::BrowserThread::IO, | 632 content::TestBrowserThread io_thread(content::BrowserThread::IO, |
| 633 &message_loop); | 633 &message_loop); |
| 634 TestingPrefServiceSimple prefs; | 634 TestingPrefServiceSimple prefs; |
| 635 VariationsService::RegisterPrefs(prefs.registry()); | 635 VariationsService::RegisterPrefs(prefs.registry()); |
| 636 | 636 |
| 637 VariationsService variations_service(new TestRequestAllowedNotifier, &prefs); | 637 VariationsService variations_service(new TestRequestAllowedNotifier, &prefs); |
| 638 | 638 |
| 639 net::TestURLFetcherFactory factory; | 639 net::TestURLFetcherFactory factory; |
| 640 variations_service.DoActualFetch(); | 640 variations_service.DoActualFetch(); |
| 641 | 641 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 652 | 652 |
| 653 TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) { | 653 TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) { |
| 654 const int non_ok_status_codes[] = { | 654 const int non_ok_status_codes[] = { |
| 655 net::HTTP_NO_CONTENT, | 655 net::HTTP_NO_CONTENT, |
| 656 net::HTTP_NOT_MODIFIED, | 656 net::HTTP_NOT_MODIFIED, |
| 657 net::HTTP_NOT_FOUND, | 657 net::HTTP_NOT_FOUND, |
| 658 net::HTTP_INTERNAL_SERVER_ERROR, | 658 net::HTTP_INTERNAL_SERVER_ERROR, |
| 659 net::HTTP_SERVICE_UNAVAILABLE, | 659 net::HTTP_SERVICE_UNAVAILABLE, |
| 660 }; | 660 }; |
| 661 | 661 |
| 662 MessageLoop message_loop; | 662 base::MessageLoop message_loop; |
| 663 content::TestBrowserThread io_thread(content::BrowserThread::IO, | 663 content::TestBrowserThread io_thread(content::BrowserThread::IO, |
| 664 &message_loop); | 664 &message_loop); |
| 665 TestingPrefServiceSimple prefs; | 665 TestingPrefServiceSimple prefs; |
| 666 VariationsService::RegisterPrefs(prefs.registry()); | 666 VariationsService::RegisterPrefs(prefs.registry()); |
| 667 | 667 |
| 668 VariationsService variations_service(new TestRequestAllowedNotifier, &prefs); | 668 VariationsService variations_service(new TestRequestAllowedNotifier, &prefs); |
| 669 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { | 669 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { |
| 670 net::TestURLFetcherFactory factory; | 670 net::TestURLFetcherFactory factory; |
| 671 variations_service.DoActualFetch(); | 671 variations_service.DoActualFetch(); |
| 672 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 672 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); |
| 673 | 673 |
| 674 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 674 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 675 SimulateServerResponse(non_ok_status_codes[i], fetcher); | 675 SimulateServerResponse(non_ok_status_codes[i], fetcher); |
| 676 variations_service.OnURLFetchComplete(fetcher); | 676 variations_service.OnURLFetchComplete(fetcher); |
| 677 | 677 |
| 678 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 678 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); |
| 679 } | 679 } |
| 680 } | 680 } |
| 681 | 681 |
| 682 } // namespace chrome_variations | 682 } // namespace chrome_variations |
| OLD | NEW |