| 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 "base/macros.h" |  | 
| 11 #include "content/browser/streams/stream.h" |  | 
| 12 #include "content/browser/streams/stream_registry.h" |  | 
| 13 #include "content/public/browser/browser_thread.h" |  | 
| 14 #include "content/public/browser/stream_handle.h" |  | 
| 15 #include "content/public/common/content_switches.h" |  | 
| 16 #include "content/test/test_navigation_url_loader_factory.h" |  | 
| 17 |  | 
| 18 namespace content { |  | 
| 19 |  | 
| 20 namespace { |  | 
| 21 |  | 
| 22 // PlzNavigate |  | 
| 23 // A UI thread singleton helper class for browser side navigations. When browser |  | 
| 24 // side navigations are enabled, initialize this class before doing any |  | 
| 25 // operation that may start a navigation request on the UI thread. Use TearDown |  | 
| 26 // at the end of the test. |  | 
| 27 class BrowserSideNavigationTestUtils { |  | 
| 28  public: |  | 
| 29   BrowserSideNavigationTestUtils() |  | 
| 30       : stream_registry_(new StreamRegistry), |  | 
| 31         loader_factory_(new TestNavigationURLLoaderFactory) { |  | 
| 32   } |  | 
| 33 |  | 
| 34   ~BrowserSideNavigationTestUtils() {} |  | 
| 35   StreamRegistry* stream_registry() { return stream_registry_.get();} |  | 
| 36 |  | 
| 37  private: |  | 
| 38   std::unique_ptr<StreamRegistry> stream_registry_; |  | 
| 39   std::unique_ptr<TestNavigationURLLoaderFactory> loader_factory_; |  | 
| 40 |  | 
| 41   DISALLOW_COPY_AND_ASSIGN(BrowserSideNavigationTestUtils); |  | 
| 42 }; |  | 
| 43 |  | 
| 44 base::LazyInstance<std::unique_ptr<BrowserSideNavigationTestUtils>> |  | 
| 45     browser_side_navigation_test_utils; |  | 
| 46 |  | 
| 47 }  // namespace |  | 
| 48 |  | 
| 49 void BrowserSideNavigationSetUp() { |  | 
| 50   DCHECK_CURRENTLY_ON(BrowserThread::UI); |  | 
| 51   browser_side_navigation_test_utils.Get().reset( |  | 
| 52       new BrowserSideNavigationTestUtils); |  | 
| 53 } |  | 
| 54 |  | 
| 55 void BrowserSideNavigationTearDown() { |  | 
| 56   DCHECK_CURRENTLY_ON(BrowserThread::UI); |  | 
| 57   browser_side_navigation_test_utils.Get().reset(nullptr); |  | 
| 58 } |  | 
| 59 |  | 
| 60 std::unique_ptr<StreamHandle> MakeEmptyStream() { |  | 
| 61   GURL url(std::string(url::kBlobScheme) + "://" + base::GenerateGUID()); |  | 
| 62   StreamRegistry* stream_registry = |  | 
| 63       browser_side_navigation_test_utils.Get()->stream_registry(); |  | 
| 64   scoped_refptr<Stream> stream(new Stream(stream_registry, NULL, url)); |  | 
| 65   stream->Finalize(); |  | 
| 66   return stream->CreateHandle(); |  | 
| 67 } |  | 
| 68 |  | 
| 69 void EnableBrowserSideNavigation() { |  | 
| 70   base::CommandLine::ForCurrentProcess()->AppendSwitch( |  | 
| 71       switches::kEnableBrowserSideNavigation); |  | 
| 72 } |  | 
| 73 |  | 
| 74 }  // namespace content |  | 
| OLD | NEW | 
|---|