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

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

Issue 1330443002: Report data usage UMA for Chrome services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NewArchServices
Patch Set: Fix calling Init function in sync_client.cc 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"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/zlib/zlib.h" 19 #include "third_party/zlib/zlib.h"
19 20
20 namespace syncer { 21 namespace syncer {
21 22
22 namespace { 23 namespace {
23 24
24 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. 25 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113.
25 const base::FilePath::CharType kDocRoot[] = 26 const base::FilePath::CharType kDocRoot[] =
26 FILE_PATH_LITERAL("chrome/test/data"); 27 FILE_PATH_LITERAL("chrome/test/data");
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 io_thread_.Stop(); 138 io_thread_.Stop();
138 } 139 }
139 140
140 HttpBridge* BuildBridge() { 141 HttpBridge* BuildBridge() {
141 if (!fake_default_request_context_getter_) { 142 if (!fake_default_request_context_getter_) {
142 fake_default_request_context_getter_ = 143 fake_default_request_context_getter_ =
143 new net::TestURLRequestContextGetter(io_thread_.task_runner()); 144 new net::TestURLRequestContextGetter(io_thread_.task_runner());
144 fake_default_request_context_getter_->AddRef(); 145 fake_default_request_context_getter_->AddRef();
145 } 146 }
146 HttpBridge* bridge = 147 HttpBridge* bridge =
147 new HttpBridge(kUserAgent, 148 new HttpBridge(kUserAgent, fake_default_request_context_getter_,
148 fake_default_request_context_getter_, 149 NetworkTimeUpdateCallback(), BindToTrackerCallback());
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, bool never_finishes) 210 MAYBE_SyncHttpBridgeTest* test,
211 bool never_finishes)
211 : HttpBridge(kUserAgent, 212 : HttpBridge(kUserAgent,
212 baseline_context_getter, 213 baseline_context_getter,
213 NetworkTimeUpdateCallback()), 214 NetworkTimeUpdateCallback(),
214 test_(test), never_finishes_(never_finishes) { } 215 BindToTrackerCallback()),
216 test_(test),
217 never_finishes_(never_finishes) {}
218
215 protected: 219 protected:
216 void MakeAsynchronousPost() override { 220 void MakeAsynchronousPost() override {
217 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); 221 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop());
218 if (never_finishes_) 222 if (never_finishes_)
219 return; 223 return;
220 224
221 // We don't actually want to make a request for this test, so just callback 225 // We don't actually want to make a request for this test, so just callback
222 // as if it completed. 226 // as if it completed.
223 test_->GetIOThreadLoop()->PostTask(FROM_HERE, 227 test_->GetIOThreadLoop()->PostTask(FROM_HERE,
224 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); 228 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this));
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 net::URLRequestContextGetter* baseline_context_getter, 576 net::URLRequestContextGetter* baseline_context_getter,
573 CancelationSignal* factory_cancelation_signal, 577 CancelationSignal* factory_cancelation_signal,
574 syncer::HttpPostProviderFactory** bridge_factory_out, 578 syncer::HttpPostProviderFactory** bridge_factory_out,
575 syncer::HttpPostProviderInterface** bridge_out, 579 syncer::HttpPostProviderInterface** bridge_out,
576 base::WaitableEvent* signal_when_created, 580 base::WaitableEvent* signal_when_created,
577 base::WaitableEvent* wait_for_shutdown) { 581 base::WaitableEvent* wait_for_shutdown) {
578 scoped_ptr<syncer::HttpBridgeFactory> bridge_factory( 582 scoped_ptr<syncer::HttpBridgeFactory> bridge_factory(
579 new syncer::HttpBridgeFactory(baseline_context_getter, 583 new syncer::HttpBridgeFactory(baseline_context_getter,
580 NetworkTimeUpdateCallback(), 584 NetworkTimeUpdateCallback(),
581 factory_cancelation_signal)); 585 factory_cancelation_signal));
582 bridge_factory->Init("test"); 586 bridge_factory->Init("test", BindToTrackerCallback());
583 *bridge_factory_out = bridge_factory.get(); 587 *bridge_factory_out = bridge_factory.get();
584 588
585 HttpPostProviderInterface* bridge = bridge_factory->Create(); 589 HttpPostProviderInterface* bridge = bridge_factory->Create();
586 *bridge_out = bridge; 590 *bridge_out = bridge;
587 591
588 signal_when_created->Signal(); 592 signal_when_created->Signal();
589 wait_for_shutdown->Wait(); 593 wait_for_shutdown->Wait();
590 594
591 bridge_factory->Destroy(bridge); 595 bridge_factory->Destroy(bridge);
592 } 596 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 new HttpBridgeFactory(baseline_context_getter.get(), 670 new HttpBridgeFactory(baseline_context_getter.get(),
667 NetworkTimeUpdateCallback(), 671 NetworkTimeUpdateCallback(),
668 &release_request_context_signal)); 672 &release_request_context_signal));
669 673
670 // UI Thread: A very early shutdown request arrives and executes on the UI 674 // UI Thread: A very early shutdown request arrives and executes on the UI
671 // thread before the posted sync thread task is run. 675 // thread before the posted sync thread task is run.
672 release_request_context_signal.Signal(); 676 release_request_context_signal.Signal();
673 677
674 // Sync thread: Finally run the posted task, only to find that our 678 // Sync thread: Finally run the posted task, only to find that our
675 // HttpBridgeFactory has been neutered. Should not crash. 679 // HttpBridgeFactory has been neutered. Should not crash.
676 factory->Init("TestUserAgent"); 680 factory->Init("TestUserAgent", BindToTrackerCallback());
677 681
678 // At this point, attempting to use the factory would trigger a crash. Both 682 // At this point, attempting to use the factory would trigger a crash. Both
679 // this test and the real world code should make sure this never happens. 683 // this test and the real world code should make sure this never happens.
680 }; 684 };
681 685
682 } // namespace syncer 686 } // 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