Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / memory / oom_priority_manager_delegate_chromeos_unittest.cc
blob4b73b6edf74c639842bac6ed0992d47abd8d77c3
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/memory/oom_priority_manager.h"
7 #include <algorithm>
8 #include <vector>
10 #include "base/logging.h"
11 #include "base/strings/string16.h"
12 #include "base/time/time.h"
13 #include "chrome/browser/memory/oom_priority_manager_delegate_chromeos.h"
14 #include "chrome/browser/memory/tab_stats.h"
15 #include "chrome/common/url_constants.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h"
19 namespace memory {
21 typedef testing::Test OomPriorityManagerDelegateTest;
23 TEST_F(OomPriorityManagerDelegateTest, GetProcessHandles) {
24 TabStats stats;
25 std::vector<OomPriorityManagerDelegate::ProcessInfo> process_id_pairs;
27 // Empty stats list gives empty |process_id_pairs| list.
28 TabStatsList empty_list;
29 process_id_pairs =
30 OomPriorityManagerDelegate::GetChildProcessInfos(empty_list);
31 EXPECT_EQ(0u, process_id_pairs.size());
33 // Two tabs in two different processes generates two
34 // |child_process_host_id| out.
35 TabStatsList two_list;
36 stats.child_process_host_id = 100;
37 stats.renderer_handle = 101;
38 two_list.push_back(stats);
39 stats.child_process_host_id = 200;
40 stats.renderer_handle = 201;
41 two_list.push_back(stats);
42 process_id_pairs = OomPriorityManagerDelegate::GetChildProcessInfos(two_list);
43 EXPECT_EQ(2u, process_id_pairs.size());
44 EXPECT_EQ(100, process_id_pairs[0].first);
45 EXPECT_EQ(101, process_id_pairs[0].second);
46 EXPECT_EQ(200, process_id_pairs[1].first);
47 EXPECT_EQ(201, process_id_pairs[1].second);
49 // Zero handles are removed.
50 TabStatsList zero_handle_list;
51 stats.child_process_host_id = 100;
52 stats.renderer_handle = 0;
53 zero_handle_list.push_back(stats);
54 process_id_pairs =
55 OomPriorityManagerDelegate::GetChildProcessInfos(zero_handle_list);
56 EXPECT_EQ(0u, process_id_pairs.size());
58 // Two tabs in the same process generates one handle out. When a duplicate
59 // occurs the later instance is dropped.
60 TabStatsList same_process_list;
61 stats.child_process_host_id = 100;
62 stats.renderer_handle = 101;
63 same_process_list.push_back(stats);
64 stats.child_process_host_id = 200;
65 stats.renderer_handle = 201;
66 same_process_list.push_back(stats);
67 stats.child_process_host_id = 300;
68 stats.renderer_handle = 101; // Duplicate.
69 same_process_list.push_back(stats);
70 process_id_pairs =
71 OomPriorityManagerDelegate::GetChildProcessInfos(same_process_list);
72 EXPECT_EQ(2u, process_id_pairs.size());
73 EXPECT_EQ(100, process_id_pairs[0].first);
74 EXPECT_EQ(101, process_id_pairs[0].second);
75 EXPECT_EQ(200, process_id_pairs[1].first);
76 EXPECT_EQ(201, process_id_pairs[1].second);
79 } // namespace memory