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

Unified Diff: content/test/browser_side_navigation_test_utils.cc

Issue 730553002: PlzNavigate: Refactor unit test helper functions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed the test utils class Created 6 years, 1 month 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 | « content/test/browser_side_navigation_test_utils.h ('k') | content/test/test_navigation_url_loader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/browser_side_navigation_test_utils.cc
diff --git a/content/test/browser_side_navigation_test_utils.cc b/content/test/browser_side_navigation_test_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c73a62e2c87c8036134b98fcf9b769bf06b94486
--- /dev/null
+++ b/content/test/browser_side_navigation_test_utils.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2014 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 "content/test/browser_side_navigation_test_utils.h"
+
+#include "base/command_line.h"
+#include "base/guid.h"
+#include "base/lazy_instance.h"
+#include "content/browser/streams/stream.h"
+#include "content/browser/streams/stream_registry.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/stream_handle.h"
+#include "content/public/common/content_switches.h"
+#include "content/test/test_navigation_url_loader_factory.h"
+
+namespace content {
+
+namespace {
+
+// PlzNavigate
+// A UI thread singleton helper class for browser side navigations. When browser
+// side navigations are enabled, initialize this class before doing any
+// operation that may start a navigation request on the UI thread. Use TearDown
+// at the end of the test.
+class BrowserSideNavigationTestUtils {
+ public:
+ BrowserSideNavigationTestUtils()
+ : stream_registry_(new StreamRegistry),
+ loader_factory_(new TestNavigationURLLoaderFactory) {
+ }
+
+ ~BrowserSideNavigationTestUtils() {}
+ StreamRegistry* stream_registry() { return stream_registry_.get();}
+
+ private:
+ scoped_ptr<StreamRegistry> stream_registry_;
+ scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserSideNavigationTestUtils);
+};
+
+base::LazyInstance<scoped_ptr<BrowserSideNavigationTestUtils>>
+ browser_side_navigation_test_utils;
+
+} // namespace
+
+void BrowserSideNavigationSetUp() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ browser_side_navigation_test_utils.Get().reset(
+ new BrowserSideNavigationTestUtils);
+}
+
+void BrowserSideNavigationTearDown() {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ browser_side_navigation_test_utils.Get().reset(nullptr);
+}
+
+scoped_ptr<StreamHandle> MakeEmptyStream() {
+ GURL url(std::string(url::kBlobScheme) + "://" + base::GenerateGUID());
+ StreamRegistry* stream_registry =
+ browser_side_navigation_test_utils.Get()->stream_registry();
+ scoped_refptr<Stream> stream(new Stream(stream_registry, NULL, url));
+ stream->Finalize();
+ return stream->CreateHandle();
+}
+
+void EnableBrowserSideNavigation() {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableBrowserSideNavigation);
+}
+
+} // namespace content
« no previous file with comments | « content/test/browser_side_navigation_test_utils.h ('k') | content/test/test_navigation_url_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698