1 // Copyright (c) 2012 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 #ifndef CONTENT_PUBLIC_TEST_TEST_BROWSER_CONTEXT_H_
6 #define CONTENT_PUBLIC_TEST_TEST_BROWSER_CONTEXT_H_
7 
8 #include <memory>
9 
10 #include "base/compiler_specific.h"
11 #include "base/files/file_path.h"
12 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "content/public/browser/browser_context.h"
16 
17 namespace content {
18 
19 class MockBackgroundSyncController;
20 class MockResourceContext;
21 class MockSSLHostStateDelegate;
22 #if !defined(OS_ANDROID)
23 class ZoomLevelDelegate;
24 #endif  // !defined(OS_ANDROID)
25 
26 class TestBrowserContext : public BrowserContext {
27  public:
28   explicit TestBrowserContext(
29       base::FilePath browser_context_dir_path = base::FilePath());
30   ~TestBrowserContext() override;
31 
32   // Takes ownership of the temporary directory so that it's not deleted when
33   // this object is destructed.
34   base::FilePath TakePath();
35 
36   void SetSpecialStoragePolicy(storage::SpecialStoragePolicy* policy);
37   void SetPermissionControllerDelegate(
38       std::unique_ptr<PermissionControllerDelegate> delegate);
39 
40   // Allow clients to make this an incognito context.
set_is_off_the_record(bool is_off_the_record)41   void set_is_off_the_record(bool is_off_the_record) {
42     is_off_the_record_ = is_off_the_record;
43   }
44 
45   // BrowserContext implementation.
46   base::FilePath GetPath() override;
47 #if !defined(OS_ANDROID)
48   std::unique_ptr<ZoomLevelDelegate> CreateZoomLevelDelegate(
49       const base::FilePath& partition_path) override;
50 #endif  // !defined(OS_ANDROID)
51   bool IsOffTheRecord() override;
52   DownloadManagerDelegate* GetDownloadManagerDelegate() override;
53   ResourceContext* GetResourceContext() override;
54   BrowserPluginGuestManager* GetGuestManager() override;
55   storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
56   PushMessagingService* GetPushMessagingService() override;
57   StorageNotificationService* GetStorageNotificationService() override;
58   SSLHostStateDelegate* GetSSLHostStateDelegate() override;
59   PermissionControllerDelegate* GetPermissionControllerDelegate() override;
60   ClientHintsControllerDelegate* GetClientHintsControllerDelegate() override;
61   BackgroundFetchDelegate* GetBackgroundFetchDelegate() override;
62   BackgroundSyncController* GetBackgroundSyncController() override;
63   BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate() override;
64 
65  private:
66   // Hold a reference here because BrowserContext owns lifetime.
67   base::ScopedTempDir browser_context_dir_;
68   std::unique_ptr<MockResourceContext> resource_context_;
69   scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
70   std::unique_ptr<MockSSLHostStateDelegate> ssl_host_state_delegate_;
71   std::unique_ptr<PermissionControllerDelegate> permission_controller_delegate_;
72   std::unique_ptr<MockBackgroundSyncController> background_sync_controller_;
73   bool is_off_the_record_ = false;
74 
75   DISALLOW_COPY_AND_ASSIGN(TestBrowserContext);
76 };
77 
78 }  // namespace content
79 
80 #endif  // CONTENT_PUBLIC_TEST_TEST_BROWSER_CONTEXT_H_
81