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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/public/util/expedited_dispatcher_test.cc
diff --git a/headless/public/util/expedited_dispatcher_test.cc b/headless/public/util/expedited_dispatcher_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5ef6301ba1d34b1026b35b88a1a8802facb7d990
--- /dev/null
+++ b/headless/public/util/expedited_dispatcher_test.cc
@@ -0,0 +1,86 @@
+// Copyright 2016 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 "headless/public/util/expedited_dispatcher.h"
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "base/run_loop.h"
+#include "base/single_thread_task_runner.h"
+#include "headless/public/util/testing/fake_managed_dispatch_url_request_job.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::ElementsAre;
+
+namespace headless {
+
+class ExpeditedDispatcherTest : public ::testing::Test {
+ protected:
+ ExpeditedDispatcherTest() {}
+ ~ExpeditedDispatcherTest() override {}
+
+ void SetUp() override {
+ expedited_dispatcher_.reset(new ExpeditedDispatcher(loop_.task_runner()));
+ }
+
+ base::MessageLoop loop_;
+ std::unique_ptr<ExpeditedDispatcher> expedited_dispatcher_;
+};
+
+TEST_F(ExpeditedDispatcherTest, DispatchDataReadyInReverseOrder) {
+ std::vector<std::string> notifications;
+ std::unique_ptr<FakeManagedDispatchURLRequestJob> job1(
+ new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 1,
+ &notifications));
+ std::unique_ptr<FakeManagedDispatchURLRequestJob> job2(
+ new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 2,
+ &notifications));
+ std::unique_ptr<FakeManagedDispatchURLRequestJob> job3(
+ new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 3,
+ &notifications));
+ std::unique_ptr<FakeManagedDispatchURLRequestJob> job4(
+ new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 4,
+ &notifications));
+ job4->DispatchHeadersComplete();
+ job3->DispatchHeadersComplete();
+ job2->DispatchHeadersComplete();
+ job1->DispatchHeadersComplete();
+
+ EXPECT_TRUE(notifications.empty());
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_THAT(notifications,
+ ElementsAre("id: 4 OK", "id: 3 OK", "id: 2 OK", "id: 1 OK"));
+}
+
+TEST_F(ExpeditedDispatcherTest, ErrorsAndDataReadyDispatchedInCallOrder) {
+ std::vector<std::string> notifications;
+ std::unique_ptr<FakeManagedDispatchURLRequestJob> job1(
+ new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 1,
+ &notifications));
+ std::unique_ptr<FakeManagedDispatchURLRequestJob> job2(
+ new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 2,
+ &notifications));
+ std::unique_ptr<FakeManagedDispatchURLRequestJob> job3(
+ new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 3,
+ &notifications));
+ std::unique_ptr<FakeManagedDispatchURLRequestJob> job4(
+ new FakeManagedDispatchURLRequestJob(expedited_dispatcher_.get(), 4,
+ &notifications));
+ job4->DispatchHeadersComplete();
+ job3->DispatchStartError(static_cast<net::Error>(-123));
+ job2->DispatchHeadersComplete();
+ job1->DispatchHeadersComplete();
+
+ EXPECT_TRUE(notifications.empty());
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_THAT(notifications, ElementsAre("id: 4 OK", "id: 3 err: -123",
+ "id: 2 OK", "id: 1 OK"));
+}
+
+} // namespace headless
« 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