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

Unified Diff: chrome/browser/chromeos/arc/process/arc_process_unittest.cc

Issue 2853633002: Add arc_process_unittest.cc (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/arc/process/arc_process_unittest.cc
diff --git a/chrome/browser/chromeos/arc/process/arc_process_unittest.cc b/chrome/browser/chromeos/arc/process/arc_process_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..546d061deffbf57604505f87f0c2709aa4bb6827
--- /dev/null
+++ b/chrome/browser/chromeos/arc/process/arc_process_unittest.cc
@@ -0,0 +1,55 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/arc/process/arc_process.h"
+
+#include <list>
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace arc {
Luis Héctor Chávez 2017/05/01 15:19:51 What was the final decision as to having the test
Yusuke Sato 2017/05/01 17:59:52 Good catch. The last conversation I remember was h
+
+// Tests that ArcProcess objects can be sorted by their priority (higher to
+// lower). This is critical for the OOM handler to work correctly.
+TEST(ArcProcess, TestSorting) {
+ const int64_t kNow = 1234567890;
Luis Héctor Chávez 2017/05/01 15:19:51 nit: constexpr
Yusuke Sato 2017/05/01 17:59:52 Done.
+
+ std::list<ArcProcess> processes;
hidehiko 2017/05/01 05:24:48 IIUC, list is used to avoid copying ArcProcess on
Yusuke Sato 2017/05/01 17:59:52 No strong reason actually, used it just for emplac
hidehiko 2017/05/02 05:43:08 In future, if emplace_front is just a reason, prob
+ processes.emplace_back(0, 0, "process 0", mojom::ProcessState::PERSISTENT,
+ false /* is_foreground */, kNow + 1);
+ processes.emplace_front(1, 1, "process 1", mojom::ProcessState::PERSISTENT,
+ false, kNow);
+ processes.emplace_back(2, 2, "process 2", mojom::ProcessState::LAST_ACTIVITY,
+ false, kNow);
+ processes.emplace_front(3, 3, "process 3", mojom::ProcessState::LAST_ACTIVITY,
+ false, kNow + 1);
+ processes.emplace_back(4, 4, "process 4", mojom::ProcessState::CACHED_EMPTY,
+ false, kNow + 1);
+ processes.emplace_front(5, 5, "process 5", mojom::ProcessState::CACHED_EMPTY,
+ false, kNow);
+ processes.sort();
+
+ ASSERT_LT(mojom::ProcessState::PERSISTENT,
Luis Héctor Chávez 2017/05/01 15:19:51 This can be done as a static assert (in arc_proces
Yusuke Sato 2017/05/01 17:59:52 Done.
+ mojom::ProcessState::LAST_ACTIVITY);
+ ASSERT_LT(mojom::ProcessState::LAST_ACTIVITY,
+ mojom::ProcessState::CACHED_EMPTY);
+
+ std::list<ArcProcess>::const_iterator it = processes.begin();
+ // 0 should have higher priority since its last_activity_time is more recent.
+ EXPECT_EQ(0, it->pid());
+ ++it;
+ EXPECT_EQ(1, it->pid());
+ ++it;
+ // Same, 3 should have higher priority.
+ EXPECT_EQ(3, it->pid());
+ ++it;
+ EXPECT_EQ(2, it->pid());
+ ++it;
+ // Same, 4 should have higher priority.
+ EXPECT_EQ(4, it->pid());
+ ++it;
+ EXPECT_EQ(5, it->pid());
+}
+
+} // namespace arc
« 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