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

Side by Side Diff: content/browser/service_worker/service_worker_browsertest.cc

Issue 2491613004: Make base::Timer sequence-friendly. (Closed)
Patch Set: rebase on r464476 Created 3 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 656
657 // Make the registration findable via storage functions. 657 // Make the registration findable via storage functions.
658 wrapper()->context()->storage()->NotifyInstallingRegistration( 658 wrapper()->context()->storage()->NotifyInstallingRegistration(
659 registration_.get()); 659 registration_.get());
660 660
661 AssociateRendererProcessToPattern(pattern); 661 AssociateRendererProcessToPattern(pattern);
662 } 662 }
663 663
664 void TimeoutWorkerOnIOThread() { 664 void TimeoutWorkerOnIOThread() {
665 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 665 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
666 version_->SimulatePingTimeoutForTesting(); 666 version_->SimulatePingTimeoutForTesting();
horo 2017/04/27 15:49:52 Add EXPECT_TRUE(version_->timeout_timer_.IsRunning
gab 2017/05/26 04:26:57 Done.
667 } 667 }
668 668
669 void AddControlleeOnIOThread() { 669 void AddControlleeOnIOThread() {
670 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); 670 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
671 std::unique_ptr<ServiceWorkerProviderHost> host = 671 std::unique_ptr<ServiceWorkerProviderHost> host =
672 CreateProviderHostForWindow(33 /* dummy render process id */, 672 CreateProviderHostForWindow(33 /* dummy render process id */,
673 1 /* dummy provider_id */, 673 1 /* dummy provider_id */,
674 true /* is_parent_frame_secure */, 674 true /* is_parent_frame_secure */,
675 wrapper()->context()->AsWeakPtr()); 675 wrapper()->context()->AsWeakPtr());
676 host->SetDocumentUrl( 676 host->SetDocumentUrl(
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 RunOnIOThread(base::Bind(&EmbeddedWorkerInstance::RemoveListener, 1164 RunOnIOThread(base::Bind(&EmbeddedWorkerInstance::RemoveListener,
1165 base::Unretained(version_->embedded_worker()), 1165 base::Unretained(version_->embedded_worker()),
1166 &wait_for_load)); 1166 &wait_for_load));
1167 1167
1168 // The script has loaded but start has not completed yet. 1168 // The script has loaded but start has not completed yet.
1169 ASSERT_EQ(SERVICE_WORKER_ERROR_FAILED, status); 1169 ASSERT_EQ(SERVICE_WORKER_ERROR_FAILED, status);
1170 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, version_->running_status()); 1170 EXPECT_EQ(EmbeddedWorkerStatus::STARTING, version_->running_status());
1171 1171
1172 // Simulate execution timeout. Use a delay to prevent killing the worker 1172 // Simulate execution timeout. Use a delay to prevent killing the worker
1173 // before it's started execution. 1173 // before it's started execution.
1174 EXPECT_TRUE(version_->timeout_timer_.IsRunning());
1175 RunOnIOThreadWithDelay( 1174 RunOnIOThreadWithDelay(
horo 2017/04/27 02:33:12 Keep this as is, and call "version_->timeout_timer
gab 2017/04/27 14:56:04 RunOnIOThreadWithDelay is an anonymous method, it
horo 2017/04/27 15:49:52 TimeoutWorkerOnIOThread() have access to |version_
gab 2017/05/26 04:26:57 Done.
1176 base::Bind(&self::TimeoutWorkerOnIOThread, base::Unretained(this)), 1175 base::Bind(
1176 [](const base::Timer* timeout_timer, self* self) {
1177 EXPECT_TRUE(timeout_timer->IsRunning());
1178 self->TimeoutWorkerOnIOThread();
1179 },
1180 base::Unretained(&version_->timeout_timer_), base::Unretained(this)),
1177 base::TimeDelta::FromMilliseconds(100)); 1181 base::TimeDelta::FromMilliseconds(100));
1178 start_run_loop.Run(); 1182 start_run_loop.Run();
1179 1183
1180 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status); 1184 EXPECT_EQ(SERVICE_WORKER_ERROR_TIMEOUT, status);
1181 } 1185 }
1182 1186
1183 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, TimeoutWorkerInEvent) { 1187 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, TimeoutWorkerInEvent) {
1184 StartServerAndNavigateToSetup(); 1188 StartServerAndNavigateToSetup();
1185 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread, 1189 RunOnIOThread(base::Bind(&self::SetUpRegistrationOnIOThread,
1186 base::Unretained(this), 1190 base::Unretained(this),
(...skipping 11 matching lines...) Expand all
1198 1202
1199 // Dispatch an event. 1203 // Dispatch an event.
1200 base::RunLoop install_run_loop; 1204 base::RunLoop install_run_loop;
1201 BrowserThread::PostTask( 1205 BrowserThread::PostTask(
1202 BrowserThread::IO, FROM_HERE, 1206 BrowserThread::IO, FROM_HERE,
1203 base::Bind(&self::InstallOnIOThread, base::Unretained(this), 1207 base::Bind(&self::InstallOnIOThread, base::Unretained(this),
1204 install_run_loop.QuitClosure(), &status)); 1208 install_run_loop.QuitClosure(), &status));
1205 1209
1206 // Simulate execution timeout. Use a delay to prevent killing the worker 1210 // Simulate execution timeout. Use a delay to prevent killing the worker
1207 // before it's started execution. 1211 // before it's started execution.
1208 EXPECT_TRUE(version_->timeout_timer_.IsRunning());
1209 RunOnIOThreadWithDelay( 1212 RunOnIOThreadWithDelay(
1210 base::Bind(&self::TimeoutWorkerOnIOThread, base::Unretained(this)), 1213 base::Bind(
1214 [](const base::Timer* timeout_timer, self* self) {
1215 EXPECT_TRUE(timeout_timer->IsRunning());
1216 self->TimeoutWorkerOnIOThread();
1217 },
1218 base::Unretained(&version_->timeout_timer_), base::Unretained(this)),
1211 base::TimeDelta::FromMilliseconds(100)); 1219 base::TimeDelta::FromMilliseconds(100));
1212 install_run_loop.Run(); 1220 install_run_loop.Run();
1213 1221
1214 // Terminating a worker, even one in an infinite loop, is treated as if 1222 // Terminating a worker, even one in an infinite loop, is treated as if
1215 // waitUntil was rejected in the renderer code. 1223 // waitUntil was rejected in the renderer code.
1216 EXPECT_EQ(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, status); 1224 EXPECT_EQ(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, status);
1217 } 1225 }
1218 1226
1219 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) { 1227 IN_PROC_BROWSER_TEST_F(ServiceWorkerVersionBrowserTest, FetchEvent_Response) {
1220 StartServerAndNavigateToSetup(); 1228 StartServerAndNavigateToSetup();
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 // effect in CanSuspendRenderer(). 3016 // effect in CanSuspendRenderer().
3009 shell()->web_contents()->WasHidden(); 3017 shell()->web_contents()->WasHidden();
3010 EXPECT_TRUE(rph->IsProcessBackgrounded()); 3018 EXPECT_TRUE(rph->IsProcessBackgrounded());
3011 3019
3012 // The process which has service worker thread shouldn't be suspended. 3020 // The process which has service worker thread shouldn't be suspended.
3013 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id)); 3021 EXPECT_FALSE(memory_coordinator->CanSuspendRenderer(render_process_id));
3014 } 3022 }
3015 #endif 3023 #endif
3016 3024
3017 } // namespace content 3025 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698