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

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

Issue 443593002: ServiceWorker: Move worker candidate process knowledge to ServiceWorkerProcessManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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/service_worker_process_manager_unittest.cc
diff --git a/content/browser/service_worker/service_worker_process_manager_unittest.cc b/content/browser/service_worker/service_worker_process_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d0d06f8615d4c353befd920f155075d95ff92559
--- /dev/null
+++ b/content/browser/service_worker/service_worker_process_manager_unittest.cc
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "content/browser/service_worker/service_worker_process_manager.h"
+#include "content/public/test/test_browser_thread_bundle.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace content {
+
+class ServiceWorkerProcessManagerTest : public testing::Test {
+ public:
+ ServiceWorkerProcessManagerTest()
+ : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {}
+
+ virtual void SetUp() OVERRIDE {
+ process_manager_.reset(new ServiceWorkerProcessManager(NULL));
+ scope_ = GURL("http://www.example.com/*");
dominicc (has gone to gerrit) 2014/08/06 06:48:18 Here too.
xiang 2014/08/11 04:50:55 Done.
+ }
+
+ virtual void TearDown() OVERRIDE {
+ process_manager_.reset();
+ }
+
+ protected:
+ TestBrowserThreadBundle thread_bundle_;
+ scoped_ptr<ServiceWorkerProcessManager> process_manager_;
+ GURL scope_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProcessManagerTest);
+};
+
+TEST_F(ServiceWorkerProcessManagerTest, SortProcess) {
+ // Process 1 has 1 ref, 2 has 2 refs and 3 has 3 refs.
+ process_manager_->AddScopeProcessReference(scope_, 1);
+ process_manager_->AddScopeProcessReference(scope_, 2);
+ process_manager_->AddScopeProcessReference(scope_, 2);
+ process_manager_->AddScopeProcessReference(scope_, 3);
+ process_manager_->AddScopeProcessReference(scope_, 3);
+ process_manager_->AddScopeProcessReference(scope_, 3);
+
+ // Process 3 has the biggest # of references and it should be chosen.
dominicc (has gone to gerrit) 2014/08/06 06:48:18 The test would be more discriminative if the outpu
xiang 2014/08/11 04:50:55 Done.
+ EXPECT_THAT(process_manager_->SortProcessesForScope(scope_),
+ testing::ElementsAre(3, 2, 1));
+
+ // Pending processes will be added with lowest priority and will only be
+ // added once.
+ process_manager_->SetProcessIdForTest(4);
+ std::vector<int> registering_processes;
+ registering_processes.push_back(1);
+ registering_processes.push_back(1);
+ registering_processes.push_back(4);
+ registering_processes.push_back(4);
+ process_manager_->AddScopePendingProcesses(scope_, registering_processes);
+ // Scores for processes 1, 2, 3 are not change, process 4's score is 0.
+ EXPECT_THAT(process_manager_->SortProcessesForScope(scope_),
+ testing::ElementsAre(3, 2, 1, 4));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698