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

Side by Side Diff: headless/public/util/deterministic_dispatcher_test.cc

Issue 2260793002: Headless utility classes for making deterministic protocol handlers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2016 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 "headless/public/util/deterministic_dispatcher.h"
6
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h"
13 #include "headless/public/util/testing/fake_managed_dispatch_url_request_job.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using testing::ElementsAre;
18
19 namespace headless {
20
21 class DeterministicDispatcherTest : public ::testing::Test {
22 protected:
23 DeterministicDispatcherTest() {}
24 ~DeterministicDispatcherTest() override {}
25
26 void SetUp() override {
27 deterministic_dispatcher_.reset(
28 new DeterministicDispatcher(loop_.task_runner()));
29 }
30
31 base::MessageLoop loop_;
32 std::unique_ptr<DeterministicDispatcher> deterministic_dispatcher_;
33 };
34
35 TEST_F(DeterministicDispatcherTest, DispatchDataReadyInReverseOrder) {
36 std::vector<std::string> notifications;
37 std::unique_ptr<FakeManagedDispatchURLRequestJob> job1(
38 new FakeManagedDispatchURLRequestJob(deterministic_dispatcher_.get(), 1,
39 &notifications));
40 std::unique_ptr<FakeManagedDispatchURLRequestJob> job2(
41 new FakeManagedDispatchURLRequestJob(deterministic_dispatcher_.get(), 2,
42 &notifications));
43 std::unique_ptr<FakeManagedDispatchURLRequestJob> job3(
44 new FakeManagedDispatchURLRequestJob(deterministic_dispatcher_.get(), 3,
45 &notifications));
46 std::unique_ptr<FakeManagedDispatchURLRequestJob> job4(
47 new FakeManagedDispatchURLRequestJob(deterministic_dispatcher_.get(), 4,
48 &notifications));
49 job4->DispatchHeadersComplete();
50 job3->DispatchHeadersComplete();
51 job2->DispatchHeadersComplete();
52 job1->DispatchHeadersComplete();
53
54 EXPECT_TRUE(notifications.empty());
55
56 base::RunLoop().RunUntilIdle();
57 EXPECT_THAT(notifications, ElementsAre("id: 1 OK"));
58
59 job1.reset();
60 base::RunLoop().RunUntilIdle();
61 EXPECT_THAT(notifications, ElementsAre("id: 1 OK", "id: 2 OK"));
62
63 job2.reset();
64 base::RunLoop().RunUntilIdle();
65 EXPECT_THAT(notifications, ElementsAre("id: 1 OK", "id: 2 OK", "id: 3 OK"));
66
67 job3.reset();
68 base::RunLoop().RunUntilIdle();
69 EXPECT_THAT(notifications,
70 ElementsAre("id: 1 OK", "id: 2 OK", "id: 3 OK", "id: 4 OK"));
71 }
72
73 TEST_F(DeterministicDispatcherTest,
74 ErrorsAndDataReadyDispatchedInCreationOrder) {
75 std::vector<std::string> notifications;
76 std::unique_ptr<FakeManagedDispatchURLRequestJob> job1(
77 new FakeManagedDispatchURLRequestJob(deterministic_dispatcher_.get(), 1,
78 &notifications));
79 std::unique_ptr<FakeManagedDispatchURLRequestJob> job2(
80 new FakeManagedDispatchURLRequestJob(deterministic_dispatcher_.get(), 2,
81 &notifications));
82 std::unique_ptr<FakeManagedDispatchURLRequestJob> job3(
83 new FakeManagedDispatchURLRequestJob(deterministic_dispatcher_.get(), 3,
84 &notifications));
85 std::unique_ptr<FakeManagedDispatchURLRequestJob> job4(
86 new FakeManagedDispatchURLRequestJob(deterministic_dispatcher_.get(), 4,
87 &notifications));
88 job4->DispatchHeadersComplete();
89 job3->DispatchStartError(static_cast<net::Error>(-123));
90 job2->DispatchHeadersComplete();
91 job1->DispatchHeadersComplete();
92
93 EXPECT_TRUE(notifications.empty());
94
95 base::RunLoop().RunUntilIdle();
96 EXPECT_THAT(notifications, ElementsAre("id: 1 OK"));
97
98 job1.reset();
99 base::RunLoop().RunUntilIdle();
100 EXPECT_THAT(notifications, ElementsAre("id: 1 OK", "id: 2 OK"));
101
102 job2.reset();
103 base::RunLoop().RunUntilIdle();
104 EXPECT_THAT(notifications,
105 ElementsAre("id: 1 OK", "id: 2 OK", "id: 3 err: -123"));
106
107 job3.reset();
108 base::RunLoop().RunUntilIdle();
109 EXPECT_THAT(notifications, ElementsAre("id: 1 OK", "id: 2 OK",
110 "id: 3 err: -123", "id: 4 OK"));
111 }
112
113 } // namespace headless
OLDNEW
« no previous file with comments | « headless/public/util/deterministic_dispatcher.cc ('k') | headless/public/util/expedited_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698