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 |