Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: chrome/browser/metrics/variations/resource_request_allowed_notifier_unittest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/prefs/testing_pref_service.h" 5 #include "base/prefs/testing_pref_service.h"
6 #include "chrome/browser/metrics/variations/eula_accepted_notifier.h" 6 #include "chrome/browser/metrics/variations/eula_accepted_notifier.h"
7 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier_te st_util.h" 7 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier_te st_util.h"
8 #include "chrome/common/chrome_notification_types.h" 8 #include "chrome/common/chrome_notification_types.h"
9 #include "chrome/test/base/testing_browser_process.h" 9 #include "chrome/test/base/testing_browser_process.h"
10 #include "content/public/browser/notification_service.h" 10 #include "content/public/browser/notification_service.h"
11 #include "content/public/test/test_browser_thread.h" 11 #include "content/public/test/test_browser_thread.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 // Override NetworkChangeNotifier to simulate connection type changes for tests. 14 // Override NetworkChangeNotifier to simulate connection type changes for tests.
15 class TestNetworkChangeNotifier : public net::NetworkChangeNotifier { 15 class TestNetworkChangeNotifier : public net::NetworkChangeNotifier {
16 public: 16 public:
17 TestNetworkChangeNotifier() 17 TestNetworkChangeNotifier()
18 : net::NetworkChangeNotifier(), 18 : net::NetworkChangeNotifier(),
19 connection_type_to_return_( 19 connection_type_to_return_(
20 net::NetworkChangeNotifier::CONNECTION_UNKNOWN) { 20 net::NetworkChangeNotifier::CONNECTION_UNKNOWN) {
21 } 21 }
22 22
23 // Simulates a change of the connection type to |type|. This will notify any 23 // Simulates a change of the connection type to |type|. This will notify any
24 // objects that are NetworkChangeNotifiers. 24 // objects that are NetworkChangeNotifiers.
25 void SimulateNetworkConnectionChange( 25 void SimulateNetworkConnectionChange(
26 net::NetworkChangeNotifier::ConnectionType type) { 26 net::NetworkChangeNotifier::ConnectionType type) {
27 connection_type_to_return_ = type; 27 connection_type_to_return_ = type;
28 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); 28 net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange();
29 MessageLoop::current()->RunUntilIdle(); 29 base::MessageLoop::current()->RunUntilIdle();
30 } 30 }
31 31
32 private: 32 private:
33 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE { 33 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE {
34 return connection_type_to_return_; 34 return connection_type_to_return_;
35 } 35 }
36 36
37 // The currently simulated network connection type. If this is set to 37 // The currently simulated network connection type. If this is set to
38 // CONNECTION_NONE, then NetworkChangeNotifier::IsOffline will return true. 38 // CONNECTION_NONE, then NetworkChangeNotifier::IsOffline will return true.
39 net::NetworkChangeNotifier::ConnectionType connection_type_to_return_; 39 net::NetworkChangeNotifier::ConnectionType connection_type_to_return_;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 virtual void SetUp() OVERRIDE { 132 virtual void SetUp() OVERRIDE {
133 // Assume the test service has already requested permission, as all tests 133 // Assume the test service has already requested permission, as all tests
134 // just test that criteria changes notify the server. 134 // just test that criteria changes notify the server.
135 // Set default EULA state to done (not waiting and EULA accepted) to 135 // Set default EULA state to done (not waiting and EULA accepted) to
136 // simplify non-ChromeOS tests. 136 // simplify non-ChromeOS tests.
137 SetWaitingForEula(false); 137 SetWaitingForEula(false);
138 SetNeedsEulaAcceptance(false); 138 SetNeedsEulaAcceptance(false);
139 } 139 }
140 140
141 private: 141 private:
142 MessageLoopForUI message_loop; 142 base::MessageLoopForUI message_loop;
143 content::TestBrowserThread ui_thread; 143 content::TestBrowserThread ui_thread;
144 TestNetworkChangeNotifier network_notifier; 144 TestNetworkChangeNotifier network_notifier;
145 TestRequestAllowedNotifier resource_request_allowed_notifier_; 145 TestRequestAllowedNotifier resource_request_allowed_notifier_;
146 TestEulaAcceptedNotifier* eula_notifier_; // Weak, owned by RRAN. 146 TestEulaAcceptedNotifier* eula_notifier_; // Weak, owned by RRAN.
147 bool was_notified_; 147 bool was_notified_;
148 148
149 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifierTest); 149 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifierTest);
150 }; 150 };
151 151
152 TEST_F(ResourceRequestAllowedNotifierTest, DoNotNotifyIfOffline) { 152 TEST_F(ResourceRequestAllowedNotifierTest, DoNotNotifyIfOffline) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 // calling SimulateResourceRequest here. 251 // calling SimulateResourceRequest here.
252 DisableEulaAndNetwork(); 252 DisableEulaAndNetwork();
253 253
254 SimulateNetworkConnectionChange( 254 SimulateNetworkConnectionChange(
255 net::NetworkChangeNotifier::CONNECTION_WIFI); 255 net::NetworkChangeNotifier::CONNECTION_WIFI);
256 EXPECT_FALSE(was_notified()); 256 EXPECT_FALSE(was_notified());
257 257
258 SimulateEulaAccepted(); 258 SimulateEulaAccepted();
259 EXPECT_FALSE(was_notified()); 259 EXPECT_FALSE(was_notified());
260 } 260 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/thread_watcher.cc ('k') | chrome/browser/metrics/variations/variations_http_header_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698