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..7b68fa11188eea840ac6c4405b09c5aba7043337 |
--- /dev/null |
+++ b/content/browser/service_worker/service_worker_process_manager_unittest.cc |
@@ -0,0 +1,72 @@ |
+// 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) {} |
Jeffrey Yasskin
2014/08/19 23:42:24
You may not need IO_MAINLOOP. BrowserThread::Curre
xiang
2014/08/29 07:49:40
Done.
|
+ |
+ virtual void SetUp() OVERRIDE { |
+ process_manager_.reset(new ServiceWorkerProcessManager(NULL)); |
+ scope_ = GURL("http://www.example.com/"); |
+ } |
+ |
+ 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 2 ref, 2 has 3 refs and 3 has 1 refs. |
+ process_manager_->AddScopeProcessReference(scope_, 1); |
+ process_manager_->AddScopeProcessReference(scope_, 1); |
+ process_manager_->AddScopeProcessReference(scope_, 2); |
+ process_manager_->AddScopeProcessReference(scope_, 2); |
+ process_manager_->AddScopeProcessReference(scope_, 2); |
+ process_manager_->AddScopeProcessReference(scope_, 3); |
+ |
+ // Process 2 has the biggest # of references and it should be chosen. |
+ EXPECT_THAT(process_manager_->SortProcessesForScope(scope_), |
+ testing::ElementsAre(2, 1, 3)); |
+ |
+ // 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. |
Jeffrey Yasskin
2014/08/19 23:42:24
s/change/changed/
xiang
2014/08/29 07:49:40
this test is removed.
|
+ EXPECT_THAT(process_manager_->SortProcessesForScope(scope_), |
+ testing::ElementsAre(2, 1, 3, 4)); |
+ |
+ process_manager_->RemoveScopeProcessReference(scope_, 1); |
+ process_manager_->RemoveScopeProcessReference(scope_, 1); |
+ process_manager_->AddScopeProcessReference(scope_, 4); |
+ process_manager_->AddScopeProcessReference(scope_, 4); |
+ // Scores for each process: 2 : 3, 3 : 1, 4 : 2, process 1 is removed. |
+ EXPECT_THAT(process_manager_->SortProcessesForScope(scope_), |
+ testing::ElementsAre(2, 4, 3)); |
+} |
+ |
+} // namespace content |