Commit ac34346a authored by Mohamad Ahmadi's avatar Mohamad Ahmadi Committed by Commit Bot

Allows constructing web::WebTest with an instance of web::WebClient

tests that depend on ChromeWebClient (for e.g., early script injection) to
run.

web: :WebTest uses an instance of web::TestWebClient by default. This allows
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I8e36ac709f5c445392a817219cabc5c5152aa164
Reviewed-on: https://chromium-review.googlesource.com/840300Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526542}
parent 19eee98d
......@@ -11,6 +11,10 @@
class TestChromeBrowserState;
namespace web {
class WebClient;
} // namespace web
// Test fixture that exposes a TestChromeBrowserState to allow configuring
// the BrowserState in tests.
class ChromeWebTest : public web::WebTestWithWebState {
......@@ -19,6 +23,7 @@ class ChromeWebTest : public web::WebTestWithWebState {
protected:
ChromeWebTest();
explicit ChromeWebTest(std::unique_ptr<web::WebClient> web_client);
// WebTest implementation.
void SetUp() override;
void TearDown() override;
......
......@@ -9,6 +9,7 @@
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
#import "ios/chrome/browser/ui/fullscreen/legacy_fullscreen_controller.h"
#import "ios/web/public/web_client.h"
#import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -17,10 +18,12 @@
ChromeWebTest::~ChromeWebTest() {}
ChromeWebTest::ChromeWebTest() : web::WebTestWithWebState() {
TestChromeBrowserState::Builder browser_state_builder;
chrome_browser_state_ = browser_state_builder.Build();
}
ChromeWebTest::ChromeWebTest(std::unique_ptr<web::WebClient> web_client)
: web::WebTestWithWebState(std::move(web_client)),
chrome_browser_state_(TestChromeBrowserState::Builder().Build()) {}
ChromeWebTest::ChromeWebTest()
: chrome_browser_state_(TestChromeBrowserState::Builder().Build()) {}
void ChromeWebTest::SetUp() {
web::WebTestWithWebState::SetUp();
......
......@@ -5,6 +5,8 @@
#ifndef IOS_WEB_PUBLIC_TEST_WEB_TEST_H_
#define IOS_WEB_PUBLIC_TEST_WEB_TEST_H_
#include <memory>
#include "ios/web/public/test/fakes/test_browser_state.h"
#include "ios/web/public/test/scoped_testing_web_client.h"
#include "ios/web/public/test/test_web_thread_bundle.h"
......@@ -13,7 +15,7 @@
namespace web {
class BrowserState;
class TestWebClient;
class WebClient;
class WebTestRenderProcessCrashObserver;
// A test fixture for web tests that need a minimum environment set up that
......@@ -21,10 +23,11 @@ class WebTestRenderProcessCrashObserver;
class WebTest : public PlatformTest {
protected:
WebTest();
explicit WebTest(std::unique_ptr<web::WebClient> web_client);
~WebTest() override;
// Returns the WebClient that is used for testing.
TestWebClient* GetWebClient();
virtual web::WebClient* GetWebClient();
// Returns the BrowserState that is used for testing.
virtual BrowserState* GetBrowserState();
......
......@@ -24,14 +24,16 @@ class WebTestRenderProcessCrashObserver : public GlobalWebStateObserver {
}
};
WebTest::WebTest()
: web_client_(base::WrapUnique(new TestWebClient)),
WebTest::WebTest() : WebTest(base::WrapUnique(new TestWebClient)) {}
WebTest::WebTest(std::unique_ptr<web::WebClient> web_client)
: web_client_(std::move(web_client)),
crash_observer_(base::MakeUnique<WebTestRenderProcessCrashObserver>()) {}
WebTest::~WebTest() {}
TestWebClient* WebTest::GetWebClient() {
return static_cast<TestWebClient*>(web_client_.Get());
web::WebClient* WebTest::GetWebClient() {
return web_client_.Get();
}
BrowserState* WebTest::GetBrowserState() {
......
......@@ -5,6 +5,8 @@
#ifndef IOS_WEB_PUBLIC_TEST_WEB_TEST_WITH_WEB_STATE_H_
#define IOS_WEB_PUBLIC_TEST_WEB_TEST_WITH_WEB_STATE_H_
#include <memory>
#import "base/ios/block_types.h"
#include "base/message_loop/message_loop.h"
#include "ios/web/public/test/web_test.h"
......@@ -13,6 +15,7 @@
namespace web {
class WebClient;
class WebState;
// Base test fixture that provides WebState for testing.
......@@ -20,6 +23,7 @@ class WebTestWithWebState : public WebTest,
public base::MessageLoop::TaskObserver {
protected:
WebTestWithWebState();
explicit WebTestWithWebState(std::unique_ptr<web::WebClient> web_client);
~WebTestWithWebState() override;
// WebTest overrides.
......
......@@ -36,6 +36,10 @@ namespace web {
WebTestWithWebState::WebTestWithWebState() {}
WebTestWithWebState::WebTestWithWebState(
std::unique_ptr<web::WebClient> web_client)
: WebTest(std::move(web_client)) {}
WebTestWithWebState::~WebTestWithWebState() {}
void WebTestWithWebState::SetUp() {
......
......@@ -5,6 +5,8 @@
#ifndef IOS_WEB_TEST_WEB_TEST_WITH_WEB_CONTROLLER_H_
#define IOS_WEB_TEST_WEB_TEST_WITH_WEB_CONTROLLER_H_
#include <memory>
#import "ios/web/public/test/web_test_with_web_state.h"
#import "ios/web/web_state/ui/crw_web_controller.h"
......@@ -14,6 +16,7 @@ namespace web {
class WebTestWithWebController : public WebTestWithWebState {
protected:
WebTestWithWebController();
explicit WebTestWithWebController(std::unique_ptr<web::WebClient> web_client);
~WebTestWithWebController() override;
// Returns web controller for testing.
CRWWebController* web_controller();
......
......@@ -4,6 +4,7 @@
#import "ios/web/test/web_test_with_web_controller.h"
#import "ios/web/public/web_client.h"
#import "ios/web/web_state/web_state_impl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -14,6 +15,10 @@ namespace web {
WebTestWithWebController::WebTestWithWebController() {}
WebTestWithWebController::WebTestWithWebController(
std::unique_ptr<web::WebClient> web_client)
: WebTestWithWebState(std::move(web_client)) {}
WebTestWithWebController::~WebTestWithWebController() {}
CRWWebController* WebTestWithWebController::web_controller() {
......
......@@ -6,6 +6,7 @@
#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>
#include <memory>
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
......@@ -24,7 +25,14 @@ namespace web {
namespace {
// A test fixture for testing the page_script_util methods.
typedef WebTest PageScriptUtilTest;
class PageScriptUtilTest : public WebTest {
protected:
PageScriptUtilTest() : WebTest(std::make_unique<TestWebClient>()) {}
TestWebClient* GetWebClient() override {
return static_cast<TestWebClient*>(WebTest::GetWebClient());
}
};
// Tests that WKWebView early page script is a valid script that injects global
// __gCrWeb object.
......
......@@ -118,6 +118,9 @@ void WaitForZoomRendering(CRWWebController* webController,
// Test fixture for testing CRWWebController. Stubs out web view.
class CRWWebControllerTest : public WebTestWithWebController {
protected:
CRWWebControllerTest()
: WebTestWithWebController(std::make_unique<TestWebClient>()) {}
void SetUp() override {
WebTestWithWebController::SetUp();
mock_web_view_ = CreateMockWebView();
......@@ -137,6 +140,11 @@ class CRWWebControllerTest : public WebTestWithWebController {
WebTestWithWebController::TearDown();
}
TestWebClient* GetWebClient() override {
return static_cast<TestWebClient*>(
WebTestWithWebController::GetWebClient());
}
// The value for web view OCMock objects to expect for |-setFrame:|.
CGRect GetExpectedWebViewFrame() const {
CGSize container_view_size = [UIScreen mainScreen].bounds.size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment