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

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

Issue 2083713002: Remove calls to MessageLoop::current() in sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self-review Created 4 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
« no previous file with comments | « sync/internal_api/http_bridge.cc ('k') | sync/internal_api/public/engine/model_safe_worker.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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/bit_cast.h" 8 #include "base/bit_cast.h"
9 #include "base/single_thread_task_runner.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
11 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "net/http/http_response_headers.h" 14 #include "net/http/http_response_headers.h"
14 #include "net/test/embedded_test_server/embedded_test_server.h" 15 #include "net/test/embedded_test_server/embedded_test_server.h"
15 #include "net/url_request/test_url_fetcher_factory.h" 16 #include "net/url_request/test_url_fetcher_factory.h"
16 #include "net/url_request/url_fetcher_delegate.h" 17 #include "net/url_request/url_fetcher_delegate.h"
17 #include "net/url_request/url_request_test_util.h" 18 #include "net/url_request/url_request_test_util.h"
18 #include "sync/internal_api/public/base/cancelation_signal.h" 19 #include "sync/internal_api/public/base/cancelation_signal.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 bool never_finishes) 136 bool never_finishes)
136 : HttpBridge(kUserAgent, 137 : HttpBridge(kUserAgent,
137 baseline_context_getter, 138 baseline_context_getter,
138 NetworkTimeUpdateCallback(), 139 NetworkTimeUpdateCallback(),
139 BindToTrackerCallback()), 140 BindToTrackerCallback()),
140 test_(test), 141 test_(test),
141 never_finishes_(never_finishes) {} 142 never_finishes_(never_finishes) {}
142 143
143 protected: 144 protected:
144 void MakeAsynchronousPost() override { 145 void MakeAsynchronousPost() override {
145 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); 146 ASSERT_TRUE(
147 test_->GetIOThreadLoop()->task_runner()->BelongsToCurrentThread());
146 if (never_finishes_) 148 if (never_finishes_)
147 return; 149 return;
148 150
149 // We don't actually want to make a request for this test, so just callback 151 // We don't actually want to make a request for this test, so just callback
150 // as if it completed. 152 // as if it completed.
151 test_->GetIOThreadLoop()->PostTask(FROM_HERE, 153 test_->GetIOThreadLoop()->PostTask(FROM_HERE,
152 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this)); 154 base::Bind(&ShuntedHttpBridge::CallOnURLFetchComplete, this));
153 } 155 }
154 156
155 private: 157 private:
156 ~ShuntedHttpBridge() override {} 158 ~ShuntedHttpBridge() override {}
157 159
158 void CallOnURLFetchComplete() { 160 void CallOnURLFetchComplete() {
159 ASSERT_TRUE(base::MessageLoop::current() == test_->GetIOThreadLoop()); 161 ASSERT_TRUE(
162 test_->GetIOThreadLoop()->task_runner()->BelongsToCurrentThread());
160 // We return a dummy content response. 163 // We return a dummy content response.
161 std::string response_content = "success!"; 164 std::string response_content = "success!";
162 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); 165 net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL);
163 scoped_refptr<net::HttpResponseHeaders> response_headers( 166 scoped_refptr<net::HttpResponseHeaders> response_headers(
164 new net::HttpResponseHeaders("")); 167 new net::HttpResponseHeaders(""));
165 fetcher.set_response_code(200); 168 fetcher.set_response_code(200);
166 fetcher.SetResponseString(response_content); 169 fetcher.SetResponseString(response_content);
167 fetcher.set_response_headers(response_headers); 170 fetcher.set_response_headers(response_headers);
168 OnURLFetchComplete(&fetcher); 171 OnURLFetchComplete(&fetcher);
169 } 172 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 574
572 // Sync thread: Finally run the posted task, only to find that our 575 // Sync thread: Finally run the posted task, only to find that our
573 // HttpBridgeFactory has been neutered. Should not crash. 576 // HttpBridgeFactory has been neutered. Should not crash.
574 factory->Init("TestUserAgent", BindToTrackerCallback()); 577 factory->Init("TestUserAgent", BindToTrackerCallback());
575 578
576 // At this point, attempting to use the factory would trigger a crash. Both 579 // At this point, attempting to use the factory would trigger a crash. Both
577 // this test and the real world code should make sure this never happens. 580 // this test and the real world code should make sure this never happens.
578 } 581 }
579 582
580 } // namespace syncer 583 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/http_bridge.cc ('k') | sync/internal_api/public/engine/model_safe_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698