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/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/web_resource/notification_promo.h" | 14 #include "chrome/browser/web_resource/notification_promo.h" |
15 #include "chrome/browser/web_resource/promo_resource_service.h" | 15 #include "chrome/browser/web_resource/promo_resource_service.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
19 #include "chrome/test/base/testing_pref_service.h" | 19 #include "chrome/test/base/testing_pref_service.h" |
20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 #include "chrome/browser/web_resource/notification_promo_mobile_ntp.h" | 24 #include "chrome/browser/web_resource/notification_promo_mobile_ntp.h" |
25 | 25 |
26 class PromoResourceServiceMobileNtpTest : public testing::Test { | 26 class PromoResourceServiceMobileNtpTest : public testing::Test { |
27 public: | 27 public: |
| 28 // |promo_resource_service_| must be created after |local_state_|. |
28 PromoResourceServiceMobileNtpTest() | 29 PromoResourceServiceMobileNtpTest() |
29 : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) { | 30 : local_state_(TestingBrowserProcess::GetGlobal()), |
30 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState( | 31 promo_resource_service_(new PromoResourceService) {} |
31 local_state_.Get()); | |
32 // |promo_resource_service_| must be created after local state is set. | |
33 promo_resource_service_ = new PromoResourceService; | |
34 } | |
35 | 32 |
36 protected: | 33 protected: |
37 ScopedTestingLocalState local_state_; | 34 ScopedTestingLocalState local_state_; |
38 scoped_refptr<PromoResourceService> promo_resource_service_; | 35 scoped_refptr<PromoResourceService> promo_resource_service_; |
39 MessageLoop loop_; | 36 MessageLoop loop_; |
40 }; | 37 }; |
41 | 38 |
42 class NotificationPromoMobileNtpTest { | 39 class NotificationPromoMobileNtpTest { |
43 public: | 40 public: |
44 NotificationPromoMobileNtpTest() : received_notification_(false) { | 41 NotificationPromoMobileNtpTest() : received_notification_(false) {} |
45 } | |
46 | 42 |
47 void Init(const std::string& json, | 43 void Init(const std::string& json, |
48 const std::string& promo_text, | 44 const std::string& promo_text, |
49 const std::string& promo_text_long, | 45 const std::string& promo_text_long, |
50 const std::string& promo_action_type, | 46 const std::string& promo_action_type, |
51 const std::string& promo_action_arg0, | 47 const std::string& promo_action_arg0, |
52 const std::string& promo_action_arg1) { | 48 const std::string& promo_action_arg1) { |
53 Value* value(base::JSONReader::Read(json)); | 49 Value* value(base::JSONReader::Read(json)); |
54 ASSERT_TRUE(value); | 50 ASSERT_TRUE(value); |
55 DictionaryValue* dict = NULL; | 51 DictionaryValue* dict = NULL; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 "It\'s simple. Go http://www.google.com/chrome/", | 173 "It\'s simple. Go http://www.google.com/chrome/", |
178 "ACTION_EMAIL", "This is the body.", "XXX value"); | 174 "ACTION_EMAIL", "This is the body.", "XXX value"); |
179 | 175 |
180 promo_test.InitPromoFromJson(true); | 176 promo_test.InitPromoFromJson(true); |
181 | 177 |
182 // Second time should not trigger a notification. | 178 // Second time should not trigger a notification. |
183 promo_test.InitPromoFromJson(false); | 179 promo_test.InitPromoFromJson(false); |
184 | 180 |
185 promo_test.TestInitFromPrefs(); | 181 promo_test.TestInitFromPrefs(); |
186 } | 182 } |
OLD | NEW |