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

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

Issue 294073009: Save running SW instance info, including its SiteInstance, into the ProcessManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test SortProcesses without doing all the work to Start an instance. Created 6 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 | 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"
11 #include "content/browser/service_worker/service_worker_context_core.h" 11 #include "content/browser/service_worker/service_worker_context_core.h"
12 #include "content/browser/service_worker/service_worker_context_wrapper.h" 12 #include "content/browser/service_worker/service_worker_context_wrapper.h"
13 #include "content/common/service_worker/embedded_worker_messages.h" 13 #include "content/common/service_worker/embedded_worker_messages.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace content { 18 namespace content {
18 19
19 static const int kRenderProcessId = 11; 20 static const int kRenderProcessId = 11;
20 21
21 class EmbeddedWorkerInstanceTest : public testing::Test { 22 class EmbeddedWorkerInstanceTest : public testing::Test {
22 protected: 23 protected:
23 EmbeddedWorkerInstanceTest() 24 EmbeddedWorkerInstanceTest()
24 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} 25 : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // But destroy it before it gets a chance to complete. 123 // But destroy it before it gets a chance to complete.
123 worker.reset(); 124 worker.reset();
124 run_loop.Run(); 125 run_loop.Run();
125 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, status); 126 EXPECT_EQ(SERVICE_WORKER_ERROR_ABORT, status);
126 127
127 // Verify that we didn't send the message to start the worker. 128 // Verify that we didn't send the message to start the worker.
128 ASSERT_FALSE( 129 ASSERT_FALSE(
129 ipc_sink()->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID)); 130 ipc_sink()->GetUniqueMessageMatching(EmbeddedWorkerMsg_StartWorker::ID));
130 } 131 }
131 132
132 TEST_F(EmbeddedWorkerInstanceTest, ChooseProcess) { 133 TEST_F(EmbeddedWorkerInstanceTest, SortProcesses) {
133 scoped_ptr<EmbeddedWorkerInstance> worker = 134 scoped_ptr<EmbeddedWorkerInstance> worker =
134 embedded_worker_registry()->CreateWorker(); 135 embedded_worker_registry()->CreateWorker();
135 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status()); 136 EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
136 137
137 // Simulate adding processes to the worker. 138 // Simulate adding processes to the worker.
138 // Process 1 has 1 ref, 2 has 2 refs and 3 has 3 refs. 139 // Process 1 has 1 ref, 2 has 2 refs and 3 has 3 refs.
139 const int embedded_worker_id = worker->embedded_worker_id(); 140 const int embedded_worker_id = worker->embedded_worker_id();
140 helper_->SimulateAddProcessToWorker(embedded_worker_id, 1); 141 helper_->SimulateAddProcessToWorker(embedded_worker_id, 1);
141 helper_->SimulateAddProcessToWorker(embedded_worker_id, 2); 142 helper_->SimulateAddProcessToWorker(embedded_worker_id, 2);
142 helper_->SimulateAddProcessToWorker(embedded_worker_id, 2); 143 helper_->SimulateAddProcessToWorker(embedded_worker_id, 2);
143 helper_->SimulateAddProcessToWorker(embedded_worker_id, 3); 144 helper_->SimulateAddProcessToWorker(embedded_worker_id, 3);
144 helper_->SimulateAddProcessToWorker(embedded_worker_id, 3); 145 helper_->SimulateAddProcessToWorker(embedded_worker_id, 3);
145 helper_->SimulateAddProcessToWorker(embedded_worker_id, 3); 146 helper_->SimulateAddProcessToWorker(embedded_worker_id, 3);
146 147
147 // Process 3 has the biggest # of references and it should be chosen. 148 // Process 3 has the biggest # of references and it should be chosen.
148 ServiceWorkerStatusCode status; 149 EXPECT_THAT(worker->SortProcesses(std::vector<int>()),
149 base::RunLoop run_loop; 150 testing::ElementsAre(3, 2, 1));
kinuko 2014/05/23 02:53:23 Neat, didn't know this notation.
150 worker->Start( 151 EXPECT_EQ(-1, worker->process_id());
151 1L,
152 GURL("http://example.com/*"),
153 GURL("http://example.com/worker.js"),
154 std::vector<int>(),
155 base::Bind(&SaveStatusAndCall, &status, run_loop.QuitClosure()));
156 run_loop.Run();
157 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status);
158 EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status());
159 EXPECT_EQ(3, worker->process_id());
160 152
161 // Wait until started message is sent back. 153 // Argument processes are added to the existing set, but only for a single
162 base::RunLoop().RunUntilIdle(); 154 // call.
163 EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status()); 155 std::vector<int> registering_processes;
156 registering_processes.push_back(1);
157 registering_processes.push_back(1);
158 registering_processes.push_back(1);
159 registering_processes.push_back(4);
160 EXPECT_THAT(worker->SortProcesses(registering_processes),
161 testing::ElementsAre(1, 3, 2, 4));
162
163 EXPECT_THAT(worker->SortProcesses(std::vector<int>()),
164 testing::ElementsAre(3, 2, 1));
164 } 165 }
165 166
166 } // namespace content 167 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698