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

Side by Side Diff: sync/internal_api/http_bridge_unittest.cc

Issue 1339943003: Revert "Report data usage UMA for Chrome services" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « sync/internal_api/http_bridge.cc ('k') | sync/internal_api/public/http_bridge.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/metrics/field_trial.h" 5 #include "base/metrics/field_trial.h"
6 #include "base/strings/stringprintf.h" 6 #include "base/strings/stringprintf.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "base/test/mock_entropy_provider.h" 8 #include "base/test/mock_entropy_provider.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
11 #include "net/test/spawned_test_server/spawned_test_server.h" 11 #include "net/test/spawned_test_server/spawned_test_server.h"
12 #include "net/url_request/test_url_fetcher_factory.h" 12 #include "net/url_request/test_url_fetcher_factory.h"
13 #include "net/url_request/url_fetcher_delegate.h" 13 #include "net/url_request/url_fetcher_delegate.h"
14 #include "net/url_request/url_request_test_util.h" 14 #include "net/url_request/url_request_test_util.h"
15 #include "sync/internal_api/public/base/cancelation_signal.h" 15 #include "sync/internal_api/public/base/cancelation_signal.h"
16 #include "sync/internal_api/public/http_bridge.h" 16 #include "sync/internal_api/public/http_bridge.h"
17 #include "sync/internal_api/public/http_post_provider_factory.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/zlib/zlib.h" 18 #include "third_party/zlib/zlib.h"
20 19
21 namespace syncer { 20 namespace syncer {
22 21
23 namespace { 22 namespace {
24 23
25 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. 24 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113.
26 const base::FilePath::CharType kDocRoot[] = 25 const base::FilePath::CharType kDocRoot[] =
27 FILE_PATH_LITERAL("chrome/test/data"); 26 FILE_PATH_LITERAL("chrome/test/data");
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 io_thread_.Stop(); 137 io_thread_.Stop();
139 } 138 }
140 139
141 HttpBridge* BuildBridge() { 140 HttpBridge* BuildBridge() {
142 if (!fake_default_request_context_getter_) { 141 if (!fake_default_request_context_getter_) {
143 fake_default_request_context_getter_ = 142 fake_default_request_context_getter_ =
144 new net::TestURLRequestContextGetter(io_thread_.task_runner()); 143 new net::TestURLRequestContextGetter(io_thread_.task_runner());
145 fake_default_request_context_getter_->AddRef(); 144 fake_default_request_context_getter_->AddRef();
146 } 145 }
147 HttpBridge* bridge = 146 HttpBridge* bridge =
148 new HttpBridge(kUserAgent, fake_default_request_context_getter_, 147 new HttpBridge(kUserAgent,
149 NetworkTimeUpdateCallback(), BindToTrackerCallback()); 148 fake_default_request_context_getter_,
149 NetworkTimeUpdateCallback());
150 return bridge; 150 return bridge;
151 } 151 }
152 152
153 static void Abort(HttpBridge* bridge) { 153 static void Abort(HttpBridge* bridge) {
154 bridge->Abort(); 154 bridge->Abort();
155 } 155 }
156 156
157 // Used by AbortAndReleaseBeforeFetchCompletes to test an interesting race 157 // Used by AbortAndReleaseBeforeFetchCompletes to test an interesting race
158 // condition. 158 // condition.
159 void RunSyncThreadBridgeUseTest(base::WaitableEvent* signal_when_created, 159 void RunSyncThreadBridgeUseTest(base::WaitableEvent* signal_when_created,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 200
201 // An HttpBridge that doesn't actually make network requests and just calls 201 // An HttpBridge that doesn't actually make network requests and just calls
202 // back with dummy response info. 202 // back with dummy response info.
203 // TODO(tim): Instead of inheriting here we should inject a component 203 // TODO(tim): Instead of inheriting here we should inject a component
204 // responsible for the MakeAsynchronousPost bit. 204 // responsible for the MakeAsynchronousPost bit.
205 class ShuntedHttpBridge : public HttpBridge { 205 class ShuntedHttpBridge : public HttpBridge {
206 public: 206 public:
207 // If |never_finishes| is true, the simulated request never actually 207 // If |never_finishes| is true, the simulated request never actually
208 // returns. 208 // returns.
209 ShuntedHttpBridge(net::URLRequestContextGetter* baseline_context_getter, 209 ShuntedHttpBridge(net::URLRequestContextGetter* baseline_context_getter,
210 MAYBE_SyncHttpBridgeTest* test, 210 MAYBE_SyncHttpBridgeTest* test, bool never_finishes)
211 bool never_finishes)
212 : HttpBridge(kUserAgent, 211 : HttpBridge(kUserAgent,
213 baseline_context_getter, 212 baseline_context_getter,
214 NetworkTimeUpdateCallback(), 213 NetworkTimeUpdateCallback()),
215 BindToTrackerCallback()), 214 test_(test), never_finishes_(never_finishes) { }
216 test_(test),
217 never_finishes_(never_finishes) {}
218
219 protected: 215 protected:
220 void MakeAsynchronousPost() override { 216 void MakeAsynchronousPost() override {
221 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); 217 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop());
222 if (never_finishes_) 218 if (never_finishes_)
223 return; 219 return;
224 220
225 // We don't actually want to make a request for this test, so just callback 221 // We don't actually want to make a request for this test, so just callback
226 // as if it completed. 222 // as if it completed.
227 test_->GetIOThreadLoop()->PostTask(FROM_HERE, 223 test_->GetIOThreadLoop()->PostTask(FROM_HERE,
228 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); 224 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this));
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 net::URLRequestContextGetter* baseline_context_getter, 572 net::URLRequestContextGetter* baseline_context_getter,
577 CancelationSignal* factory_cancelation_signal, 573 CancelationSignal* factory_cancelation_signal,
578 syncer::HttpPostProviderFactory** bridge_factory_out, 574 syncer::HttpPostProviderFactory** bridge_factory_out,
579 syncer::HttpPostProviderInterface** bridge_out, 575 syncer::HttpPostProviderInterface** bridge_out,
580 base::WaitableEvent* signal_when_created, 576 base::WaitableEvent* signal_when_created,
581 base::WaitableEvent* wait_for_shutdown) { 577 base::WaitableEvent* wait_for_shutdown) {
582 scoped_ptr<syncer::HttpBridgeFactory> bridge_factory( 578 scoped_ptr<syncer::HttpBridgeFactory> bridge_factory(
583 new syncer::HttpBridgeFactory(baseline_context_getter, 579 new syncer::HttpBridgeFactory(baseline_context_getter,
584 NetworkTimeUpdateCallback(), 580 NetworkTimeUpdateCallback(),
585 factory_cancelation_signal)); 581 factory_cancelation_signal));
586 bridge_factory->Init("test", BindToTrackerCallback()); 582 bridge_factory->Init("test");
587 *bridge_factory_out = bridge_factory.get(); 583 *bridge_factory_out = bridge_factory.get();
588 584
589 HttpPostProviderInterface* bridge = bridge_factory->Create(); 585 HttpPostProviderInterface* bridge = bridge_factory->Create();
590 *bridge_out = bridge; 586 *bridge_out = bridge;
591 587
592 signal_when_created->Signal(); 588 signal_when_created->Signal();
593 wait_for_shutdown->Wait(); 589 wait_for_shutdown->Wait();
594 590
595 bridge_factory->Destroy(bridge); 591 bridge_factory->Destroy(bridge);
596 } 592 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 new HttpBridgeFactory(baseline_context_getter.get(), 666 new HttpBridgeFactory(baseline_context_getter.get(),
671 NetworkTimeUpdateCallback(), 667 NetworkTimeUpdateCallback(),
672 &release_request_context_signal)); 668 &release_request_context_signal));
673 669
674 // UI Thread: A very early shutdown request arrives and executes on the UI 670 // UI Thread: A very early shutdown request arrives and executes on the UI
675 // thread before the posted sync thread task is run. 671 // thread before the posted sync thread task is run.
676 release_request_context_signal.Signal(); 672 release_request_context_signal.Signal();
677 673
678 // Sync thread: Finally run the posted task, only to find that our 674 // Sync thread: Finally run the posted task, only to find that our
679 // HttpBridgeFactory has been neutered. Should not crash. 675 // HttpBridgeFactory has been neutered. Should not crash.
680 factory->Init("TestUserAgent", BindToTrackerCallback()); 676 factory->Init("TestUserAgent");
681 677
682 // At this point, attempting to use the factory would trigger a crash. Both 678 // At this point, attempting to use the factory would trigger a crash. Both
683 // this test and the real world code should make sure this never happens. 679 // this test and the real world code should make sure this never happens.
684 }; 680 };
685 681
686 } // namespace syncer 682 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/http_bridge.cc ('k') | sync/internal_api/public/http_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698