| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "extensions/browser/guest_view/test_guest_view_manager.h" | |
| 6 | |
| 7 #include "extensions/browser/guest_view/guest_view_manager_delegate.h" | |
| 8 | |
| 9 using guestview::GuestViewManagerDelegate; | |
| 10 | |
| 11 namespace extensions { | |
| 12 | |
| 13 TestGuestViewManager::TestGuestViewManager( | |
| 14 content::BrowserContext* context, | |
| 15 scoped_ptr<GuestViewManagerDelegate> delegate) | |
| 16 : GuestViewManager(context, delegate.Pass()), | |
| 17 num_guests_created_(0) { | |
| 18 } | |
| 19 | |
| 20 TestGuestViewManager::~TestGuestViewManager() { | |
| 21 } | |
| 22 | |
| 23 int TestGuestViewManager::GetNumGuestsActive() const { | |
| 24 return guest_web_contents_by_instance_id_.size(); | |
| 25 } | |
| 26 | |
| 27 int TestGuestViewManager::GetNumRemovedInstanceIDs() const { | |
| 28 return removed_instance_ids_.size(); | |
| 29 } | |
| 30 | |
| 31 content::WebContents* TestGuestViewManager::GetLastGuestCreated() { | |
| 32 content::WebContents* web_contents = nullptr; | |
| 33 for (int i = current_instance_id_; i >= 0; i--) { | |
| 34 web_contents = GetGuestByInstanceID(i); | |
| 35 if (web_contents) { | |
| 36 break; | |
| 37 } | |
| 38 } | |
| 39 return web_contents; | |
| 40 } | |
| 41 | |
| 42 void TestGuestViewManager::WaitForAllGuestsDeleted() { | |
| 43 // Make sure that every guest that was created have been removed. | |
| 44 for (auto& watcher : guest_web_contents_watchers_) | |
| 45 watcher->Wait(); | |
| 46 } | |
| 47 | |
| 48 void TestGuestViewManager::WaitForGuestCreated() { | |
| 49 created_message_loop_runner_ = new content::MessageLoopRunner; | |
| 50 created_message_loop_runner_->Run(); | |
| 51 } | |
| 52 | |
| 53 content::WebContents* TestGuestViewManager::WaitForSingleGuestCreated() { | |
| 54 if (!GetNumGuestsActive()) { | |
| 55 // Guests have been created and subsequently destroyed. | |
| 56 if (num_guests_created() > 0) | |
| 57 return nullptr; | |
| 58 WaitForGuestCreated(); | |
| 59 } | |
| 60 | |
| 61 return GetLastGuestCreated(); | |
| 62 } | |
| 63 | |
| 64 void TestGuestViewManager::AddGuest(int guest_instance_id, | |
| 65 content::WebContents* guest_web_contents) { | |
| 66 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents); | |
| 67 | |
| 68 guest_web_contents_watchers_.push_back( | |
| 69 linked_ptr<content::WebContentsDestroyedWatcher>( | |
| 70 new content::WebContentsDestroyedWatcher(guest_web_contents))); | |
| 71 | |
| 72 ++num_guests_created_; | |
| 73 | |
| 74 if (created_message_loop_runner_.get()) | |
| 75 created_message_loop_runner_->Quit(); | |
| 76 } | |
| 77 | |
| 78 void TestGuestViewManager::RemoveGuest(int guest_instance_id) { | |
| 79 GuestViewManager::RemoveGuest(guest_instance_id); | |
| 80 } | |
| 81 | |
| 82 // Test factory for creating test instances of GuestViewManager. | |
| 83 TestGuestViewManagerFactory::TestGuestViewManagerFactory() | |
| 84 : test_guest_view_manager_(NULL) { | |
| 85 } | |
| 86 | |
| 87 TestGuestViewManagerFactory::~TestGuestViewManagerFactory() { | |
| 88 } | |
| 89 | |
| 90 GuestViewManager* TestGuestViewManagerFactory::CreateGuestViewManager( | |
| 91 content::BrowserContext* context, | |
| 92 scoped_ptr<guestview::GuestViewManagerDelegate> delegate) { | |
| 93 if (!test_guest_view_manager_) { | |
| 94 test_guest_view_manager_ = | |
| 95 new TestGuestViewManager(context, delegate.Pass()); | |
| 96 } | |
| 97 return test_guest_view_manager_; | |
| 98 } | |
| 99 | |
| 100 } // namespace extensions | |
| OLD | NEW |