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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 " \"inproduct\": \"31/01/10 01:00 GMT\"" | 50 " \"inproduct\": \"31/01/10 01:00 GMT\"" |
51 " }," | 51 " }," |
52 " {" | 52 " {" |
53 " \"name\": \"custom_logo_end\"," | 53 " \"name\": \"custom_logo_end\"," |
54 " \"inproduct\": \"31/01/12 01:00 GMT\"" | 54 " \"inproduct\": \"31/01/12 01:00 GMT\"" |
55 " }" | 55 " }" |
56 " ]" | 56 " ]" |
57 " }" | 57 " }" |
58 "}"; | 58 "}"; |
59 scoped_ptr<DictionaryValue> test_json( | 59 scoped_ptr<DictionaryValue> test_json( |
60 static_cast<DictionaryValue*>(base::JSONReader::Read(json, false))); | 60 static_cast<DictionaryValue*>(base::JSONReader::Read(json))); |
61 | 61 |
62 // Check that prefs are set correctly. | 62 // Check that prefs are set correctly. |
63 web_resource_service_->UnpackLogoSignal(*(test_json.get())); | 63 web_resource_service_->UnpackLogoSignal(*(test_json.get())); |
64 PrefService* prefs = profile_.GetPrefs(); | 64 PrefService* prefs = profile_.GetPrefs(); |
65 ASSERT_TRUE(prefs != NULL); | 65 ASSERT_TRUE(prefs != NULL); |
66 | 66 |
67 double logo_start = | 67 double logo_start = |
68 prefs->GetDouble(prefs::kNtpCustomLogoStart); | 68 prefs->GetDouble(prefs::kNtpCustomLogoStart); |
69 EXPECT_EQ(logo_start, 1264899600); // unix epoch for Jan 31 2010 0100 GMT. | 69 EXPECT_EQ(logo_start, 1264899600); // unix epoch for Jan 31 2010 0100 GMT. |
70 double logo_end = | 70 double logo_end = |
(...skipping 10 matching lines...) Expand all Loading... |
81 " }," | 81 " }," |
82 " {" | 82 " {" |
83 " \"name\": \"custom_logo_end\"," | 83 " \"name\": \"custom_logo_end\"," |
84 " \"inproduct\": \"31/01/12 01:00 GMT\"" | 84 " \"inproduct\": \"31/01/12 01:00 GMT\"" |
85 " }" | 85 " }" |
86 " ]" | 86 " ]" |
87 " }" | 87 " }" |
88 "}"; | 88 "}"; |
89 test_json->Clear(); | 89 test_json->Clear(); |
90 test_json.reset(static_cast<DictionaryValue*>( | 90 test_json.reset(static_cast<DictionaryValue*>( |
91 base::JSONReader::Read(json, false))); | 91 base::JSONReader::Read(json))); |
92 | 92 |
93 // Check that prefs are set correctly. | 93 // Check that prefs are set correctly. |
94 web_resource_service_->UnpackLogoSignal(*(test_json.get())); | 94 web_resource_service_->UnpackLogoSignal(*(test_json.get())); |
95 | 95 |
96 logo_start = prefs->GetDouble(prefs::kNtpCustomLogoStart); | 96 logo_start = prefs->GetDouble(prefs::kNtpCustomLogoStart); |
97 EXPECT_EQ(logo_start, 1267365600); // date changes to Feb 28 2010 1400 GMT. | 97 EXPECT_EQ(logo_start, 1267365600); // date changes to Feb 28 2010 1400 GMT. |
98 | 98 |
99 // If no date is included in the prefs, reset custom logo dates to 0. | 99 // If no date is included in the prefs, reset custom logo dates to 0. |
100 json = "{ " | 100 json = "{ " |
101 " \"topic\": {" | 101 " \"topic\": {" |
102 " \"answers\": [" | 102 " \"answers\": [" |
103 " {" | 103 " {" |
104 " }" | 104 " }" |
105 " ]" | 105 " ]" |
106 " }" | 106 " }" |
107 "}"; | 107 "}"; |
108 test_json->Clear(); | 108 test_json->Clear(); |
109 test_json.reset(static_cast<DictionaryValue*>( | 109 test_json.reset(static_cast<DictionaryValue*>( |
110 base::JSONReader::Read(json, false))); | 110 base::JSONReader::Read(json))); |
111 | 111 |
112 // Check that prefs are set correctly. | 112 // Check that prefs are set correctly. |
113 web_resource_service_->UnpackLogoSignal(*(test_json.get())); | 113 web_resource_service_->UnpackLogoSignal(*(test_json.get())); |
114 logo_start = prefs->GetDouble(prefs::kNtpCustomLogoStart); | 114 logo_start = prefs->GetDouble(prefs::kNtpCustomLogoStart); |
115 EXPECT_EQ(logo_start, 0); // date value reset to 0; | 115 EXPECT_EQ(logo_start, 0); // date value reset to 0; |
116 logo_end = prefs->GetDouble(prefs::kNtpCustomLogoEnd); | 116 logo_end = prefs->GetDouble(prefs::kNtpCustomLogoEnd); |
117 EXPECT_EQ(logo_end, 0); // date value reset to 0; | 117 EXPECT_EQ(logo_end, 0); // date value reset to 0; |
118 } | 118 } |
119 | 119 |
120 class NotificationPromoTestDelegate : public NotificationPromo::Delegate { | 120 class NotificationPromoTestDelegate : public NotificationPromo::Delegate { |
(...skipping 22 matching lines...) Expand all Loading... |
143 void Init(NotificationPromo* notification_promo, | 143 void Init(NotificationPromo* notification_promo, |
144 const std::string& json, | 144 const std::string& json, |
145 double start, double end, | 145 double start, double end, |
146 int build, int time_slice, | 146 int build, int time_slice, |
147 int max_group, int max_views, int platform, | 147 int max_group, int max_views, int platform, |
148 int feature_mask, const std::string& text, bool closed, | 148 int feature_mask, const std::string& text, bool closed, |
149 bool gplus) { | 149 bool gplus) { |
150 notification_promo_ = notification_promo; | 150 notification_promo_ = notification_promo; |
151 | 151 |
152 test_json_.reset(static_cast<DictionaryValue*>( | 152 test_json_.reset(static_cast<DictionaryValue*>( |
153 base::JSONReader::Read(json, false))); | 153 base::JSONReader::Read(json))); |
154 | 154 |
155 start_ = start; | 155 start_ = start; |
156 end_ = end; | 156 end_ = end; |
157 | 157 |
158 build_ = build; | 158 build_ = build; |
159 time_slice_ = time_slice; | 159 time_slice_ = time_slice; |
160 max_group_ = max_group; | 160 max_group_ = max_group; |
161 max_views_ = max_views; | 161 max_views_ = max_views; |
162 platform_ = platform; | 162 platform_ = platform; |
163 | 163 |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 " \"name\": \"webstore_promo:15:1:\"," | 689 " \"name\": \"webstore_promo:15:1:\"," |
690 " \"question\": \"The header!\"," | 690 " \"question\": \"The header!\"," |
691 " \"inproduct_target\": \"The button label!\"," | 691 " \"inproduct_target\": \"The button label!\"," |
692 " \"inproduct\": \"http://link.com\"," | 692 " \"inproduct\": \"http://link.com\"," |
693 " \"tooltip\": \"No thanks, hide this.\"" | 693 " \"tooltip\": \"No thanks, hide this.\"" |
694 " }" | 694 " }" |
695 " ]" | 695 " ]" |
696 " }" | 696 " }" |
697 "}"; | 697 "}"; |
698 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( | 698 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
699 base::JSONReader::Read(json, false))); | 699 base::JSONReader::Read(json))); |
700 | 700 |
701 // Set the source logo URL to verify that it gets cleared. | 701 // Set the source logo URL to verify that it gets cleared. |
702 AppsPromo::SetSourcePromoLogoURL(GURL("https://www.google.com/test.png")); | 702 AppsPromo::SetSourcePromoLogoURL(GURL("https://www.google.com/test.png")); |
703 | 703 |
704 // Check that prefs are set correctly. | 704 // Check that prefs are set correctly. |
705 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); | 705 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
706 | 706 |
707 AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); | 707 AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); |
708 EXPECT_EQ("341252", actual_data.id); | 708 EXPECT_EQ("341252", actual_data.id); |
709 EXPECT_EQ("The header!", actual_data.header); | 709 EXPECT_EQ("The header!", actual_data.header); |
(...skipping 15 matching lines...) Expand all Loading... |
725 " \"topic\": {" | 725 " \"topic\": {" |
726 " \"answers\": [" | 726 " \"answers\": [" |
727 " {" | 727 " {" |
728 " \"answer_id\": \"sdlfj32\"," | 728 " \"answer_id\": \"sdlfj32\"," |
729 " \"name\": \"webstore_promo:#klsdjlfSD\"" | 729 " \"name\": \"webstore_promo:#klsdjlfSD\"" |
730 " }" | 730 " }" |
731 " ]" | 731 " ]" |
732 " }" | 732 " }" |
733 "}"; | 733 "}"; |
734 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( | 734 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
735 base::JSONReader::Read(json, false))); | 735 base::JSONReader::Read(json))); |
736 | 736 |
737 // Check that prefs are set correctly. | 737 // Check that prefs are set correctly. |
738 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); | 738 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
739 EXPECT_FALSE(AppsPromo::IsPromoSupportedForLocale()); | 739 EXPECT_FALSE(AppsPromo::IsPromoSupportedForLocale()); |
740 EXPECT_TRUE(AppsPromo::IsWebStoreSupportedForLocale()); | 740 EXPECT_TRUE(AppsPromo::IsWebStoreSupportedForLocale()); |
741 } | 741 } |
742 | 742 |
743 // Tests that we can successfully unpack web store signals with HTTPS | 743 // Tests that we can successfully unpack web store signals with HTTPS |
744 // logos. | 744 // logos. |
745 TEST_F(PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo) { | 745 TEST_F(PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo) { |
(...skipping 16 matching lines...) Expand all Loading... |
762 " \"question\": \"Header!\"," | 762 " \"question\": \"Header!\"," |
763 " \"inproduct_target\": \"The button label!\"," | 763 " \"inproduct_target\": \"The button label!\"," |
764 " \"inproduct\": \"http://link.com\"," | 764 " \"inproduct\": \"http://link.com\"," |
765 " \"tooltip\": \"No thanks, hide this.\"" | 765 " \"tooltip\": \"No thanks, hide this.\"" |
766 " }" | 766 " }" |
767 " ]" | 767 " ]" |
768 " }" | 768 " }" |
769 "}"; | 769 "}"; |
770 | 770 |
771 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( | 771 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
772 base::JSONReader::Read(json, false))); | 772 base::JSONReader::Read(json))); |
773 | 773 |
774 // Update the promo multiple times to verify the logo is cached correctly. | 774 // Update the promo multiple times to verify the logo is cached correctly. |
775 for (size_t i = 0; i < 2; ++i) { | 775 for (size_t i = 0; i < 2; ++i) { |
776 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); | 776 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
777 | 777 |
778 // We should only need to run the message loop the first time since the | 778 // We should only need to run the message loop the first time since the |
779 // image is then cached. | 779 // image is then cached. |
780 if (i == 0) | 780 if (i == 0) |
781 loop_.RunAllPending(); | 781 loop_.RunAllPending(); |
782 | 782 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 " \"question\": \"Header!\"," | 822 " \"question\": \"Header!\"," |
823 " \"inproduct_target\": \"The button label!\"," | 823 " \"inproduct_target\": \"The button label!\"," |
824 " \"inproduct\": \"http://link.com\"," | 824 " \"inproduct\": \"http://link.com\"," |
825 " \"tooltip\": \"No thanks, hide this.\"" | 825 " \"tooltip\": \"No thanks, hide this.\"" |
826 " }" | 826 " }" |
827 " ]" | 827 " ]" |
828 " }" | 828 " }" |
829 "}"; | 829 "}"; |
830 | 830 |
831 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( | 831 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
832 base::JSONReader::Read(json, false))); | 832 base::JSONReader::Read(json))); |
833 | 833 |
834 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); | 834 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
835 | 835 |
836 loop_.RunAllPending(); | 836 loop_.RunAllPending(); |
837 | 837 |
838 // Reset this scoped_ptr to prevent a DCHECK. | 838 // Reset this scoped_ptr to prevent a DCHECK. |
839 web_resource_service_->apps_promo_logo_fetcher_.reset(); | 839 web_resource_service_->apps_promo_logo_fetcher_.reset(); |
840 | 840 |
841 AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); | 841 AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); |
842 EXPECT_EQ("340252", actual_data.id); | 842 EXPECT_EQ("340252", actual_data.id); |
(...skipping 30 matching lines...) Expand all Loading... |
873 " \"question\": \"Header!\"," | 873 " \"question\": \"Header!\"," |
874 " \"inproduct_target\": \"The button label!\"," | 874 " \"inproduct_target\": \"The button label!\"," |
875 " \"inproduct\": \"http://link.com\"," | 875 " \"inproduct\": \"http://link.com\"," |
876 " \"tooltip\": \"No thanks, hide this.\"" | 876 " \"tooltip\": \"No thanks, hide this.\"" |
877 " }" | 877 " }" |
878 " ]" | 878 " ]" |
879 " }" | 879 " }" |
880 "}"; | 880 "}"; |
881 | 881 |
882 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( | 882 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
883 base::JSONReader::Read(json, false))); | 883 base::JSONReader::Read(json))); |
884 | 884 |
885 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); | 885 web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
886 | 886 |
887 loop_.RunAllPending(); | 887 loop_.RunAllPending(); |
888 | 888 |
889 // Reset this scoped_ptr to prevent a DCHECK. | 889 // Reset this scoped_ptr to prevent a DCHECK. |
890 web_resource_service_->apps_promo_logo_fetcher_.reset(); | 890 web_resource_service_->apps_promo_logo_fetcher_.reset(); |
891 | 891 |
892 AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); | 892 AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); |
893 EXPECT_EQ("340252", actual_data.id); | 893 EXPECT_EQ("340252", actual_data.id); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); | 941 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); |
942 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); | 942 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); |
943 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); | 943 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); |
944 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); | 944 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); |
945 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); | 945 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); |
946 | 946 |
947 // invalid | 947 // invalid |
948 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1)); | 948 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, -1)); |
949 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX)); | 949 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, INT_MAX)); |
950 } | 950 } |
OLD | NEW |