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

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

Issue 2687083002: Headless: make URLRequestDispatcher aware of navigations (Closed)
Patch Set: Address nits Created 3 years, 10 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 | « headless/public/util/expedited_dispatcher.cc ('k') | headless/public/util/navigation_request.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "headless/public/util/expedited_dispatcher.h" 5 #include "headless/public/util/expedited_dispatcher.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "headless/public/util/navigation_request.h"
13 #include "headless/public/util/testing/fake_managed_dispatch_url_request_job.h" 15 #include "headless/public/util/testing/fake_managed_dispatch_url_request_job.h"
14 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
16 18
17 using testing::ElementsAre; 19 using testing::ElementsAre;
18 20
19 namespace headless { 21 namespace headless {
20 22
21 class ExpeditedDispatcherTest : public ::testing::Test { 23 class ExpeditedDispatcherTest : public ::testing::Test {
22 protected: 24 protected:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 job2->DispatchHeadersComplete(); 78 job2->DispatchHeadersComplete();
77 job1->DispatchHeadersComplete(); 79 job1->DispatchHeadersComplete();
78 80
79 EXPECT_TRUE(notifications.empty()); 81 EXPECT_TRUE(notifications.empty());
80 82
81 base::RunLoop().RunUntilIdle(); 83 base::RunLoop().RunUntilIdle();
82 EXPECT_THAT(notifications, ElementsAre("id: 4 OK", "id: 3 err: -123", 84 EXPECT_THAT(notifications, ElementsAre("id: 4 OK", "id: 3 err: -123",
83 "id: 2 OK", "id: 1 OK")); 85 "id: 2 OK", "id: 1 OK"));
84 } 86 }
85 87
88 namespace {
89 class NavigationRequestForTest : public NavigationRequest {
90 public:
91 explicit NavigationRequestForTest(base::Closure* done_closure)
92 : done_closure_(done_closure) {}
93
94 ~NavigationRequestForTest() override {}
95
96 // NavigationRequest implementation:
97 void StartProcessing(base::Closure done_callback) override {
98 *done_closure_ = std::move(done_callback);
99 }
100
101 private:
102 base::Closure* done_closure_; // NOT OWNED
103 };
104 } // namespace
105
106 TEST_F(ExpeditedDispatcherTest, NavigationDoesNotBlockUrlRequests) {
107 std::vector<std::string> notifications;
108 std::unique_ptr<FakeManagedDispatchURLRequestJob> job1(
109 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 1,
110 &notifications));
111 base::Closure navigation_done_closure;
112 expedited_dispatcher_->NavigationRequested(
113 base::MakeUnique<NavigationRequestForTest>(&navigation_done_closure));
114 std::unique_ptr<FakeManagedDispatchURLRequestJob> job2(
115 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 2,
116 &notifications));
117 std::unique_ptr<FakeManagedDispatchURLRequestJob> job3(
118 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 3,
119 &notifications));
120 std::unique_ptr<FakeManagedDispatchURLRequestJob> job4(
121 new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 4,
122 &notifications));
123 job1->DispatchHeadersComplete();
124 job2->DispatchHeadersComplete();
125 job3->DispatchHeadersComplete();
126 job4->DispatchHeadersComplete();
127
128 EXPECT_TRUE(notifications.empty());
129
130 base::RunLoop().RunUntilIdle();
131 EXPECT_THAT(notifications,
132 ElementsAre("id: 1 OK", "id: 2 OK", "id: 3 OK", "id: 4 OK"));
133 }
134
86 } // namespace headless 135 } // namespace headless
OLDNEW
« no previous file with comments | « headless/public/util/expedited_dispatcher.cc ('k') | headless/public/util/navigation_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698