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

Side by Side Diff: headless/public/util/expedited_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/expedited_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 ExpeditedDispatcherTest : public ::testing::Test {
22 protected:
23 ExpeditedDispatcherTest() {}
24 ~ExpeditedDispatcherTest() override {}
25
26 void SetUp() override {
27 expedited_dispatcher_.reset(new ExpeditedDispatcher(loop_.task_runner()));
28 }
29
30 base::MessageLoop loop_;
31 std::unique_ptr<ExpeditedDispatcher> expedited_dispatcher_;
32 };
33
34 TEST_F(ExpeditedDispatcherTest, DispatchDataReadyInReverseOrder) {
35 std::vector<std::string> notifications;
36 std::unique_ptr<FakeManagedDispatchURLRequestJob> job1(
37 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 1,
38 &notifications));
39 std::unique_ptr<FakeManagedDispatchURLRequestJob> job2(
40 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 2,
41 &notifications));
42 std::unique_ptr<FakeManagedDispatchURLRequestJob> job3(
43 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 3,
44 &notifications));
45 std::unique_ptr<FakeManagedDispatchURLRequestJob> job4(
46 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 4,
47 &notifications));
48 job4->DispatchHeadersComplete();
49 job3->DispatchHeadersComplete();
50 job2->DispatchHeadersComplete();
51 job1->DispatchHeadersComplete();
52
53 EXPECT_TRUE(notifications.empty());
54
55 base::RunLoop().RunUntilIdle();
56 EXPECT_THAT(notifications,
57 ElementsAre("id: 4 OK", "id: 3 OK", "id: 2 OK", "id: 1 OK"));
58 }
59
60 TEST_F(ExpeditedDispatcherTest, ErrorsAndDataReadyDispatchedInCallOrder) {
61 std::vector<std::string> notifications;
62 std::unique_ptr<FakeManagedDispatchURLRequestJob> job1(
63 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 1,
64 &notifications));
65 std::unique_ptr<FakeManagedDispatchURLRequestJob> job2(
66 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 2,
67 &notifications));
68 std::unique_ptr<FakeManagedDispatchURLRequestJob> job3(
69 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 3,
70 &notifications));
71 std::unique_ptr<FakeManagedDispatchURLRequestJob> job4(
72 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 4,
73 &notifications));
74 job4->DispatchHeadersComplete();
75 job3->DispatchStartError(static_cast<net::Error>(-123));
76 job2->DispatchHeadersComplete();
77 job1->DispatchHeadersComplete();
78
79 EXPECT_TRUE(notifications.empty());
80
81 base::RunLoop().RunUntilIdle();
82 EXPECT_THAT(notifications, ElementsAre("id: 4 OK", "id: 3 err: -123",
83 "id: 2 OK", "id: 1 OK"));
84 }
85
86 } // namespace headless
OLDNEW
« no previous file with comments | « headless/public/util/expedited_dispatcher.cc ('k') | headless/public/util/generic_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698