[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / components / guest_view / browser / test_guest_view_manager.h
blobd312d98c688f3b2bd38a71a94b322ff85067310e
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 content::WebContents* WaitForSingleGuestCreated();
27 void WaitForSingleViewGarbageCollected();
29 content::WebContents* GetLastGuestCreated();
31 // Returns the number of guests currently still alive at the time of calling
32 // this method.
33 size_t GetNumGuestsActive() const;
35 // Returns the size of the set of removed instance IDs.
36 size_t GetNumRemovedInstanceIDs() const;
38 using GuestViewCreateFunction =
39 base::Callback<GuestViewBase*(content::WebContents*)>;
41 template <typename T>
42 void RegisterTestGuestViewType(
43 const GuestViewCreateFunction& create_function) {
44 auto registry_entry = std::make_pair(
45 T::Type,
46 GuestViewData(create_function, base::Bind(&T::CleanUp)));
47 guest_view_registry_.insert(registry_entry);
50 // Returns the number of guests that have been created since the creation of
51 // this GuestViewManager.
52 int num_guests_created() const { return num_guests_created_; }
54 // Returns the number of GuestViews that have been garbage collected in
55 // JavaScript since the creation of this GuestViewManager.
56 int num_views_garbage_collected() const {
57 return num_views_garbage_collected_;
60 // Returns the last guest instance ID removed from the manager.
61 int last_instance_id_removed() const { return last_instance_id_removed_; }
63 private:
64 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove);
66 // GuestViewManager override:
67 void AddGuest(int guest_instance_id,
68 content::WebContents* guest_web_contents) override;
69 void RemoveGuest(int guest_instance_id) override;
70 void ViewGarbageCollected(int embedder_process_id,
71 int view_instance_id) override;
73 void WaitForGuestCreated();
75 void WaitForViewGarbageCollected();
77 using GuestViewManager::last_instance_id_removed_;
78 using GuestViewManager::removed_instance_ids_;
80 int num_guests_created_;
82 int num_views_garbage_collected_;
84 std::vector<linked_ptr<content::WebContentsDestroyedWatcher>>
85 guest_web_contents_watchers_;
86 scoped_refptr<content::MessageLoopRunner> created_message_loop_runner_;
87 scoped_refptr<content::MessageLoopRunner> gc_message_loop_runner_;
89 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManager);
92 // Test factory for creating test instances of GuestViewManager.
93 class TestGuestViewManagerFactory : public GuestViewManagerFactory {
94 public:
95 TestGuestViewManagerFactory();
96 ~TestGuestViewManagerFactory() override;
98 GuestViewManager* CreateGuestViewManager(
99 content::BrowserContext* context,
100 scoped_ptr<GuestViewManagerDelegate> delegate) override;
102 private:
103 TestGuestViewManager* test_guest_view_manager_;
105 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory);
108 } // namespace guest_view
110 #endif // COMPONENTS_GUEST_VIEW_BROWSER_TEST_GUEST_VIEW_MANAGER_H_