Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / extensions / browser / guest_view / test_guest_view_manager.cc
blob3704cc8d13a4aa814000b0492aec6028a19e539e
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 #include "extensions/browser/guest_view/test_guest_view_manager.h"
7 #include "base/strings/stringprintf.h"
8 #include "content/public/test/browser_test_utils.h"
9 #include "extensions/browser/app_window/app_window.h"
10 #include "extensions/browser/app_window/app_window_registry.h"
11 #include "extensions/browser/extension_host.h"
12 #include "extensions/browser/process_manager.h"
13 #include "extensions/common/extension.h"
14 #include "extensions/common/extension_paths.h"
15 #include "extensions/shell/browser/shell_extension_system.h"
16 #include "extensions/shell/test/shell_test.h"
17 #include "extensions/test/extension_test_message_listener.h"
19 namespace extensions {
21 TestGuestViewManager::TestGuestViewManager(content::BrowserContext* context)
22 : GuestViewManager(context) {
25 TestGuestViewManager::~TestGuestViewManager() {
28 int TestGuestViewManager::GetNumGuests() const {
29 return guest_web_contents_by_instance_id_.size();
32 content::WebContents* TestGuestViewManager::GetLastGuestCreated() {
33 content::WebContents* web_contents = nullptr;
34 for (int i = current_instance_id_; i >= 0; i--) {
35 web_contents = GetGuestByInstanceID(i);
36 if (web_contents) {
37 break;
40 return web_contents;
43 void TestGuestViewManager::WaitForAllGuestsDeleted() {
44 // Make sure that every guest that was created have been removed.
45 for (auto& watcher : guest_web_contents_watchers_)
46 watcher->Wait();
49 void TestGuestViewManager::WaitForGuestCreated() {
50 created_message_loop_runner_ = new content::MessageLoopRunner;
51 created_message_loop_runner_->Run();
54 content::WebContents* TestGuestViewManager::WaitForSingleGuestCreated() {
55 if (GetNumGuests() == 0)
56 WaitForGuestCreated();
58 return GetLastGuestCreated();
61 void TestGuestViewManager::AddGuest(int guest_instance_id,
62 content::WebContents* guest_web_contents) {
63 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents);
65 guest_web_contents_watchers_.push_back(
66 linked_ptr<content::WebContentsDestroyedWatcher>(
67 new content::WebContentsDestroyedWatcher(guest_web_contents)));
69 if (created_message_loop_runner_.get())
70 created_message_loop_runner_->Quit();
73 void TestGuestViewManager::RemoveGuest(int guest_instance_id) {
74 GuestViewManager::RemoveGuest(guest_instance_id);
77 // Test factory for creating test instances of GuestViewManager.
78 TestGuestViewManagerFactory::TestGuestViewManagerFactory()
79 : test_guest_view_manager_(NULL) {
82 TestGuestViewManagerFactory::~TestGuestViewManagerFactory() {
85 GuestViewManager* TestGuestViewManagerFactory::CreateGuestViewManager(
86 content::BrowserContext* context) {
87 return GetManager(context);
90 // This function gets called from GuestViewManager::FromBrowserContext(),
91 // where test_guest_view_manager_ is assigned to a linked_ptr that takes care
92 // of deleting it.
93 TestGuestViewManager* TestGuestViewManagerFactory::GetManager(
94 content::BrowserContext* context) {
95 DCHECK(!test_guest_view_manager_);
96 test_guest_view_manager_ = new TestGuestViewManager(context);
97 return test_guest_view_manager_;
100 } // namespace extensions