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

Unified Diff: content/browser/service_worker/embedded_worker_instance_unittest.cc

Issue 2039743003: Introduce ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time UMA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/embedded_worker_instance_unittest.cc
diff --git a/content/browser/service_worker/embedded_worker_instance_unittest.cc b/content/browser/service_worker/embedded_worker_instance_unittest.cc
index 62e1ce66f6d39853c877a146c3621756a4afff6c..f2df6b57612e8242b411fa28ae93d1757f9ebd2b 100644
--- a/content/browser/service_worker/embedded_worker_instance_unittest.cc
+++ b/content/browser/service_worker/embedded_worker_instance_unittest.cc
@@ -12,6 +12,7 @@
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "content/browser/service_worker/embedded_worker_registry.h"
+#include "content/browser/service_worker/embedded_worker_status.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
@@ -61,12 +62,12 @@ class EmbeddedWorkerInstanceTest : public testing::Test,
struct EventLog {
EventType type;
- EmbeddedWorkerInstance::Status status;
+ EmbeddedWorkerStatus status;
};
void RecordEvent(
EventType type,
- EmbeddedWorkerInstance::Status status = EmbeddedWorkerInstance::STOPPED) {
+ EmbeddedWorkerStatus status = EmbeddedWorkerStatus::STOPPED) {
EventLog log = {type, status};
events_.push_back(log);
}
@@ -76,10 +77,10 @@ class EmbeddedWorkerInstanceTest : public testing::Test,
RecordEvent(START_WORKER_MESSAGE_SENT);
}
void OnStarted() override { RecordEvent(STARTED); }
- void OnStopped(EmbeddedWorkerInstance::Status old_status) override {
+ void OnStopped(EmbeddedWorkerStatus old_status) override {
RecordEvent(STOPPED, old_status);
}
- void OnDetached(EmbeddedWorkerInstance::Status old_status) override {
+ void OnDetached(EmbeddedWorkerStatus old_status) override {
RecordEvent(DETACHED, old_status);
}
@@ -164,7 +165,7 @@ class FailToSendIPCHelper : public EmbeddedWorkerTestHelper {
TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) {
std::unique_ptr<EmbeddedWorkerInstance> worker =
embedded_worker_registry()->CreateWorker();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
const int64_t service_worker_version_id = 55L;
const GURL pattern("http://example.com/");
@@ -181,23 +182,23 @@ TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) {
CreateStartParams(service_worker_version_id, pattern, url);
worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
run_loop.QuitClosure()));
- EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status());
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
// The 'WorkerStarted' message should have been sent by
// EmbeddedWorkerTestHelper.
- EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id());
// Stop the worker.
EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop());
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, worker->status());
base::RunLoop().RunUntilIdle();
// The 'WorkerStopped' message should have been sent by
// EmbeddedWorkerTestHelper.
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
// Verify that we've sent two messages to start and terminate the worker.
ASSERT_TRUE(
@@ -211,7 +212,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StartAndStop) {
TEST_F(EmbeddedWorkerInstanceTest, ForceNewProcess) {
std::unique_ptr<EmbeddedWorkerInstance> worker =
embedded_worker_registry()->CreateWorker();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
const int64_t service_worker_version_id = 55L;
const GURL pattern("http://example.com/");
@@ -238,7 +239,7 @@ TEST_F(EmbeddedWorkerInstanceTest, ForceNewProcess) {
run_loop.QuitClosure()));
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
- EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
// The worker should be using the default render process.
EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id());
@@ -260,11 +261,11 @@ TEST_F(EmbeddedWorkerInstanceTest, ForceNewProcess) {
CreateStartParams(service_worker_version_id, pattern, url));
worker->Start(std::move(params), base::Bind(&SaveStatusAndCall, &status,
run_loop.QuitClosure()));
- EXPECT_EQ(EmbeddedWorkerInstance::STARTING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STARTING, worker->status());
run_loop.Run();
EXPECT_EQ(SERVICE_WORKER_OK, status);
- EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
// The worker should be using the new render process.
EXPECT_EQ(helper_->new_render_process_id(), worker->process_id());
EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop());
@@ -275,7 +276,7 @@ TEST_F(EmbeddedWorkerInstanceTest, ForceNewProcess) {
TEST_F(EmbeddedWorkerInstanceTest, StopWhenDevToolsAttached) {
std::unique_ptr<EmbeddedWorkerInstance> worker =
embedded_worker_registry()->CreateWorker();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
const int64_t service_worker_version_id = 55L;
const GURL pattern("http://example.com/");
@@ -288,33 +289,33 @@ TEST_F(EmbeddedWorkerInstanceTest, StopWhenDevToolsAttached) {
// Start the worker and then call StopIfIdle().
EXPECT_EQ(SERVICE_WORKER_OK,
StartWorker(worker.get(), service_worker_version_id, pattern, url));
- EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id());
worker->StopIfIdle();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, worker->status());
base::RunLoop().RunUntilIdle();
// The worker must be stopped now.
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
// Set devtools_attached to true, and do the same.
worker->set_devtools_attached(true);
EXPECT_EQ(SERVICE_WORKER_OK,
StartWorker(worker.get(), service_worker_version_id, pattern, url));
- EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
EXPECT_EQ(helper_->mock_render_process_id(), worker->process_id());
worker->StopIfIdle();
base::RunLoop().RunUntilIdle();
// The worker must not be stopped this time.
- EXPECT_EQ(EmbeddedWorkerInstance::RUNNING, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, worker->status());
// Calling Stop() actually stops the worker regardless of whether devtools
// is attached or not.
EXPECT_EQ(SERVICE_WORKER_OK, worker->Stop());
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
}
// Test that the removal of a worker from the registry doesn't remove
@@ -392,7 +393,7 @@ TEST_F(EmbeddedWorkerInstanceTest, DetachDuringProcessAllocation) {
worker->Detach();
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id());
// The start callback should not be aborted by detach (see a comment on the
@@ -402,7 +403,7 @@ TEST_F(EmbeddedWorkerInstanceTest, DetachDuringProcessAllocation) {
// "PROCESS_ALLOCATED" event should not be recorded.
ASSERT_EQ(1u, events_.size());
EXPECT_EQ(DETACHED, events_[0].type);
- EXPECT_EQ(EmbeddedWorkerInstance::STARTING, events_[0].status);
+ EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[0].status);
}
TEST_F(EmbeddedWorkerInstanceTest, DetachAfterSendingStartWorkerMessage) {
@@ -431,7 +432,7 @@ TEST_F(EmbeddedWorkerInstanceTest, DetachAfterSendingStartWorkerMessage) {
worker->Detach();
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id());
// The start callback should not be aborted by detach (see a comment on the
@@ -441,7 +442,7 @@ TEST_F(EmbeddedWorkerInstanceTest, DetachAfterSendingStartWorkerMessage) {
// "STARTED" event should not be recorded.
ASSERT_EQ(1u, events_.size());
EXPECT_EQ(DETACHED, events_[0].type);
- EXPECT_EQ(EmbeddedWorkerInstance::STARTING, events_[0].status);
+ EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[0].status);
}
TEST_F(EmbeddedWorkerInstanceTest, StopDuringProcessAllocation) {
@@ -463,7 +464,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopDuringProcessAllocation) {
worker->Stop();
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id());
// The start callback should not be aborted by stop (see a comment on the dtor
@@ -473,7 +474,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopDuringProcessAllocation) {
// "PROCESS_ALLOCATED" event should not be recorded.
ASSERT_EQ(1u, events_.size());
EXPECT_EQ(DETACHED, events_[0].type);
- EXPECT_EQ(EmbeddedWorkerInstance::STARTING, events_[0].status);
+ EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[0].status);
events_.clear();
// Restart the worker.
@@ -520,7 +521,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopDuringPausedAfterDownload) {
base::RunLoop().RunUntilIdle();
// The resume after download message should not have been sent.
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
EXPECT_FALSE(ipc_sink()->GetFirstMessageMatching(
EmbeddedWorkerMsg_ResumeAfterDownload::ID));
}
@@ -551,7 +552,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) {
worker->Stop();
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
EXPECT_EQ(ChildProcessHost::kInvalidUniqueID, worker->process_id());
// The start callback should not be aborted by stop (see a comment on the dtor
@@ -561,7 +562,7 @@ TEST_F(EmbeddedWorkerInstanceTest, StopAfterSendingStartWorkerMessage) {
// "STARTED" event should not be recorded.
ASSERT_EQ(1u, events_.size());
EXPECT_EQ(STOPPED, events_[0].type);
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPING, events_[0].status);
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPING, events_[0].status);
events_.clear();
// Restart the worker.
@@ -608,13 +609,13 @@ TEST_F(EmbeddedWorkerInstanceTest, Detach) {
// Detach.
int process_id = worker->process_id();
worker->Detach();
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
// Send the registry a message from the detached worker. Nothing should
// happen.
embedded_worker_registry()->OnWorkerStarted(process_id,
worker->embedded_worker_id());
- EXPECT_EQ(EmbeddedWorkerInstance::STOPPED, worker->status());
+ EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, worker->status());
}
// Test for when sending the start IPC failed.
@@ -645,7 +646,7 @@ TEST_F(EmbeddedWorkerInstanceTest, FailToSendStartIPC) {
ASSERT_EQ(2u, events_.size());
EXPECT_EQ(PROCESS_ALLOCATED, events_[0].type);
EXPECT_EQ(STOPPED, events_[1].type);
- EXPECT_EQ(EmbeddedWorkerInstance::STARTING, events_[1].status);
+ EXPECT_EQ(EmbeddedWorkerStatus::STARTING, events_[1].status);
}
} // namespace content
« no previous file with comments | « content/browser/service_worker/embedded_worker_instance.cc ('k') | content/browser/service_worker/embedded_worker_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698