Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / job_queue_unittest.cc
blob08d2ced1322b4d0ecc8b3e255316f0a1e591e56d
1 // Copyright 2013 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/chromeos/drive/job_queue.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace drive {
11 TEST(JobQueueTest, BasicJobQueueOperations) {
12 const int kNumMaxConcurrentJobs = 3;
13 const int kNumPriorityLevels = 2;
14 enum {HIGH_PRIORITY, LOW_PRIORITY};
16 // Create a queue. Number of jobs are initially zero.
17 JobQueue queue(kNumMaxConcurrentJobs, kNumPriorityLevels);
18 EXPECT_EQ(0U, queue.GetNumberOfJobs());
20 // Push 4 jobs.
21 queue.Push(101, LOW_PRIORITY);
22 queue.Push(102, HIGH_PRIORITY);
23 queue.Push(103, LOW_PRIORITY);
24 queue.Push(104, HIGH_PRIORITY);
26 // High priority jobs should be popped first.
27 JobID id;
28 EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
29 EXPECT_EQ(102, id);
30 EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
31 EXPECT_EQ(104, id);
33 // Then low priority jobs follow.
34 EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
35 EXPECT_EQ(101, id);
37 // The queue allows at most 3 parallel runs. So returns false here.
38 EXPECT_FALSE(queue.PopForRun(LOW_PRIORITY, &id));
40 // No jobs finished yet, so the job count is four.
41 EXPECT_EQ(4U, queue.GetNumberOfJobs());
43 // Mark one job as finished.
44 queue.MarkFinished(104);
45 EXPECT_EQ(3U, queue.GetNumberOfJobs());
47 // Then the next jobs can be popped.
48 EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
49 EXPECT_EQ(103, id);
51 // Push 1 more job.
52 queue.Push(105, LOW_PRIORITY);
54 // Finish all 3 running jobs.
55 queue.MarkFinished(101);
56 queue.MarkFinished(102);
57 queue.MarkFinished(103);
58 EXPECT_EQ(1U, queue.GetNumberOfJobs());
60 // The remaining jobs is of low priority, so under HIGH_PRIORITY context, it
61 // cannot be popped for running.
62 EXPECT_FALSE(queue.PopForRun(HIGH_PRIORITY, &id));
64 // Under the low priority context, it is fine.
65 EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
66 EXPECT_EQ(105, id);
69 TEST(JobQueueTest, JobQueueRemove) {
70 const int kNumMaxConcurrentJobs = 3;
71 const int kNumPriorityLevels = 2;
72 enum {HIGH_PRIORITY, LOW_PRIORITY};
74 // Create a queue. Number of jobs are initially zero.
75 JobQueue queue(kNumMaxConcurrentJobs, kNumPriorityLevels);
76 EXPECT_EQ(0U, queue.GetNumberOfJobs());
78 // Push 4 jobs.
79 queue.Push(101, LOW_PRIORITY);
80 queue.Push(102, HIGH_PRIORITY);
81 queue.Push(103, LOW_PRIORITY);
82 queue.Push(104, HIGH_PRIORITY);
83 EXPECT_EQ(4U, queue.GetNumberOfJobs());
85 // Remove 2.
86 queue.Remove(101);
87 queue.Remove(104);
88 EXPECT_EQ(2U, queue.GetNumberOfJobs());
90 // Pop the 2 jobs.
91 JobID id;
92 EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
93 EXPECT_EQ(102, id);
94 EXPECT_TRUE(queue.PopForRun(LOW_PRIORITY, &id));
95 EXPECT_EQ(103, id);
96 queue.MarkFinished(102);
97 queue.MarkFinished(103);
99 // 0 job left.
100 EXPECT_EQ(0U, queue.GetNumberOfJobs());
101 EXPECT_FALSE(queue.PopForRun(LOW_PRIORITY, &id));
104 } // namespace drive