OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 7 #include "content/public/test/test_browser_thread_bundle.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "url/gurl.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 class ServiceWorkerProcessManagerTest : public testing::Test { |
| 15 public: |
| 16 virtual void SetUp() OVERRIDE { |
| 17 process_manager_.reset(new ServiceWorkerProcessManager(NULL)); |
| 18 pattern_ = GURL("http://www.example.com/"); |
| 19 } |
| 20 |
| 21 virtual void TearDown() OVERRIDE { |
| 22 process_manager_.reset(); |
| 23 } |
| 24 |
| 25 protected: |
| 26 TestBrowserThreadBundle thread_bundle_; |
| 27 scoped_ptr<ServiceWorkerProcessManager> process_manager_; |
| 28 GURL pattern_; |
| 29 |
| 30 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProcessManagerTest); |
| 32 }; |
| 33 |
| 34 TEST_F(ServiceWorkerProcessManagerTest, SortProcess) { |
| 35 // Process 1 has 2 ref, 2 has 3 refs and 3 has 1 refs. |
| 36 process_manager_->AddProcessReferenceToPattern(pattern_, 1); |
| 37 process_manager_->AddProcessReferenceToPattern(pattern_, 1); |
| 38 process_manager_->AddProcessReferenceToPattern(pattern_, 2); |
| 39 process_manager_->AddProcessReferenceToPattern(pattern_, 2); |
| 40 process_manager_->AddProcessReferenceToPattern(pattern_, 2); |
| 41 process_manager_->AddProcessReferenceToPattern(pattern_, 3); |
| 42 |
| 43 // Process 2 has the biggest # of references and it should be chosen. |
| 44 EXPECT_THAT(process_manager_->SortProcessesForPattern(pattern_), |
| 45 testing::ElementsAre(2, 1, 3)); |
| 46 |
| 47 process_manager_->RemoveProcessReferenceFromPattern(pattern_, 1); |
| 48 process_manager_->RemoveProcessReferenceFromPattern(pattern_, 1); |
| 49 // Scores for each process: 2 : 3, 3 : 1, process 1 is removed. |
| 50 EXPECT_THAT(process_manager_->SortProcessesForPattern(pattern_), |
| 51 testing::ElementsAre(2, 3)); |
| 52 } |
| 53 |
| 54 } // namespace content |
OLD | NEW |