OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/prefs/testing_pref_service.h" | 5 #include "base/prefs/testing_pref_service.h" |
6 #include "chrome/browser/chrome_notification_types.h" | |
7 #include "chrome/browser/web_resource/eula_accepted_notifier.h" | 6 #include "chrome/browser/web_resource/eula_accepted_notifier.h" |
8 #include "chrome/browser/web_resource/resource_request_allowed_notifier_test_uti
l.h" | 7 #include "chrome/browser/web_resource/resource_request_allowed_notifier_test_uti
l.h" |
9 #include "chrome/test/base/testing_browser_process.h" | |
10 #include "content/public/browser/notification_service.h" | |
11 #include "content/public/test/test_browser_thread.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
13 | 9 |
14 // Override NetworkChangeNotifier to simulate connection type changes for tests. | 10 // Override NetworkChangeNotifier to simulate connection type changes for tests. |
15 class TestNetworkChangeNotifier : public net::NetworkChangeNotifier { | 11 class TestNetworkChangeNotifier : public net::NetworkChangeNotifier { |
16 public: | 12 public: |
17 TestNetworkChangeNotifier() | 13 TestNetworkChangeNotifier() |
18 : net::NetworkChangeNotifier(), | 14 : net::NetworkChangeNotifier(), |
19 connection_type_to_return_( | 15 connection_type_to_return_( |
20 net::NetworkChangeNotifier::CONNECTION_UNKNOWN) { | 16 net::NetworkChangeNotifier::CONNECTION_UNKNOWN) { |
21 } | 17 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 }; | 64 }; |
69 | 65 |
70 // A test fixture class for ResourceRequestAllowedNotifier tests that require | 66 // A test fixture class for ResourceRequestAllowedNotifier tests that require |
71 // network state simulations. This also acts as the service implementing the | 67 // network state simulations. This also acts as the service implementing the |
72 // ResourceRequestAllowedNotifier::Observer interface. | 68 // ResourceRequestAllowedNotifier::Observer interface. |
73 class ResourceRequestAllowedNotifierTest | 69 class ResourceRequestAllowedNotifierTest |
74 : public testing::Test, | 70 : public testing::Test, |
75 public ResourceRequestAllowedNotifier::Observer { | 71 public ResourceRequestAllowedNotifier::Observer { |
76 public: | 72 public: |
77 ResourceRequestAllowedNotifierTest() | 73 ResourceRequestAllowedNotifierTest() |
78 : ui_thread(content::BrowserThread::UI, &message_loop), | 74 : resource_request_allowed_notifier_(&prefs_), |
79 eula_notifier_(new TestEulaAcceptedNotifier), | 75 eula_notifier_(new TestEulaAcceptedNotifier), |
80 was_notified_(false) { | 76 was_notified_(false) { |
81 resource_request_allowed_notifier_.InitWithEulaAcceptNotifier( | 77 resource_request_allowed_notifier_.InitWithEulaAcceptNotifier( |
82 this, scoped_ptr<EulaAcceptedNotifier>(eula_notifier_)); | 78 this, scoped_ptr<EulaAcceptedNotifier>(eula_notifier_)); |
83 } | 79 } |
84 ~ResourceRequestAllowedNotifierTest() override {} | 80 ~ResourceRequestAllowedNotifierTest() override {} |
85 | 81 |
86 bool was_notified() const { return was_notified_; } | 82 bool was_notified() const { return was_notified_; } |
87 | 83 |
88 // ResourceRequestAllowedNotifier::Observer override: | 84 // ResourceRequestAllowedNotifier::Observer override: |
89 void OnResourceRequestsAllowed() override { was_notified_ = true; } | 85 void OnResourceRequestsAllowed() override { was_notified_ = true; } |
90 | 86 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // Assume the test service has already requested permission, as all tests | 128 // Assume the test service has already requested permission, as all tests |
133 // just test that criteria changes notify the server. | 129 // just test that criteria changes notify the server. |
134 // Set default EULA state to done (not waiting and EULA accepted) to | 130 // Set default EULA state to done (not waiting and EULA accepted) to |
135 // simplify non-ChromeOS tests. | 131 // simplify non-ChromeOS tests. |
136 SetWaitingForEula(false); | 132 SetWaitingForEula(false); |
137 SetNeedsEulaAcceptance(false); | 133 SetNeedsEulaAcceptance(false); |
138 } | 134 } |
139 | 135 |
140 private: | 136 private: |
141 base::MessageLoopForUI message_loop; | 137 base::MessageLoopForUI message_loop; |
142 content::TestBrowserThread ui_thread; | |
143 TestNetworkChangeNotifier network_notifier; | 138 TestNetworkChangeNotifier network_notifier; |
| 139 TestingPrefServiceSimple prefs_; |
144 TestRequestAllowedNotifier resource_request_allowed_notifier_; | 140 TestRequestAllowedNotifier resource_request_allowed_notifier_; |
145 TestEulaAcceptedNotifier* eula_notifier_; // Weak, owned by RRAN. | 141 TestEulaAcceptedNotifier* eula_notifier_; // Weak, owned by RRAN. |
146 bool was_notified_; | 142 bool was_notified_; |
147 | 143 |
148 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifierTest); | 144 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifierTest); |
149 }; | 145 }; |
150 | 146 |
151 TEST_F(ResourceRequestAllowedNotifierTest, DoNotNotifyIfOffline) { | 147 TEST_F(ResourceRequestAllowedNotifierTest, DoNotNotifyIfOffline) { |
152 SetWaitingForNetwork(true); | 148 SetWaitingForNetwork(true); |
153 EXPECT_FALSE(SimulateResourceRequest()); | 149 EXPECT_FALSE(SimulateResourceRequest()); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // calling SimulateResourceRequest here. | 280 // calling SimulateResourceRequest here. |
285 DisableEulaAndNetwork(); | 281 DisableEulaAndNetwork(); |
286 | 282 |
287 SimulateNetworkConnectionChange( | 283 SimulateNetworkConnectionChange( |
288 net::NetworkChangeNotifier::CONNECTION_WIFI); | 284 net::NetworkChangeNotifier::CONNECTION_WIFI); |
289 EXPECT_FALSE(was_notified()); | 285 EXPECT_FALSE(was_notified()); |
290 | 286 |
291 SimulateEulaAccepted(); | 287 SimulateEulaAccepted(); |
292 EXPECT_FALSE(was_notified()); | 288 EXPECT_FALSE(was_notified()); |
293 } | 289 } |
OLD | NEW |