OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "content/browser/service_worker/embedded_worker_instance.h" | 8 #include "content/browser/service_worker/embedded_worker_instance.h" |
9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 // Start should succeed. | 68 // Start should succeed. |
69 ServiceWorkerStatusCode status; | 69 ServiceWorkerStatusCode status; |
70 base::RunLoop run_loop; | 70 base::RunLoop run_loop; |
71 worker->Start( | 71 worker->Start( |
72 service_worker_version_id, | 72 service_worker_version_id, |
73 pattern, | 73 pattern, |
74 url, | 74 url, |
75 false, | 75 false, |
76 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); | 76 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure())); |
| 77 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status()); |
77 run_loop.Run(); | 78 run_loop.Run(); |
78 EXPECT_EQ(SERVICE_WORKER_OK, status); | 79 EXPECT_EQ(SERVICE_WORKER_OK, status); |
79 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status()); | |
80 base::RunLoop().RunUntilIdle(); | |
81 | 80 |
82 // Worker started message should be notified (by EmbeddedWorkerTestHelper). | 81 // The 'WorkerStarted' message should have been sent by |
| 82 // EmbeddedWorkerTestHelper. |
83 EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status()); | 83 EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status()); |
84 EXPECT_EQ(kRenderProcessId, worker->process_id()); | 84 EXPECT_EQ(kRenderProcessId, worker->process_id()); |
85 | 85 |
86 // Stop the worker. | 86 // Stop the worker. |
87 EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop()); | 87 EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop()); |
88 EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status()); | 88 EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status()); |
89 base::RunLoop().RunUntilIdle(); | 89 base::RunLoop().RunUntilIdle(); |
90 | 90 |
91 // Worker stopped message should be notified (by EmbeddedWorkerTestHelper). | 91 // The 'WorkerStopped' message should have been sent by |
| 92 // EmbeddedWorkerTestHelper. |
92 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); | 93 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); |
93 | 94 |
94 // Verify that we've sent two messages to start and terminate the worker. | 95 // Verify that we've sent two messages to start and terminate the worker. |
95 ASSERT_TRUE(ipc_sink()->GetUniqueMessageMatching( | 96 ASSERT_TRUE(ipc_sink()->GetUniqueMessageMatching( |
96 EmbeddedWorkerMsg_StartWorker::ID)); | 97 EmbeddedWorkerMsg_StartWorker::ID)); |
97 ASSERT_TRUE(ipc_sink()->GetUniqueMessageMatching( | 98 ASSERT_TRUE(ipc_sink()->GetUniqueMessageMatching( |
98 EmbeddedWorkerMsg_StopWorker::ID)); | 99 EmbeddedWorkerMsg_StopWorker::ID)); |
99 } | 100 } |
100 | 101 |
101 TEST_F(EmbeddedWorkerInstanceTest, InstanceDestroyedBeforeStartFinishes) { | 102 TEST_F(EmbeddedWorkerInstanceTest, InstanceDestroyedBeforeStartFinishes) { |
(...skipping 20 matching lines...) Expand all Loading... |
122 worker.reset(); | 123 worker.reset(); |
123 run_loop.Run(); | 124 run_loop.Run(); |
124 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, status); | 125 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, status); |
125 | 126 |
126 // Verify that we didn't send the message to start the worker. | 127 // Verify that we didn't send the message to start the worker. |
127 ASSERT_FALSE( | 128 ASSERT_FALSE( |
128 ipc_sink()->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID)); | 129 ipc_sink()->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID)); |
129 } | 130 } |
130 | 131 |
131 } // namespace content | 132 } // namespace content |
OLD | NEW |