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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
| 7 #include <memory> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "components/prefs/testing_pref_service.h" | 16 #include "components/prefs/testing_pref_service.h" |
16 #include "components/version_info/version_info.h" | 17 #include "components/version_info/version_info.h" |
(...skipping 13 matching lines...) Expand all Loading... |
30 PromoResourceServiceMobileNtpTest() { | 31 PromoResourceServiceMobileNtpTest() { |
31 NotificationPromo::RegisterPrefs(local_state_.registry()); | 32 NotificationPromo::RegisterPrefs(local_state_.registry()); |
32 promo_resource_service_.reset(new PromoResourceService( | 33 promo_resource_service_.reset(new PromoResourceService( |
33 &local_state_, kChannel, "en", nullptr, nullptr, | 34 &local_state_, kChannel, "en", nullptr, nullptr, |
34 web_resource::WebResourceService::ParseJSONCallback())); | 35 web_resource::WebResourceService::ParseJSONCallback())); |
35 } | 36 } |
36 | 37 |
37 protected: | 38 protected: |
38 TestingPrefServiceSimple local_state_; | 39 TestingPrefServiceSimple local_state_; |
39 // |promo_resource_service_| must be created after |local_state_|. | 40 // |promo_resource_service_| must be created after |local_state_|. |
40 scoped_ptr<PromoResourceService> promo_resource_service_; | 41 std::unique_ptr<PromoResourceService> promo_resource_service_; |
41 base::MessageLoop loop_; | 42 base::MessageLoop loop_; |
42 }; | 43 }; |
43 | 44 |
44 class NotificationPromoMobileNtpTest { | 45 class NotificationPromoMobileNtpTest { |
45 public: | 46 public: |
46 explicit NotificationPromoMobileNtpTest(PrefService* local_state) | 47 explicit NotificationPromoMobileNtpTest(PrefService* local_state) |
47 : local_state_(local_state), | 48 : local_state_(local_state), |
48 mobile_promo_(local_state), | 49 mobile_promo_(local_state), |
49 received_notification_(false) {} | 50 received_notification_(false) {} |
50 | 51 |
51 void Init(const std::string& json, | 52 void Init(const std::string& json, |
52 const std::string& promo_text, | 53 const std::string& promo_text, |
53 const std::string& promo_text_long, | 54 const std::string& promo_text_long, |
54 const std::string& promo_action_type, | 55 const std::string& promo_action_type, |
55 const std::string& promo_action_arg0, | 56 const std::string& promo_action_arg0, |
56 const std::string& promo_action_arg1) { | 57 const std::string& promo_action_arg1) { |
57 scoped_ptr<base::Value> value = base::JSONReader::Read(json); | 58 std::unique_ptr<base::Value> value = base::JSONReader::Read(json); |
58 ASSERT_TRUE(value); | 59 ASSERT_TRUE(value); |
59 base::DictionaryValue* dict = NULL; | 60 base::DictionaryValue* dict = NULL; |
60 value.release()->GetAsDictionary(&dict); | 61 value.release()->GetAsDictionary(&dict); |
61 ASSERT_TRUE(dict); | 62 ASSERT_TRUE(dict); |
62 test_json_.reset(dict); | 63 test_json_.reset(dict); |
63 | 64 |
64 promo_text_ = promo_text; | 65 promo_text_ = promo_text; |
65 promo_text_long_ = promo_text_long; | 66 promo_text_long_ = promo_text_long; |
66 promo_action_type_ = promo_action_type; | 67 promo_action_type_ = promo_action_type; |
67 promo_action_args_.push_back(promo_action_arg0); | 68 promo_action_args_.push_back(promo_action_arg0); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 EXPECT_TRUE(prefs_mobile_promo.action_args()->GetString(i, &prefs_value)); | 119 EXPECT_TRUE(prefs_mobile_promo.action_args()->GetString(i, &prefs_value)); |
119 EXPECT_TRUE(mobile_promo_.action_args()->GetString(i, &promo_value)); | 120 EXPECT_TRUE(mobile_promo_.action_args()->GetString(i, &promo_value)); |
120 EXPECT_EQ(promo_value, prefs_value); | 121 EXPECT_EQ(promo_value, prefs_value); |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 private: | 125 private: |
125 PrefService* local_state_; | 126 PrefService* local_state_; |
126 NotificationPromoMobileNtp mobile_promo_; | 127 NotificationPromoMobileNtp mobile_promo_; |
127 bool received_notification_; | 128 bool received_notification_; |
128 scoped_ptr<base::DictionaryValue> test_json_; | 129 std::unique_ptr<base::DictionaryValue> test_json_; |
129 | 130 |
130 std::string promo_text_; | 131 std::string promo_text_; |
131 std::string promo_text_long_; | 132 std::string promo_text_long_; |
132 std::string promo_action_type_; | 133 std::string promo_action_type_; |
133 std::vector<std::string> promo_action_args_; | 134 std::vector<std::string> promo_action_args_; |
134 }; | 135 }; |
135 | 136 |
136 TEST_F(PromoResourceServiceMobileNtpTest, NotificationPromoMobileNtpTest) { | 137 TEST_F(PromoResourceServiceMobileNtpTest, NotificationPromoMobileNtpTest) { |
137 NotificationPromoMobileNtpTest promo_test(&local_state_); | 138 NotificationPromoMobileNtpTest promo_test(&local_state_); |
138 | 139 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 179 |
179 promo_test.InitPromoFromJson(true); | 180 promo_test.InitPromoFromJson(true); |
180 | 181 |
181 // Second time should not trigger a notification. | 182 // Second time should not trigger a notification. |
182 promo_test.InitPromoFromJson(false); | 183 promo_test.InitPromoFromJson(false); |
183 | 184 |
184 promo_test.TestInitFromPrefs(); | 185 promo_test.TestInitFromPrefs(); |
185 } | 186 } |
186 | 187 |
187 } // namespace web_resource | 188 } // namespace web_resource |
OLD | NEW |