1 // Copyright (c) 2014 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.
5 #include "content/test/browser_side_navigation_test_utils.h"
7 #include "base/command_line.h"
9 #include "base/lazy_instance.h"
10 #include "content/browser/streams/stream.h"
11 #include "content/browser/streams/stream_registry.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/stream_handle.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/test/test_navigation_url_loader_factory.h"
22 // A UI thread singleton helper class for browser side navigations. When browser
23 // side navigations are enabled, initialize this class before doing any
24 // operation that may start a navigation request on the UI thread. Use TearDown
25 // at the end of the test.
26 class BrowserSideNavigationTestUtils
{
28 BrowserSideNavigationTestUtils()
29 : stream_registry_(new StreamRegistry
),
30 loader_factory_(new TestNavigationURLLoaderFactory
) {
33 ~BrowserSideNavigationTestUtils() {}
34 StreamRegistry
* stream_registry() { return stream_registry_
.get();}
37 scoped_ptr
<StreamRegistry
> stream_registry_
;
38 scoped_ptr
<TestNavigationURLLoaderFactory
> loader_factory_
;
40 DISALLOW_COPY_AND_ASSIGN(BrowserSideNavigationTestUtils
);
43 base::LazyInstance
<scoped_ptr
<BrowserSideNavigationTestUtils
>>
44 browser_side_navigation_test_utils
;
48 void BrowserSideNavigationSetUp() {
49 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
50 browser_side_navigation_test_utils
.Get().reset(
51 new BrowserSideNavigationTestUtils
);
54 void BrowserSideNavigationTearDown() {
55 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
56 browser_side_navigation_test_utils
.Get().reset(nullptr);
59 scoped_ptr
<StreamHandle
> MakeEmptyStream() {
60 GURL
url(std::string(url::kBlobScheme
) + "://" + base::GenerateGUID());
61 StreamRegistry
* stream_registry
=
62 browser_side_navigation_test_utils
.Get()->stream_registry();
63 scoped_refptr
<Stream
> stream(new Stream(stream_registry
, NULL
, url
));
65 return stream
->CreateHandle();
68 void EnableBrowserSideNavigation() {
69 base::CommandLine::ForCurrentProcess()->AppendSwitch(
70 switches::kEnableBrowserSideNavigation
);
73 } // namespace content