OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/test/browser_side_navigation_test_utils.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/guid.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" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // PlzNavigate |
| 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 { |
| 27 public: |
| 28 BrowserSideNavigationTestUtils() |
| 29 : stream_registry_(new StreamRegistry), |
| 30 loader_factory_(new TestNavigationURLLoaderFactory) { |
| 31 } |
| 32 |
| 33 ~BrowserSideNavigationTestUtils() {} |
| 34 StreamRegistry* stream_registry() { return stream_registry_.get();} |
| 35 |
| 36 private: |
| 37 scoped_ptr<StreamRegistry> stream_registry_; |
| 38 scoped_ptr<TestNavigationURLLoaderFactory> loader_factory_; |
| 39 |
| 40 DISALLOW_COPY_AND_ASSIGN(BrowserSideNavigationTestUtils); |
| 41 }; |
| 42 |
| 43 base::LazyInstance<scoped_ptr<BrowserSideNavigationTestUtils>> |
| 44 browser_side_navigation_test_utils; |
| 45 |
| 46 } // namespace |
| 47 |
| 48 void BrowserSideNavigationSetUp() { |
| 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 50 browser_side_navigation_test_utils.Get().reset( |
| 51 new BrowserSideNavigationTestUtils); |
| 52 } |
| 53 |
| 54 void BrowserSideNavigationTearDown() { |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 56 browser_side_navigation_test_utils.Get().reset(nullptr); |
| 57 } |
| 58 |
| 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)); |
| 64 stream->Finalize(); |
| 65 return stream->CreateHandle(); |
| 66 } |
| 67 |
| 68 void EnableBrowserSideNavigation() { |
| 69 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 70 switches::kEnableBrowserSideNavigation); |
| 71 } |
| 72 |
| 73 } // namespace content |
OLD | NEW |