OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/time.h" | 6 #include "base/time.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/web_resource/web_resource_service.h" | 10 #include "chrome/browser/web_resource/web_resource_service.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 base::JSONReader::Read(json, false))); | 87 base::JSONReader::Read(json, false))); |
88 | 88 |
89 // Check that prefs are set correctly. | 89 // Check that prefs are set correctly. |
90 web_resource_service->UnpackLogoSignal(*(test_json.get())); | 90 web_resource_service->UnpackLogoSignal(*(test_json.get())); |
91 logo_start = profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoStart); | 91 logo_start = profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoStart); |
92 ASSERT_EQ(logo_start, 0); // date value reset to 0; | 92 ASSERT_EQ(logo_start, 0); // date value reset to 0; |
93 logo_end = profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoEnd); | 93 logo_end = profile.GetPrefs()->GetReal(prefs::kNTPCustomLogoEnd); |
94 ASSERT_EQ(logo_end, 0); // date value reset to 0; | 94 ASSERT_EQ(logo_end, 0); // date value reset to 0; |
95 } | 95 } |
96 | 96 |
| 97 TEST_F(WebResourceServiceTest, UnpackPromoSignal) { |
| 98 // Set up a testing profile and create a web resource service. |
| 99 TestingProfile profile; |
| 100 scoped_refptr<WebResourceService> web_resource_service( |
| 101 new WebResourceService(&profile)); |
| 102 |
| 103 // Set up start and end dates and promo line in a Dictionary as if parsed |
| 104 // from the service. |
| 105 std::string json = "{ " |
| 106 " \"topic\": {" |
| 107 " \"answers\": [" |
| 108 " {" |
| 109 " \"name\": \"promo_start\"," |
| 110 " \"tooltip\": \"Eat more pie!\"," |
| 111 " \"inproduct\": \"31/01/10 01:00 GMT\"" |
| 112 " }," |
| 113 " {" |
| 114 " \"name\": \"promo_end\"," |
| 115 " \"inproduct\": \"31/01/12 01:00 GMT\"" |
| 116 " }" |
| 117 " ]" |
| 118 " }" |
| 119 "}"; |
| 120 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
| 121 base::JSONReader::Read(json, false))); |
| 122 |
| 123 // Check that prefs are set correctly. |
| 124 web_resource_service->UnpackPromoSignal(*(test_json.get())); |
| 125 double promo_start = |
| 126 profile.GetPrefs()->GetReal(prefs::kNTPPromoStart); |
| 127 ASSERT_EQ(promo_start, 1264899600); // unix epoch for Jan 31 2010 0100 GMT. |
| 128 double promo_end = |
| 129 profile.GetPrefs()->GetReal(prefs::kNTPPromoEnd); |
| 130 ASSERT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT. |
| 131 std::string promo_line = profile.GetPrefs()->GetString(prefs::kNTPPromoLine); |
| 132 ASSERT_EQ(promo_line, "Eat more pie!"); |
| 133 } |
| 134 |
OLD | NEW |