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) {} | |
18 | |
19 virtual void SetUp() OVERRIDE { | |
20 process_manager_.reset(new ServiceWorkerProcessManager(NULL)); | |
21 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.
| |
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 1 ref, 2 has 2 refs and 3 has 3 refs. | |
39 process_manager_->AddScopeProcessReference(scope_, 1); | |
40 process_manager_->AddScopeProcessReference(scope_, 2); | |
41 process_manager_->AddScopeProcessReference(scope_, 2); | |
42 process_manager_->AddScopeProcessReference(scope_, 3); | |
43 process_manager_->AddScopeProcessReference(scope_, 3); | |
44 process_manager_->AddScopeProcessReference(scope_, 3); | |
45 | |
46 // 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.
| |
47 EXPECT_THAT(process_manager_->SortProcessesForScope(scope_), | |
48 testing::ElementsAre(3, 2, 1)); | |
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. | |
60 EXPECT_THAT(process_manager_->SortProcessesForScope(scope_), | |
61 testing::ElementsAre(3, 2, 1, 4)); | |
62 } | |
63 | |
64 } // namespace content | |
OLD | NEW |