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

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

Issue 147593006: Refine error code returned by ServiceWorkerVersion::StartWorker (e.g. PROCESS_NOT_FOUND etc) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 scoped_ptr<EmbeddedWorkerInstance> worker = 48 scoped_ptr<EmbeddedWorkerInstance> worker =
49 embedded_worker_registry()->CreateWorker(); 49 embedded_worker_registry()->CreateWorker();
50 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); 50 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
51 51
52 const int embedded_worker_id = worker->embedded_worker_id(); 52 const int embedded_worker_id = worker->embedded_worker_id();
53 const int process_id = 11; 53 const int process_id = 11;
54 const int64 service_worker_version_id = 55L; 54 const int64 service_worker_version_id = 55L;
55 const GURL url("http://example.com/worker.js"); 55 const GURL url("http://example.com/worker.js");
56 56
57 // This fails as we have no available process yet. 57 // This fails as we have no available process yet.
58 EXPECT_FALSE(worker->Start(service_worker_version_id, url)); 58 EXPECT_EQ(SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND,
59 worker->Start(service_worker_version_id, url));
59 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); 60 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
60 61
61 // Simulate adding one process to the worker. 62 // Simulate adding one process to the worker.
62 helper_->SimulateAddProcess(embedded_worker_id, process_id); 63 helper_->SimulateAddProcess(embedded_worker_id, process_id);
63 64
64 // Start should succeed. 65 // Start should succeed.
65 EXPECT_TRUE(worker->Start(service_worker_version_id, url)); 66 EXPECT_EQ(SERVICE_WORKER_OK,
67 worker->Start(service_worker_version_id, url));
66 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status()); 68 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status());
67 base::RunLoop().RunUntilIdle(); 69 base::RunLoop().RunUntilIdle();
68 70
69 // Worker started message should be notified (by EmbeddedWorkerTestHelper). 71 // Worker started message should be notified (by EmbeddedWorkerTestHelper).
70 EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status()); 72 EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
71 EXPECT_EQ(process_id, worker->process_id()); 73 EXPECT_EQ(process_id, worker->process_id());
72 74
73 // Stop the worker. 75 // Stop the worker.
74 EXPECT_TRUE(worker->Stop()); 76 EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop());
75 EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status()); 77 EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status());
76 base::RunLoop().RunUntilIdle(); 78 base::RunLoop().RunUntilIdle();
77 79
78 // Worker stopped message should be notified (by EmbeddedWorkerTestHelper). 80 // Worker stopped message should be notified (by EmbeddedWorkerTestHelper).
79 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); 81 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
80 82
81 // Verify that we've sent two messages to start and terminate the worker. 83 // Verify that we've sent two messages to start and terminate the worker.
82 ASSERT_TRUE(ipc_sink()->GetUniqueMessageMatching( 84 ASSERT_TRUE(ipc_sink()->GetUniqueMessageMatching(
83 EmbeddedWorkerMsg_StartWorker::ID)); 85 EmbeddedWorkerMsg_StartWorker::ID));
84 ASSERT_TRUE(ipc_sink()->GetUniqueMessageMatching( 86 ASSERT_TRUE(ipc_sink()->GetUniqueMessageMatching(
85 EmbeddedWorkerMsg_StopWorker::ID)); 87 EmbeddedWorkerMsg_StopWorker::ID));
86 } 88 }
87 89
88 TEST_F(EmbeddedWorkerInstanceTest, ChooseProcess) { 90 TEST_F(EmbeddedWorkerInstanceTest, ChooseProcess) {
89 scoped_ptr<EmbeddedWorkerInstance> worker = 91 scoped_ptr<EmbeddedWorkerInstance> worker =
90 embedded_worker_registry()->CreateWorker(); 92 embedded_worker_registry()->CreateWorker();
91 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); 93 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
92 94
93 // Simulate adding processes to the worker. 95 // Simulate adding processes to the worker.
94 // Process 1 has 1 ref, 2 has 2 refs and 3 has 3 refs. 96 // Process 1 has 1 ref, 2 has 2 refs and 3 has 3 refs.
95 const int embedded_worker_id = worker->embedded_worker_id(); 97 const int embedded_worker_id = worker->embedded_worker_id();
96 helper_->SimulateAddProcess(embedded_worker_id, 1); 98 helper_->SimulateAddProcess(embedded_worker_id, 1);
97 helper_->SimulateAddProcess(embedded_worker_id, 2); 99 helper_->SimulateAddProcess(embedded_worker_id, 2);
98 helper_->SimulateAddProcess(embedded_worker_id, 2); 100 helper_->SimulateAddProcess(embedded_worker_id, 2);
99 helper_->SimulateAddProcess(embedded_worker_id, 3); 101 helper_->SimulateAddProcess(embedded_worker_id, 3);
100 helper_->SimulateAddProcess(embedded_worker_id, 3); 102 helper_->SimulateAddProcess(embedded_worker_id, 3);
101 helper_->SimulateAddProcess(embedded_worker_id, 3); 103 helper_->SimulateAddProcess(embedded_worker_id, 3);
102 104
103 // Process 3 has the biggest # of references and it should be chosen. 105 // Process 3 has the biggest # of references and it should be chosen.
104 EXPECT_TRUE(worker->Start(1L, GURL("http://example.com/worker.js"))); 106 EXPECT_EQ(SERVICE_WORKER_OK,
107 worker->Start(1L, GURL("http://example.com/worker.js")));
105 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status()); 108 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status());
106 EXPECT_EQ(3, worker->process_id()); 109 EXPECT_EQ(3, worker->process_id());
107 110
108 // Wait until started message is sent back. 111 // Wait until started message is sent back.
109 base::RunLoop().RunUntilIdle(); 112 base::RunLoop().RunUntilIdle();
110 EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status()); 113 EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
111 } 114 }
112 115
113 } // namespace content 116 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/embedded_worker_instance.cc ('k') | content/browser/service_worker/embedded_worker_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698