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 ServiceWorkerProcessManagerTest() | |
17 : 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.
| |
18 | |
19 virtual void SetUp() OVERRIDE { | |
20 process_manager_.reset(new ServiceWorkerProcessManager(NULL)); | |
21 scope_ = GURL("http://www.example.com/"); | |
22 } | |
23 | |
24 virtual void TearDown() OVERRIDE { | |
25 process_manager_.reset(); | |
26 } | |
27 | |
28 protected: | |
29 TestBrowserThreadBundle thread_bundle_; | |
30 scoped_ptr<ServiceWorkerProcessManager> process_manager_; | |
31 GURL scope_; | |
32 | |
33 private: | |
34 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProcessManagerTest); | |
35 }; | |
36 | |
37 TEST_F(ServiceWorkerProcessManagerTest, SortProcess) { | |
38 // Process 1 has 2 ref, 2 has 3 refs and 3 has 1 refs. | |
39 process_manager_->AddScopeProcessReference(scope_, 1); | |
40 process_manager_->AddScopeProcessReference(scope_, 1); | |
41 process_manager_->AddScopeProcessReference(scope_, 2); | |
42 process_manager_->AddScopeProcessReference(scope_, 2); | |
43 process_manager_->AddScopeProcessReference(scope_, 2); | |
44 process_manager_->AddScopeProcessReference(scope_, 3); | |
45 | |
46 // Process 2 has the biggest # of references and it should be chosen. | |
47 EXPECT_THAT(process_manager_->SortProcessesForScope(scope_), | |
48 testing::ElementsAre(2, 1, 3)); | |
49 | |
50 // Pending processes will be added with lowest priority and will only be | |
51 // added once. | |
52 process_manager_->SetProcessIdForTest(4); | |
53 std::vector<int> registering_processes; | |
54 registering_processes.push_back(1); | |
55 registering_processes.push_back(1); | |
56 registering_processes.push_back(4); | |
57 registering_processes.push_back(4); | |
58 process_manager_->AddScopePendingProcesses(scope_, registering_processes); | |
59 // 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.
| |
60 EXPECT_THAT(process_manager_->SortProcessesForScope(scope_), | |
61 testing::ElementsAre(2, 1, 3, 4)); | |
62 | |
63 process_manager_->RemoveScopeProcessReference(scope_, 1); | |
64 process_manager_->RemoveScopeProcessReference(scope_, 1); | |
65 process_manager_->AddScopeProcessReference(scope_, 4); | |
66 process_manager_->AddScopeProcessReference(scope_, 4); | |
67 // Scores for each process: 2 : 3, 3 : 1, 4 : 2, process 1 is removed. | |
68 EXPECT_THAT(process_manager_->SortProcessesForScope(scope_), | |
69 testing::ElementsAre(2, 4, 3)); | |
70 } | |
71 | |
72 } // namespace content | |
OLD | NEW |