Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3299)

Unified Diff: chrome/browser/apps/web_view_browsertest.cc

Issue 334923002: Remove ContentBrowserClient::GuestWebContentsAttached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_adview
Patch Set: Added missing file Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/apps/web_view_browsertest.cc
diff --git a/chrome/browser/apps/web_view_browsertest.cc b/chrome/browser/apps/web_view_browsertest.cc
index 991168727b677c5f2eb0874c0acae38aa7ccb068..23c94fc525e4b5b4e9e0a446492c2ffd9125c14b 100644
--- a/chrome/browser/apps/web_view_browsertest.cc
+++ b/chrome/browser/apps/web_view_browsertest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "apps/ui/native_app_window.h"
+#include "base/memory/singleton.h"
lazyboy 2014/06/13 17:40:01 Do you need this?
Fady Samuel 2014/06/16 14:35:40 No removed.
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -10,6 +11,8 @@
#include "chrome/browser/apps/app_browsertest_util.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
+#include "chrome/browser/guest_view/guest_view_manager.h"
+#include "chrome/browser/guest_view/guest_view_manager_factory.h"
#include "chrome/browser/prerender/prerender_link_manager.h"
#include "chrome/browser/prerender/prerender_link_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
@@ -92,10 +95,11 @@ class TestInterstitialPageDelegate : public content::InterstitialPageDelegate {
virtual std::string GetHTMLContents() OVERRIDE { return std::string(); }
};
-// Used to get notified when a guest is created.
-class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient {
+class TestGuestViewManager : public GuestViewManager {
public:
- GuestContentBrowserClient() : web_contents_(NULL) {}
+ explicit TestGuestViewManager(content::BrowserContext* context) :
+ GuestViewManager(context),
+ web_contents_(NULL) {}
content::WebContents* WaitForGuestCreated() {
if (web_contents_)
@@ -107,13 +111,10 @@ class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient {
}
private:
- // ChromeContentBrowserClient implementation:
- virtual void GuestWebContentsAttached(
- content::WebContents* guest_web_contents,
- content::WebContents* embedder_web_contents,
- const base::DictionaryValue& extra_params) OVERRIDE {
- ChromeContentBrowserClient::GuestWebContentsAttached(
- guest_web_contents, embedder_web_contents, extra_params);
+ // GuestViewManager override:
+ virtual void AddGuest(int guest_instance_id,
+ content::WebContents* guest_web_contents) OVERRIDE{
+ GuestViewManager::AddGuest(guest_instance_id, guest_web_contents);
web_contents_ = guest_web_contents;
if (message_loop_runner_)
@@ -124,6 +125,32 @@ class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient {
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
};
+// Test factory for creating test instances of GuestViewManager.
+class TestGuestViewManagerFactory : public GuestViewManagerFactory {
+ public:
+ TestGuestViewManagerFactory() :
+ test_guest_view_manager_(NULL) {}
+
+ virtual ~TestGuestViewManagerFactory() {}
+
+ virtual GuestViewManager* CreateGuestViewManager(
+ content::BrowserContext* context) OVERRIDE {
+ return GetManager(context);
+ }
+
+ TestGuestViewManager* GetManager(content::BrowserContext* context) {
+ if (!test_guest_view_manager_) {
+ test_guest_view_manager_ = new TestGuestViewManager(context);
+ }
+ return test_guest_view_manager_;
+ }
+
+ private:
+ TestGuestViewManager* test_guest_view_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory);
+};
+
class WebContentsHiddenObserver : public content::WebContentsObserver {
public:
WebContentsHiddenObserver(content::WebContents* web_contents,
@@ -663,9 +690,6 @@ class WebViewTest : public extensions::PlatformAppBrowserTest {
}
void LoadAppWithGuest(const std::string& app_path) {
- GuestContentBrowserClient new_client;
- content::ContentBrowserClient* old_client =
- SetBrowserClientForTesting(&new_client);
ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED",
false);
@@ -673,8 +697,7 @@ class WebViewTest : public extensions::PlatformAppBrowserTest {
LoadAndLaunchPlatformApp(app_path.c_str());
ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
- guest_web_contents_ = new_client.WaitForGuestCreated();
- SetBrowserClientForTesting(old_client);
+ guest_web_contents_ = GetGuestViewManager()->WaitForGuestCreated();
}
void SendMessageToEmbedder(const std::string& message) {
@@ -712,8 +735,13 @@ class WebViewTest : public extensions::PlatformAppBrowserTest {
return embedder_web_contents_;
}
+ TestGuestViewManager* GetGuestViewManager() {
+ return factory_.GetManager(browser()->profile());
+ }
+
WebViewTest() : guest_web_contents_(NULL),
embedder_web_contents_(NULL) {
+ GuestViewManager::set_factory_for_testing(&factory_);
}
private:
@@ -729,6 +757,7 @@ class WebViewTest : public extensions::PlatformAppBrowserTest {
scoped_ptr<content::FakeSpeechRecognitionManager>
fake_speech_recognition_manager_;
+ TestGuestViewManagerFactory factory_;
// Note that these are only set if you launch app using LoadAppWithGuest().
content::WebContents* guest_web_contents_;
content::WebContents* embedder_web_contents_;
@@ -1209,10 +1238,6 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_InterstitialTeardown) {
LoadAndLaunchPlatformApp("web_view/interstitial_teardown");
ASSERT_TRUE(embedder_loaded_listener.WaitUntilSatisfied());
- GuestContentBrowserClient new_client;
- content::ContentBrowserClient* old_client =
- SetBrowserClientForTesting(&new_client);
-
// Now load the guest.
content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
ExtensionTestMessageListener second("GuestAddedToDom", false);
@@ -1222,8 +1247,8 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_InterstitialTeardown) {
ASSERT_TRUE(second.WaitUntilSatisfied());
// Wait for interstitial page to be shown in guest.
- content::WebContents* guest_web_contents = new_client.WaitForGuestCreated();
- SetBrowserClientForTesting(old_client);
+ content::WebContents* guest_web_contents =
+ GetGuestViewManager()->WaitForGuestCreated();
ASSERT_TRUE(guest_web_contents->GetRenderProcessHost()->IsIsolatedGuest());
WaitForInterstitial(guest_web_contents);

Powered by Google App Engine
This is Rietveld 408576698