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/prefs/browser_prefs.h" | 14 #include "chrome/browser/prefs/browser_prefs.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/web_resource/notification_promo.h" | 16 #include "chrome/browser/web_resource/notification_promo.h" |
17 #include "chrome/browser/web_resource/promo_resource_service.h" | 17 #include "chrome/browser/web_resource/promo_resource_service.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
22 #include "chrome/test/base/testing_pref_service.h" | 22 #include "chrome/test/base/testing_pref_service.h" |
23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "net/url_request/test_url_fetcher_factory.h" | 25 #include "net/url_request/test_url_fetcher_factory.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
27 | 27 |
28 class PromoResourceServiceTest : public testing::Test { | 28 class PromoResourceServiceTest : public testing::Test { |
29 public: | 29 public: |
| 30 // |promo_resource_service_| must be created after |local_state_|. |
30 PromoResourceServiceTest() | 31 PromoResourceServiceTest() |
31 : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) { | 32 : local_state_(TestingBrowserProcess::GetGlobal()), |
32 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState( | 33 promo_resource_service_(new PromoResourceService) {} |
33 local_state_.Get()); | |
34 // |promo_resource_service_| must be created after local state is set. | |
35 promo_resource_service_ = new PromoResourceService; | |
36 } | |
37 | 34 |
38 protected: | 35 protected: |
39 ScopedTestingLocalState local_state_; | 36 ScopedTestingLocalState local_state_; |
40 scoped_refptr<PromoResourceService> promo_resource_service_; | 37 scoped_refptr<PromoResourceService> promo_resource_service_; |
41 MessageLoop loop_; | 38 MessageLoop loop_; |
42 }; | 39 }; |
43 | 40 |
44 class NotificationPromoTest { | 41 class NotificationPromoTest { |
45 public: | 42 public: |
46 NotificationPromoTest() | 43 NotificationPromoTest() |
47 : received_notification_(false), | 44 : received_notification_(false), |
48 start_(0.0), | 45 start_(0.0), |
49 end_(0.0), | 46 end_(0.0), |
50 num_groups_(0), | 47 num_groups_(0), |
51 initial_segment_(0), | 48 initial_segment_(0), |
52 increment_(1), | 49 increment_(1), |
53 time_slice_(0), | 50 time_slice_(0), |
54 max_group_(0), | 51 max_group_(0), |
55 max_views_(0), | 52 max_views_(0), |
56 closed_(false) { | 53 closed_(false) {} |
57 } | |
58 | 54 |
59 void Init(const std::string& json, | 55 void Init(const std::string& json, |
60 const std::string& promo_text, | 56 const std::string& promo_text, |
61 double start, double end, | 57 double start, double end, |
62 int num_groups, int initial_segment, int increment, | 58 int num_groups, int initial_segment, int increment, |
63 int time_slice, int max_group, int max_views) { | 59 int time_slice, int max_group, int max_views) { |
64 Value* value(base::JSONReader::Read(json)); | 60 Value* value(base::JSONReader::Read(json)); |
65 ASSERT_TRUE(value); | 61 ASSERT_TRUE(value); |
66 DictionaryValue* dict = NULL; | 62 DictionaryValue* dict = NULL; |
67 value->GetAsDictionary(&dict); | 63 value->GetAsDictionary(&dict); |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 promo_test.TestInitFromPrefs(); | 485 promo_test.TestInitFromPrefs(); |
490 } | 486 } |
491 | 487 |
492 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { | 488 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { |
493 GURL promo_server_url = NotificationPromo::PromoServerURL(); | 489 GURL promo_server_url = NotificationPromo::PromoServerURL(); |
494 EXPECT_FALSE(promo_server_url.is_empty()); | 490 EXPECT_FALSE(promo_server_url.is_empty()); |
495 EXPECT_TRUE(promo_server_url.is_valid()); | 491 EXPECT_TRUE(promo_server_url.is_valid()); |
496 EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme)); | 492 EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme)); |
497 // TODO(achuith): Test this better. | 493 // TODO(achuith): Test this better. |
498 } | 494 } |
OLD | NEW |