Don't preload rarely seen large images
[chromium-blink-merge.git] / components / guest_view / browser / test_guest_view_manager.h
blob76f0cd7e98d1eaef182c1ea79432221dabba8239
1 // Copyright 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 #ifndef COMPONENTS_GUEST_VIEW_BROWSER_TEST_GUEST_VIEW_MANAGER_H_
6 #define COMPONENTS_GUEST_VIEW_BROWSER_TEST_GUEST_VIEW_MANAGER_H_
8 #include "base/memory/linked_ptr.h"
9 #include "components/guest_view/browser/guest_view_manager.h"
10 #include "components/guest_view/browser/guest_view_manager_factory.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/test_utils.h"
14 namespace guest_view {
16 class TestGuestViewManager : public GuestViewManager {
17 public:
18 TestGuestViewManager(
19 content::BrowserContext* context,
20 scoped_ptr<GuestViewManagerDelegate> delegate);
21 ~TestGuestViewManager() override;
23 void WaitForAllGuestsDeleted();
25 void WaitForLastGuestDeleted();
27 content::WebContents* WaitForSingleGuestCreated();
29 void WaitForSingleViewGarbageCollected();
31 content::WebContents* GetLastGuestCreated();
33 // Returns the number of guests currently still alive at the time of calling
34 // this method.
35 size_t GetNumGuestsActive() const;
37 // Returns the size of the set of removed instance IDs.
38 size_t GetNumRemovedInstanceIDs() const;
40 using GuestViewCreateFunction =
41 base::Callback<GuestViewBase*(content::WebContents*)>;
43 template <typename T>
44 void RegisterTestGuestViewType(
45 const GuestViewCreateFunction& create_function) {
46 auto registry_entry = std::make_pair(
47 T::Type,
48 GuestViewData(create_function, base::Bind(&T::CleanUp)));
49 guest_view_registry_.insert(registry_entry);
52 // Returns the number of times EmbedderWillBeDestroyed() was called.
53 int num_embedder_processes_destroyed() const {
54 return num_embedder_processes_destroyed_;
57 // Returns the number of guests that have been created since the creation of
58 // this GuestViewManager.
59 int num_guests_created() const { return num_guests_created_; }
61 // Returns the number of GuestViews that have been garbage collected in
62 // JavaScript since the creation of this GuestViewManager.
63 int num_views_garbage_collected() const {
64 return num_views_garbage_collected_;
67 // Returns the last guest instance ID removed from the manager.
68 int last_instance_id_removed() const { return last_instance_id_removed_; }
70 private:
71 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove);
73 // GuestViewManager override:
74 void AddGuest(int guest_instance_id,
75 content::WebContents* guest_web_contents) override;
76 void RemoveGuest(int guest_instance_id) override;
77 void EmbedderWillBeDestroyed(int embedder_process_id) override;
78 void ViewGarbageCollected(int embedder_process_id,
79 int view_instance_id) override;
81 void WaitForGuestCreated();
83 void WaitForViewGarbageCollected();
85 using GuestViewManager::last_instance_id_removed_;
86 using GuestViewManager::removed_instance_ids_;
88 int num_embedder_processes_destroyed_;
89 int num_guests_created_;
90 int num_views_garbage_collected_;
92 std::vector<linked_ptr<content::WebContentsDestroyedWatcher>>
93 guest_web_contents_watchers_;
94 scoped_refptr<content::MessageLoopRunner> created_message_loop_runner_;
95 scoped_refptr<content::MessageLoopRunner> gc_message_loop_runner_;
97 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManager);
100 // Test factory for creating test instances of GuestViewManager.
101 class TestGuestViewManagerFactory : public GuestViewManagerFactory {
102 public:
103 TestGuestViewManagerFactory();
104 ~TestGuestViewManagerFactory() override;
106 GuestViewManager* CreateGuestViewManager(
107 content::BrowserContext* context,
108 scoped_ptr<GuestViewManagerDelegate> delegate) override;
110 private:
111 TestGuestViewManager* test_guest_view_manager_;
113 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory);
116 } // namespace guest_view
118 #endif // COMPONENTS_GUEST_VIEW_BROWSER_TEST_GUEST_VIEW_MANAGER_H_