Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/chromeos/arc/process/arc_process_unittest.cc

Issue 2853633002: Add arc_process_unittest.cc (Closed)
Patch Set: address comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 "chrome/browser/chromeos/arc/process/arc_process.h"
6
7 #include <assert.h>
8 #include <list>
9
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace arc {
13
14 namespace {
15
16 // Tests that ArcProcess objects can be sorted by their priority (higher to
17 // lower). This is critical for the OOM handler to work correctly.
18 TEST(ArcProcess, TestSorting) {
19 constexpr int64_t kNow = 1234567890;
20
21 std::list<ArcProcess> processes; // use list<> for emplace_front.
22 processes.emplace_back(0, 0, "process 0", mojom::ProcessState::PERSISTENT,
23 false /* is_foreground */, kNow + 1);
24 processes.emplace_front(1, 1, "process 1", mojom::ProcessState::PERSISTENT,
25 false, kNow);
26 processes.emplace_back(2, 2, "process 2", mojom::ProcessState::LAST_ACTIVITY,
27 false, kNow);
28 processes.emplace_front(3, 3, "process 3", mojom::ProcessState::LAST_ACTIVITY,
29 false, kNow + 1);
30 processes.emplace_back(4, 4, "process 4", mojom::ProcessState::CACHED_EMPTY,
31 false, kNow + 1);
32 processes.emplace_front(5, 5, "process 5", mojom::ProcessState::CACHED_EMPTY,
33 false, kNow);
34 processes.sort();
35
36 static_assert(
37 mojom::ProcessState::PERSISTENT < mojom::ProcessState::LAST_ACTIVITY,
38 "unexpected enum values");
39 static_assert(
40 mojom::ProcessState::LAST_ACTIVITY < mojom::ProcessState::CACHED_EMPTY,
41 "unexpected enum values");
42
43 std::list<ArcProcess>::const_iterator it = processes.begin();
44 // 0 should have higher priority since its last_activity_time is more recent.
45 EXPECT_EQ(0, it->pid());
46 ++it;
47 EXPECT_EQ(1, it->pid());
48 ++it;
49 // Same, 3 should have higher priority.
50 EXPECT_EQ(3, it->pid());
51 ++it;
52 EXPECT_EQ(2, it->pid());
53 ++it;
54 // Same, 4 should have higher priority.
55 EXPECT_EQ(4, it->pid());
56 ++it;
57 EXPECT_EQ(5, it->pid());
58 }
59
60 } // namespace
61
62 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698