Commit 5fdcca81 authored by Eugene But's avatar Eugene But Committed by Chromium LUCI CQ

[ios] Use Fake term for ios/web/test/fake names

This CL leaves old headers to avoid changing the clients in
one large CL. Those old headers import new headers and typedef
the old names to point to the new names.

Bug: 688063
Change-Id: I31c34463d47e31335dd0909fe816707733cf1a1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2583386
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835741}
parent 9a10fc2d
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace web { namespace web {
class WebState; class WebState;
class TestWebState; class FakeWebState;
// Decides the navigation policy for a web state. // Decides the navigation policy for a web state.
class WebStatePolicyDecider { class WebStatePolicyDecider {
...@@ -141,7 +141,7 @@ class WebStatePolicyDecider { ...@@ -141,7 +141,7 @@ class WebStatePolicyDecider {
private: private:
friend class WebStateImpl; friend class WebStateImpl;
friend class TestWebState; friend class FakeWebState;
// Resets the current web state. // Resets the current web state.
void ResetWebState(); void ResetWebState();
......
...@@ -42,6 +42,8 @@ source_set("fakes") { ...@@ -42,6 +42,8 @@ source_set("fakes") {
"crw_fake_web_state_policy_decider.mm", "crw_fake_web_state_policy_decider.mm",
"crw_fake_web_view_content_view.h", "crw_fake_web_view_content_view.h",
"crw_fake_web_view_content_view.mm", "crw_fake_web_view_content_view.mm",
"fake_browser_state.cc",
"fake_browser_state.h",
"fake_cookie_store.cc", "fake_cookie_store.cc",
"fake_cookie_store.h", "fake_cookie_store.h",
"fake_download_controller_delegate.h", "fake_download_controller_delegate.h",
...@@ -52,27 +54,31 @@ source_set("fakes") { ...@@ -52,27 +54,31 @@ source_set("fakes") {
"fake_find_in_page_manager_delegate.mm", "fake_find_in_page_manager_delegate.mm",
"fake_navigation_context.h", "fake_navigation_context.h",
"fake_navigation_context.mm", "fake_navigation_context.mm",
"fake_navigation_manager.h",
"fake_navigation_manager.mm",
"fake_web_client.h",
"fake_web_client.mm",
"fake_web_frame.cc", "fake_web_frame.cc",
"fake_web_frame.h", "fake_web_frame.h",
"fake_web_frames_manager.h", "fake_web_frames_manager.h",
"fake_web_frames_manager.mm", "fake_web_frames_manager.mm",
"fake_web_state.h",
"fake_web_state.mm",
"fake_web_state_observer.h",
"fake_web_state_observer.mm",
"fake_web_state_observer_util.h",
"fake_web_state_observer_util.mm",
"fake_web_state_policy_decider.h", "fake_web_state_policy_decider.h",
"fake_web_state_policy_decider.mm", "fake_web_state_policy_decider.mm",
"test_browser_state.cc",
"test_browser_state.h", "test_browser_state.h",
"test_java_script_dialog_presenter.h", "test_java_script_dialog_presenter.h",
"test_java_script_dialog_presenter.mm", "test_java_script_dialog_presenter.mm",
"test_navigation_manager.h", "test_navigation_manager.h",
"test_navigation_manager.mm",
"test_web_client.h", "test_web_client.h",
"test_web_client.mm",
"test_web_state.h", "test_web_state.h",
"test_web_state.mm",
"test_web_state_delegate.h", "test_web_state_delegate.h",
"test_web_state_delegate.mm", "test_web_state_delegate.mm",
"test_web_state_observer.h", "test_web_state_observer.h",
"test_web_state_observer.mm",
"test_web_state_observer_util.h", "test_web_state_observer_util.h",
"test_web_state_observer_util.mm",
] ]
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ios/web/public/test/fakes/test_browser_state.h" #include "ios/web/public/test/fakes/fake_browser_state.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
...@@ -46,44 +46,44 @@ class TestContextURLRequestContextGetter : public net::URLRequestContextGetter { ...@@ -46,44 +46,44 @@ class TestContextURLRequestContextGetter : public net::URLRequestContextGetter {
} // namespace } // namespace
// static // static
const char TestBrowserState::kCorsExemptTestHeaderName[] = "ExemptTest"; const char FakeBrowserState::kCorsExemptTestHeaderName[] = "ExemptTest";
TestBrowserState::TestBrowserState() : is_off_the_record_(false) {} FakeBrowserState::FakeBrowserState() : is_off_the_record_(false) {}
TestBrowserState::~TestBrowserState() {} FakeBrowserState::~FakeBrowserState() {}
bool TestBrowserState::IsOffTheRecord() const { bool FakeBrowserState::IsOffTheRecord() const {
return is_off_the_record_; return is_off_the_record_;
} }
base::FilePath TestBrowserState::GetStatePath() const { base::FilePath FakeBrowserState::GetStatePath() const {
return base::FilePath(); return base::FilePath();
} }
net::URLRequestContextGetter* TestBrowserState::GetRequestContext() { net::URLRequestContextGetter* FakeBrowserState::GetRequestContext() {
if (!request_context_) if (!request_context_)
request_context_ = new TestContextURLRequestContextGetter(this); request_context_ = new TestContextURLRequestContextGetter(this);
return request_context_.get(); return request_context_.get();
} }
void TestBrowserState::UpdateCorsExemptHeader( void FakeBrowserState::UpdateCorsExemptHeader(
network::mojom::NetworkContextParams* params) { network::mojom::NetworkContextParams* params) {
DCHECK(params); DCHECK(params);
params->cors_exempt_header_list.push_back(kCorsExemptTestHeaderName); params->cors_exempt_header_list.push_back(kCorsExemptTestHeaderName);
} }
void TestBrowserState::SetOffTheRecord(bool flag) { void FakeBrowserState::SetOffTheRecord(bool flag) {
is_off_the_record_ = flag; is_off_the_record_ = flag;
} }
scoped_refptr<network::SharedURLLoaderFactory> scoped_refptr<network::SharedURLLoaderFactory>
TestBrowserState::GetSharedURLLoaderFactory() { FakeBrowserState::GetSharedURLLoaderFactory() {
return test_shared_url_loader_factory_ return test_shared_url_loader_factory_
? test_shared_url_loader_factory_ ? test_shared_url_loader_factory_
: BrowserState::GetSharedURLLoaderFactory(); : BrowserState::GetSharedURLLoaderFactory();
} }
void TestBrowserState::SetSharedURLLoaderFactory( void FakeBrowserState::SetSharedURLLoaderFactory(
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory) { scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory) {
test_shared_url_loader_factory_ = std::move(shared_url_loader_factory); test_shared_url_loader_factory_ = std::move(shared_url_loader_factory);
} }
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_FAKE_BROWSER_STATE_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_FAKE_BROWSER_STATE_H_
#include "base/memory/ref_counted.h"
#include "ios/web/public/browser_state.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace web {
class FakeBrowserState : public BrowserState {
public:
static const char kCorsExemptTestHeaderName[];
FakeBrowserState();
~FakeBrowserState() override;
// BrowserState:
bool IsOffTheRecord() const override;
base::FilePath GetStatePath() const override;
net::URLRequestContextGetter* GetRequestContext() override;
void UpdateCorsExemptHeader(
network::mojom::NetworkContextParams* params) override;
scoped_refptr<network::SharedURLLoaderFactory> GetSharedURLLoaderFactory()
override;
// Sets a SharedURLLoaderFactory for test.
void SetSharedURLLoaderFactory(
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory);
// Makes |IsOffTheRecord| return the given flag value.
void SetOffTheRecord(bool flag);
private:
scoped_refptr<net::URLRequestContextGetter> request_context_;
bool is_off_the_record_;
// A SharedURLLoaderFactory for test.
scoped_refptr<network::SharedURLLoaderFactory>
test_shared_url_loader_factory_;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_FAKE_BROWSER_STATE_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_FAKE_NAVIGATION_MANAGER_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_FAKE_NAVIGATION_MANAGER_H_
#include "base/callback.h"
#include "ios/web/public/deprecated/navigation_item_list.h"
#import "ios/web/public/navigation/navigation_item.h"
#import "ios/web/public/navigation/navigation_manager.h"
#include "ui/base/page_transition_types.h"
namespace web {
// A minimal implementation of web::NavigationManager that raises NOTREACHED()
// on most calls.
class FakeNavigationManager : public NavigationManager {
public:
FakeNavigationManager();
~FakeNavigationManager() override;
BrowserState* GetBrowserState() const override;
WebState* GetWebState() const override;
NavigationItem* GetVisibleItem() const override;
NavigationItem* GetLastCommittedItem() const override;
NavigationItem* GetPendingItem() const override;
NavigationItem* GetTransientItem() const override;
void DiscardNonCommittedItems() override;
void LoadURLWithParams(const NavigationManager::WebLoadParams&) override;
void LoadIfNecessary() override;
void AddTransientURLRewriter(
BrowserURLRewriter::URLRewriter rewriter) override;
int GetItemCount() const override;
NavigationItem* GetItemAtIndex(size_t index) const override;
int GetIndexOfItem(const NavigationItem* item) const override;
int GetPendingItemIndex() const override;
int GetLastCommittedItemIndex() const override;
bool CanGoBack() const override;
bool CanGoForward() const override;
bool CanGoToOffset(int offset) const override;
void GoBack() override;
void GoForward() override;
void GoToIndex(int index) override;
void Reload(ReloadType reload_type, bool check_for_reposts) override;
void ReloadWithUserAgentType(UserAgentType user_agent_type) override;
NavigationItemList GetBackwardItems() const override;
NavigationItemList GetForwardItems() const override;
void Restore(int last_committed_item_index,
std::vector<std::unique_ptr<NavigationItem>> items) override;
bool IsRestoreSessionInProgress() const override;
void AddRestoreCompletionCallback(base::OnceClosure callback) override;
// Setters for test data.
// Sets a value for last committed item that will be returned by
// GetLastCommittedItem().
void SetLastCommittedItem(NavigationItem* item);
// Sets a value for pending item that will be returned by GetPendingItem().
void SetPendingItem(NavigationItem* item);
// Sets a value for the index that will be returned by GetPendingItemIndex().
void SetPendingItemIndex(int index);
// Sets a value for visible item that will be returned by GetVisibleItem().
void SetVisibleItem(NavigationItem* item);
// Adds an item to items_. Affects the return values for, GetItemCount(),
// GetItemAtIndex(), and GetCurrentItemIndex().
void AddItem(const GURL& url, ui::PageTransition transition);
// Sets the index to be returned by GetLastCommittedItemIndex(). |index| must
// be either -1 or between 0 and GetItemCount()-1, inclusively.
void SetLastCommittedItemIndex(const int index);
// Sets the index to be returned by GetBrowserState().
void SetBrowserState(web::BrowserState* browser_state);
// Returns whether LoadURLWithParams has been called.
bool LoadURLWithParamsWasCalled();
// Returns whether LoadIfNecessary has been called.
bool LoadIfNecessaryWasCalled();
// Returns whether Reload has been called;
bool ReloadWasCalled();
private:
// A list of items constructed by calling AddItem().
web::ScopedNavigationItemList items_;
int items_index_;
// Individual backing instance variables for Set* test set up methods.
NavigationItem* pending_item_;
int pending_item_index_;
NavigationItem* last_committed_item_;
NavigationItem* visible_item_;
web::BrowserState* browser_state_;
bool load_url_with_params_was_called_;
bool load_if_necessary_was_called_;
bool reload_was_called_;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_FAKE_NAVIGATION_MANAGER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/web/public/test/fakes/test_navigation_manager.h" #import "ios/web/public/test/fakes/fake_navigation_manager.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
namespace web { namespace web {
TestNavigationManager::TestNavigationManager() FakeNavigationManager::FakeNavigationManager()
: items_index_(-1), : items_index_(-1),
pending_item_(nullptr), pending_item_(nullptr),
pending_item_index_(-1), pending_item_index_(-1),
...@@ -21,73 +21,73 @@ TestNavigationManager::TestNavigationManager() ...@@ -21,73 +21,73 @@ TestNavigationManager::TestNavigationManager()
load_if_necessary_was_called_(false), load_if_necessary_was_called_(false),
reload_was_called_(false) {} reload_was_called_(false) {}
TestNavigationManager::~TestNavigationManager() {} FakeNavigationManager::~FakeNavigationManager() {}
BrowserState* TestNavigationManager::GetBrowserState() const { BrowserState* FakeNavigationManager::GetBrowserState() const {
return browser_state_; return browser_state_;
} }
WebState* TestNavigationManager::GetWebState() const { WebState* FakeNavigationManager::GetWebState() const {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
NavigationItem* TestNavigationManager::GetVisibleItem() const { NavigationItem* FakeNavigationManager::GetVisibleItem() const {
return visible_item_; return visible_item_;
} }
void TestNavigationManager::SetVisibleItem(NavigationItem* item) { void FakeNavigationManager::SetVisibleItem(NavigationItem* item) {
visible_item_ = item; visible_item_ = item;
} }
NavigationItem* TestNavigationManager::GetLastCommittedItem() const { NavigationItem* FakeNavigationManager::GetLastCommittedItem() const {
return last_committed_item_; return last_committed_item_;
} }
void TestNavigationManager::SetLastCommittedItem(NavigationItem* item) { void FakeNavigationManager::SetLastCommittedItem(NavigationItem* item) {
last_committed_item_ = item; last_committed_item_ = item;
} }
NavigationItem* TestNavigationManager::GetPendingItem() const { NavigationItem* FakeNavigationManager::GetPendingItem() const {
return pending_item_; return pending_item_;
} }
void TestNavigationManager::SetPendingItem(NavigationItem* item) { void FakeNavigationManager::SetPendingItem(NavigationItem* item) {
pending_item_ = item; pending_item_ = item;
} }
web::NavigationItem* TestNavigationManager::GetTransientItem() const { web::NavigationItem* FakeNavigationManager::GetTransientItem() const {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
void TestNavigationManager::DiscardNonCommittedItems() { void FakeNavigationManager::DiscardNonCommittedItems() {
SetPendingItem(nullptr); SetPendingItem(nullptr);
} }
void TestNavigationManager::LoadURLWithParams( void FakeNavigationManager::LoadURLWithParams(
const NavigationManager::WebLoadParams& params) { const NavigationManager::WebLoadParams& params) {
load_url_with_params_was_called_ = true; load_url_with_params_was_called_ = true;
} }
void TestNavigationManager::LoadIfNecessary() { void FakeNavigationManager::LoadIfNecessary() {
load_if_necessary_was_called_ = true; load_if_necessary_was_called_ = true;
} }
void TestNavigationManager::AddTransientURLRewriter( void FakeNavigationManager::AddTransientURLRewriter(
BrowserURLRewriter::URLRewriter rewriter) { BrowserURLRewriter::URLRewriter rewriter) {
NOTREACHED(); NOTREACHED();
} }
int TestNavigationManager::GetItemCount() const { int FakeNavigationManager::GetItemCount() const {
return items_.size(); return items_.size();
} }
web::NavigationItem* TestNavigationManager::GetItemAtIndex(size_t index) const { web::NavigationItem* FakeNavigationManager::GetItemAtIndex(size_t index) const {
return items_[index].get(); return items_[index].get();
} }
int TestNavigationManager::GetIndexOfItem( int FakeNavigationManager::GetIndexOfItem(
const web::NavigationItem* item) const { const web::NavigationItem* item) const {
for (size_t index = 0; index < items_.size(); ++index) { for (size_t index = 0; index < items_.size(); ++index) {
if (items_[index].get() == item) if (items_[index].get() == item)
...@@ -96,84 +96,84 @@ int TestNavigationManager::GetIndexOfItem( ...@@ -96,84 +96,84 @@ int TestNavigationManager::GetIndexOfItem(
return -1; return -1;
} }
void TestNavigationManager::SetLastCommittedItemIndex(const int index) { void FakeNavigationManager::SetLastCommittedItemIndex(const int index) {
DCHECK(index == -1 || index >= 0 && index < GetItemCount()); DCHECK(index == -1 || index >= 0 && index < GetItemCount());
items_index_ = index; items_index_ = index;
} }
int TestNavigationManager::GetLastCommittedItemIndex() const { int FakeNavigationManager::GetLastCommittedItemIndex() const {
return items_index_; return items_index_;
} }
int TestNavigationManager::GetPendingItemIndex() const { int FakeNavigationManager::GetPendingItemIndex() const {
return pending_item_index_; return pending_item_index_;
} }
void TestNavigationManager::SetPendingItemIndex(int index) { void FakeNavigationManager::SetPendingItemIndex(int index) {
pending_item_index_ = index; pending_item_index_ = index;
} }
bool TestNavigationManager::CanGoBack() const { bool FakeNavigationManager::CanGoBack() const {
return items_index_ > 0; return items_index_ > 0;
} }
bool TestNavigationManager::CanGoForward() const { bool FakeNavigationManager::CanGoForward() const {
return items_index_ < GetItemCount() - 1; return items_index_ < GetItemCount() - 1;
} }
bool TestNavigationManager::CanGoToOffset(int offset) const { bool FakeNavigationManager::CanGoToOffset(int offset) const {
NOTREACHED(); NOTREACHED();
return false; return false;
} }
void TestNavigationManager::GoBack() { void FakeNavigationManager::GoBack() {
items_index_--; items_index_--;
} }
void TestNavigationManager::GoForward() { void FakeNavigationManager::GoForward() {
items_index_++; items_index_++;
} }
void TestNavigationManager::GoToIndex(int index) { void FakeNavigationManager::GoToIndex(int index) {
NOTREACHED(); NOTREACHED();
} }
void TestNavigationManager::Reload(ReloadType reload_type, void FakeNavigationManager::Reload(ReloadType reload_type,
bool check_for_repost) { bool check_for_repost) {
reload_was_called_ = true; reload_was_called_ = true;
} }
void TestNavigationManager::ReloadWithUserAgentType( void FakeNavigationManager::ReloadWithUserAgentType(
UserAgentType user_agent_type) { UserAgentType user_agent_type) {
NOTREACHED(); NOTREACHED();
} }
NavigationItemList TestNavigationManager::GetBackwardItems() const { NavigationItemList FakeNavigationManager::GetBackwardItems() const {
return NavigationItemList(); return NavigationItemList();
} }
NavigationItemList TestNavigationManager::GetForwardItems() const { NavigationItemList FakeNavigationManager::GetForwardItems() const {
return NavigationItemList(); return NavigationItemList();
} }
void TestNavigationManager::Restore( void FakeNavigationManager::Restore(
int last_committed_item_index, int last_committed_item_index,
std::vector<std::unique_ptr<NavigationItem>> items) { std::vector<std::unique_ptr<NavigationItem>> items) {
NOTREACHED(); NOTREACHED();
} }
bool TestNavigationManager::IsRestoreSessionInProgress() const { bool FakeNavigationManager::IsRestoreSessionInProgress() const {
return false; return false;
} }
void TestNavigationManager::AddRestoreCompletionCallback( void FakeNavigationManager::AddRestoreCompletionCallback(
base::OnceClosure callback) { base::OnceClosure callback) {
NOTREACHED(); NOTREACHED();
} }
// Adds a new navigation item of |transition| type at the end of this // Adds a new navigation item of |transition| type at the end of this
// navigation manager. // navigation manager.
void TestNavigationManager::AddItem(const GURL& url, void FakeNavigationManager::AddItem(const GURL& url,
ui::PageTransition transition) { ui::PageTransition transition) {
items_.push_back(web::NavigationItem::Create()); items_.push_back(web::NavigationItem::Create());
items_.back()->SetTransitionType(transition); items_.back()->SetTransitionType(transition);
...@@ -181,19 +181,19 @@ void TestNavigationManager::AddItem(const GURL& url, ...@@ -181,19 +181,19 @@ void TestNavigationManager::AddItem(const GURL& url,
SetLastCommittedItemIndex(GetItemCount() - 1); SetLastCommittedItemIndex(GetItemCount() - 1);
} }
void TestNavigationManager::SetBrowserState(web::BrowserState* browser_state) { void FakeNavigationManager::SetBrowserState(web::BrowserState* browser_state) {
browser_state_ = browser_state; browser_state_ = browser_state;
} }
bool TestNavigationManager::LoadURLWithParamsWasCalled() { bool FakeNavigationManager::LoadURLWithParamsWasCalled() {
return load_url_with_params_was_called_; return load_url_with_params_was_called_;
} }
bool TestNavigationManager::LoadIfNecessaryWasCalled() { bool FakeNavigationManager::LoadIfNecessaryWasCalled() {
return load_if_necessary_was_called_; return load_if_necessary_was_called_;
} }
bool TestNavigationManager::ReloadWasCalled() { bool FakeNavigationManager::ReloadWasCalled() {
return reload_was_called_; return reload_was_called_;
} }
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_CLIENT_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_CLIENT_H_
#import <Foundation/Foundation.h>
#include <vector>
#import "ios/web/public/web_client.h"
#include "net/ssl/ssl_info.h"
#include "url/gurl.h"
namespace web {
class BrowserState;
// A WebClient used for testing purposes.
class FakeWebClient : public web::WebClient {
public:
FakeWebClient();
~FakeWebClient() override;
// WebClient implementation.
void AddAdditionalSchemes(Schemes* schemes) const override;
// Returns true for kTestWebUIScheme URL.
bool IsAppSpecificURL(const GURL& url) const override;
bool ShouldBlockUrlDuringRestore(const GURL& url,
WebState* web_state) const override;
void AddSerializableData(web::SerializableUserDataManager* user_data_manager,
web::WebState* web_state) override;
std::string GetUserAgent(UserAgentType type) const override;
// Returns |plugin_not_supported_text_| as the text to be displayed for an
// unsupported plugin.
base::string16 GetPluginNotSupportedText() const override;
base::RefCountedMemory* GetDataResourceBytes(int id) const override;
NSString* GetDocumentStartScriptForMainFrame(
BrowserState* browser_state) const override;
NSString* GetDocumentStartScriptForAllFrames(
BrowserState* browser_state) const override;
void AllowCertificateError(WebState*,
int cert_error,
const net::SSLInfo&,
const GURL&,
bool overridable,
int64_t navigation_id,
base::OnceCallback<void(bool)>) override;
void PrepareErrorPage(WebState* web_state,
const GURL& url,
NSError* error,
bool is_post,
bool is_off_the_record,
const base::Optional<net::SSLInfo>& info,
int64_t navigation_id,
base::OnceCallback<void(NSString*)> callback) override;
UIView* GetWindowedContainer() override;
UserAgentType GetDefaultUserAgent(id<UITraitEnvironment> web_view,
const GURL& url) override;
// Sets |plugin_not_supported_text_|.
void SetPluginNotSupportedText(const base::string16& text);
// Changes Early Page Script for testing purposes.
void SetEarlyPageScript(NSString* page_script);
// Overrides AllowCertificateError response.
void SetAllowCertificateErrors(bool flag);
// Accessors for last arguments passed to AllowCertificateError.
int last_cert_error_code() const { return last_cert_error_code_; }
const net::SSLInfo& last_cert_error_ssl_info() const {
return last_cert_error_ssl_info_;
}
const GURL& last_cert_error_request_url() const {
return last_cert_error_request_url_;
}
bool last_cert_error_overridable() { return last_cert_error_overridable_; }
void SetDefaultUserAgent(UserAgentType type) { default_user_agent_ = type; }
private:
base::string16 plugin_not_supported_text_;
NSString* early_page_script_ = nil;
// Last arguments passed to AllowCertificateError.
int last_cert_error_code_ = 0;
net::SSLInfo last_cert_error_ssl_info_;
GURL last_cert_error_request_url_;
bool last_cert_error_overridable_ = true;
bool allow_certificate_errors_ = false;
UserAgentType default_user_agent_ = UserAgentType::MOBILE;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_CLIENT_H_
...@@ -22,39 +22,39 @@ ...@@ -22,39 +22,39 @@
namespace web { namespace web {
TestWebClient::TestWebClient() = default; FakeWebClient::FakeWebClient() = default;
TestWebClient::~TestWebClient() = default; FakeWebClient::~FakeWebClient() = default;
void TestWebClient::AddAdditionalSchemes(Schemes* schemes) const { void FakeWebClient::AddAdditionalSchemes(Schemes* schemes) const {
schemes->standard_schemes.push_back(kTestWebUIScheme); schemes->standard_schemes.push_back(kTestWebUIScheme);
schemes->standard_schemes.push_back(kTestAppSpecificScheme); schemes->standard_schemes.push_back(kTestAppSpecificScheme);
} }
bool TestWebClient::IsAppSpecificURL(const GURL& url) const { bool FakeWebClient::IsAppSpecificURL(const GURL& url) const {
return url.SchemeIs(kTestWebUIScheme) || url.SchemeIs(kTestAppSpecificScheme); return url.SchemeIs(kTestWebUIScheme) || url.SchemeIs(kTestAppSpecificScheme);
} }
bool TestWebClient::ShouldBlockUrlDuringRestore(const GURL& url, bool FakeWebClient::ShouldBlockUrlDuringRestore(const GURL& url,
WebState* web_state) const { WebState* web_state) const {
return false; return false;
} }
void TestWebClient::AddSerializableData( void FakeWebClient::AddSerializableData(
web::SerializableUserDataManager* user_data_manager, web::SerializableUserDataManager* user_data_manager,
web::WebState* web_state) {} web::WebState* web_state) {}
base::string16 TestWebClient::GetPluginNotSupportedText() const { base::string16 FakeWebClient::GetPluginNotSupportedText() const {
return plugin_not_supported_text_; return plugin_not_supported_text_;
} }
std::string TestWebClient::GetUserAgent(UserAgentType type) const { std::string FakeWebClient::GetUserAgent(UserAgentType type) const {
if (type == UserAgentType::DESKTOP) if (type == UserAgentType::DESKTOP)
return "Chromium/66.0.3333.0 CFNetwork/893.14 Darwin/16.7.0 Desktop"; return "Chromium/66.0.3333.0 CFNetwork/893.14 Darwin/16.7.0 Desktop";
return "Chromium/66.0.3333.0 CFNetwork/893.14 Darwin/16.7.0 Mobile"; return "Chromium/66.0.3333.0 CFNetwork/893.14 Darwin/16.7.0 Mobile";
} }
base::RefCountedMemory* TestWebClient::GetDataResourceBytes( base::RefCountedMemory* FakeWebClient::GetDataResourceBytes(
int resource_id) const { int resource_id) const {
if (!ui::ResourceBundle::HasSharedInstance()) if (!ui::ResourceBundle::HasSharedInstance())
return nullptr; return nullptr;
...@@ -62,25 +62,25 @@ base::RefCountedMemory* TestWebClient::GetDataResourceBytes( ...@@ -62,25 +62,25 @@ base::RefCountedMemory* TestWebClient::GetDataResourceBytes(
resource_id); resource_id);
} }
NSString* TestWebClient::GetDocumentStartScriptForMainFrame( NSString* FakeWebClient::GetDocumentStartScriptForMainFrame(
BrowserState* browser_state) const { BrowserState* browser_state) const {
return early_page_script_ ? early_page_script_ : @""; return early_page_script_ ? early_page_script_ : @"";
} }
NSString* TestWebClient::GetDocumentStartScriptForAllFrames( NSString* FakeWebClient::GetDocumentStartScriptForAllFrames(
BrowserState* browser_state) const { BrowserState* browser_state) const {
return web::test::GetPageScript(@"all_frames_web_test_bundle"); return web::test::GetPageScript(@"all_frames_web_test_bundle");
} }
void TestWebClient::SetPluginNotSupportedText(const base::string16& text) { void FakeWebClient::SetPluginNotSupportedText(const base::string16& text) {
plugin_not_supported_text_ = text; plugin_not_supported_text_ = text;
} }
void TestWebClient::SetEarlyPageScript(NSString* page_script) { void FakeWebClient::SetEarlyPageScript(NSString* page_script) {
early_page_script_ = [page_script copy]; early_page_script_ = [page_script copy];
} }
void TestWebClient::AllowCertificateError( void FakeWebClient::AllowCertificateError(
WebState* web_state, WebState* web_state,
int cert_error, int cert_error,
const net::SSLInfo& ssl_info, const net::SSLInfo& ssl_info,
...@@ -99,11 +99,11 @@ void TestWebClient::AllowCertificateError( ...@@ -99,11 +99,11 @@ void TestWebClient::AllowCertificateError(
base::BindOnce(std::move(callback), allow_certificate_errors_)); base::BindOnce(std::move(callback), allow_certificate_errors_));
} }
void TestWebClient::SetAllowCertificateErrors(bool flag) { void FakeWebClient::SetAllowCertificateErrors(bool flag) {
allow_certificate_errors_ = flag; allow_certificate_errors_ = flag;
} }
void TestWebClient::PrepareErrorPage( void FakeWebClient::PrepareErrorPage(
WebState* web_state, WebState* web_state,
const GURL& url, const GURL& url,
NSError* error, NSError* error,
...@@ -117,11 +117,11 @@ void TestWebClient::PrepareErrorPage( ...@@ -117,11 +117,11 @@ void TestWebClient::PrepareErrorPage(
web_state, url, error, is_post, is_off_the_record, cert_status))); web_state, url, error, is_post, is_off_the_record, cert_status)));
} }
UIView* TestWebClient::GetWindowedContainer() { UIView* FakeWebClient::GetWindowedContainer() {
return UIApplication.sharedApplication.keyWindow.rootViewController.view; return UIApplication.sharedApplication.keyWindow.rootViewController.view;
} }
UserAgentType TestWebClient::GetDefaultUserAgent( UserAgentType FakeWebClient::GetDefaultUserAgent(
id<UITraitEnvironment> web_view, id<UITraitEnvironment> web_view,
const GURL& url) { const GURL& url) {
return default_user_agent_; return default_user_agent_;
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_H_
#include <stdint.h>
#include <memory>
#include <string>
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "ios/web/public/deprecated/url_verification_constants.h"
#import "ios/web/public/navigation/navigation_manager.h"
#import "ios/web/public/navigation/web_state_policy_decider.h"
#import "ios/web/public/web_state.h"
#include "ios/web/public/web_state_observer.h"
#include "url/gurl.h"
@class NSURLRequest;
@class NSURLResponse;
namespace web {
// Minimal implementation of WebState, to be used in tests.
class FakeWebState : public WebState {
public:
FakeWebState();
~FakeWebState() override;
// WebState implementation.
Getter CreateDefaultGetter() override;
OnceGetter CreateDefaultOnceGetter() override;
WebStateDelegate* GetDelegate() override;
void SetDelegate(WebStateDelegate* delegate) override;
bool IsWebUsageEnabled() const override;
void SetWebUsageEnabled(bool enabled) override;
UIView* GetView() override;
void DidCoverWebContent() override;
void DidRevealWebContent() override;
void WasShown() override;
void WasHidden() override;
void SetKeepRenderProcessAlive(bool keep_alive) override;
BrowserState* GetBrowserState() const override;
void OpenURL(const OpenURLParams& params) override {}
void Stop() override {}
const NavigationManager* GetNavigationManager() const override;
NavigationManager* GetNavigationManager() override;
const WebFramesManager* GetWebFramesManager() const override;
WebFramesManager* GetWebFramesManager() override;
const SessionCertificatePolicyCache* GetSessionCertificatePolicyCache()
const override;
SessionCertificatePolicyCache* GetSessionCertificatePolicyCache() override;
CRWSessionStorage* BuildSessionStorage() override;
CRWJSInjectionReceiver* GetJSInjectionReceiver() const override;
void LoadData(NSData* data, NSString* mime_type, const GURL& url) override;
void ExecuteJavaScript(const base::string16& javascript) override;
void ExecuteJavaScript(const base::string16& javascript,
JavaScriptResultCallback callback) override;
void ExecuteUserJavaScript(NSString* javaScript) override;
const std::string& GetContentsMimeType() const override;
bool ContentIsHTML() const override;
const base::string16& GetTitle() const override;
bool IsLoading() const override;
double GetLoadingProgress() const override;
bool IsVisible() const override;
bool IsCrashed() const override;
bool IsEvicted() const override;
bool IsBeingDestroyed() const override;
const GURL& GetVisibleURL() const override;
const GURL& GetLastCommittedURL() const override;
GURL GetCurrentURL(URLVerificationTrustLevel* trust_level) const override;
base::CallbackListSubscription AddScriptCommandCallback(
const ScriptCommandCallback& callback,
const std::string& command_prefix) override;
CRWWebViewProxyType GetWebViewProxy() const override;
bool IsShowingWebInterstitial() const override;
WebInterstitial* GetWebInterstitial() const override;
void AddObserver(WebStateObserver* observer) override;
void RemoveObserver(WebStateObserver* observer) override;
void CloseWebState() override;
void AddPolicyDecider(WebStatePolicyDecider* decider) override;
void RemovePolicyDecider(WebStatePolicyDecider* decider) override;
void DidChangeVisibleSecurityState() override;
bool HasOpener() const override;
void SetHasOpener(bool has_opener) override;
bool CanTakeSnapshot() const override;
void TakeSnapshot(const gfx::RectF& rect, SnapshotCallback callback) override;
void CreateFullPagePdf(base::OnceCallback<void(NSData*)> callback) override;
// Setters for test data.
void SetBrowserState(BrowserState* browser_state);
void SetJSInjectionReceiver(CRWJSInjectionReceiver* injection_receiver);
void SetTitle(const base::string16& title);
void SetContentIsHTML(bool content_is_html);
void SetContentsMimeType(const std::string& mime_type);
void SetLoading(bool is_loading);
void SetCurrentURL(const GURL& url);
void SetVisibleURL(const GURL& url);
void SetTrustLevel(URLVerificationTrustLevel trust_level);
void SetNavigationManager(
std::unique_ptr<NavigationManager> navigation_manager);
void SetWebFramesManager(
std::unique_ptr<WebFramesManager> web_frames_manager);
void SetView(UIView* view);
void SetIsCrashed(bool value);
void SetIsEvicted(bool value);
void SetWebViewProxy(CRWWebViewProxyType web_view_proxy);
void ClearLastExecutedJavascript();
void SetCanTakeSnapshot(bool can_take_snapshot);
// Getters for test data.
// Uses |policy_deciders| to return whether the navigation corresponding to
// |request| should be allowed. Defaults to PolicyDecision::Allow().
WebStatePolicyDecider::PolicyDecision ShouldAllowRequest(
NSURLRequest* request,
const WebStatePolicyDecider::RequestInfo& request_info);
// Uses |policy_deciders| to determine whether the navigation corresponding to
// |response| should be allowed. Calls |callback| with the decision. Defaults
// to PolicyDecision::Allow().
void ShouldAllowResponse(
NSURLResponse* response,
bool for_main_frame,
base::OnceCallback<void(WebStatePolicyDecider::PolicyDecision)> callback);
base::string16 GetLastExecutedJavascript() const;
NSData* GetLastLoadedData() const;
bool IsClosed() const;
// Notifier for tests.
void OnPageLoaded(PageLoadCompletionStatus load_completion_status);
void OnNavigationStarted(NavigationContext* navigation_context);
void OnNavigationRedirected(NavigationContext* context);
void OnNavigationFinished(NavigationContext* navigation_context);
void OnRenderProcessGone();
void OnBackForwardStateChanged();
void OnVisibleSecurityStateChanged();
void OnWebFrameDidBecomeAvailable(WebFrame* frame);
void OnWebFrameWillBecomeUnavailable(WebFrame* frame);
private:
BrowserState* browser_state_;
CRWJSInjectionReceiver* injection_receiver_;
bool web_usage_enabled_;
bool is_loading_;
bool is_visible_;
bool is_crashed_;
bool is_evicted_;
bool has_opener_;
bool can_take_snapshot_;
bool is_closed_;
GURL url_;
base::string16 title_;
base::string16 last_executed_javascript_;
URLVerificationTrustLevel trust_level_;
bool content_is_html_;
std::string mime_type_;
std::unique_ptr<NavigationManager> navigation_manager_;
std::unique_ptr<WebFramesManager> web_frames_manager_;
UIView* view_;
CRWWebViewProxyType web_view_proxy_;
NSData* last_loaded_data_;
base::RepeatingCallbackList<ScriptCommandCallbackSignature> callback_list_;
// A list of observers notified when page state changes. Weak references.
base::ObserverList<WebStateObserver, true>::Unchecked observers_;
// All the WebStatePolicyDeciders asked for navigation decision. Weak
// references.
base::ObserverList<WebStatePolicyDecider, true>::Unchecked policy_deciders_;
base::WeakPtrFactory<FakeWebState> weak_factory_{this};
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_OBSERVER_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_OBSERVER_H_
#include "ios/web/public/test/fakes/test_web_state_observer_util.h"
#include "ios/web/public/web_state_observer.h"
namespace web {
class WebState;
// Test observer to check that the WebStateObserver methods are called as
// expected. Can only observe a single WebState.
// TODO(crbug.com/775684): fix this to allow observing multiple WebStates.
class FakeWebStateObserver : public WebStateObserver {
public:
FakeWebStateObserver(WebState* web_state);
~FakeWebStateObserver() override;
WebState* web_state() { return web_state_; }
// Arguments passed to |WasShown|.
web::TestWasShownInfo* was_shown_info() { return was_shown_info_.get(); }
// Arguments passed to |WasHidden|.
web::TestWasHiddenInfo* was_hidden_info() { return was_hidden_info_.get(); }
// Arguments passed to |DidStartNavigation|.
web::TestDidStartNavigationInfo* did_start_navigation_info() {
return did_start_navigation_info_.get();
}
// Arguments passed to |DidFinishNavigation|.
web::TestDidFinishNavigationInfo* did_finish_navigation_info() {
return did_finish_navigation_info_.get();
}
// Arguments passed to |PageLoaded|.
web::TestLoadPageInfo* load_page_info() { return load_page_info_.get(); }
// Arguments passed to |LoadProgressChanged|.
web::TestChangeLoadingProgressInfo* change_loading_progress_info() {
return change_loading_progress_info_.get();
}
// Arguments passed to |TitleWasSet|.
web::TestTitleWasSetInfo* title_was_set_info() {
return title_was_set_info_.get();
}
// Arguments passed to |DidChangeVisibleSecurityState|.
web::TestDidChangeVisibleSecurityStateInfo*
did_change_visible_security_state_info() {
return did_change_visible_security_state_info_.get();
}
// Arguments passed to |FaviconUrlUpdated|.
web::TestUpdateFaviconUrlCandidatesInfo*
update_favicon_url_candidates_info() {
return update_favicon_url_candidates_info_.get();
}
// Arguments passed to |WebFrameDidBecomeAvailable|.
web::TestWebFrameAvailabilityInfo* web_frame_available_info() {
return web_frame_available_info_.get();
}
// Arguments passed to |WebFrameWillBecomeUnavailable|.
web::TestWebFrameAvailabilityInfo* web_frame_unavailable_info() {
return web_frame_unavailable_info_.get();
}
// Arguments passed to |RenderProcessGone|.
web::TestRenderProcessGoneInfo* render_process_gone_info() {
return render_process_gone_info_.get();
}
// Arguments passed to |WebStateDestroyed|.
web::TestWebStateDestroyedInfo* web_state_destroyed_info() {
return web_state_destroyed_info_.get();
}
// Arguments passed to |DidStartLoading|.
web::TestStopLoadingInfo* stop_loading_info() {
return stop_loading_info_.get();
}
// Arguments passed to |DidStopLoading|.
web::TestStartLoadingInfo* start_loading_info() {
return start_loading_info_.get();
}
private:
// WebStateObserver implementation:
void WasShown(WebState* web_state) override;
void WasHidden(WebState* web_state) override;
void PageLoaded(WebState* web_state,
PageLoadCompletionStatus load_completion_status) override;
void LoadProgressChanged(WebState* web_state, double progress) override;
void DidStartNavigation(WebState* web_state,
NavigationContext* context) override;
void DidFinishNavigation(WebState* web_state,
NavigationContext* context) override;
void TitleWasSet(WebState* web_state) override;
void DidChangeVisibleSecurityState(WebState* web_state) override;
void FaviconUrlUpdated(WebState* web_state,
const std::vector<FaviconURL>& candidates) override;
void WebFrameDidBecomeAvailable(WebState* web_state,
WebFrame* web_frame) override;
void WebFrameWillBecomeUnavailable(WebState* web_state,
WebFrame* web_frame) override;
void RenderProcessGone(WebState* web_state) override;
void WebStateDestroyed(WebState* web_state) override;
void DidStartLoading(WebState* web_state) override;
void DidStopLoading(WebState* web_state) override;
// The WebState this instance is observing. Will be null after
// WebStateDestroyed has been called.
web::WebState* web_state_ = nullptr;
std::unique_ptr<web::TestWasShownInfo> was_shown_info_;
std::unique_ptr<web::TestWasHiddenInfo> was_hidden_info_;
std::unique_ptr<web::TestLoadPageInfo> load_page_info_;
std::unique_ptr<web::TestChangeLoadingProgressInfo>
change_loading_progress_info_;
std::unique_ptr<web::TestDidStartNavigationInfo> did_start_navigation_info_;
std::unique_ptr<web::TestDidFinishNavigationInfo> did_finish_navigation_info_;
std::unique_ptr<web::TestTitleWasSetInfo> title_was_set_info_;
std::unique_ptr<web::TestDidChangeVisibleSecurityStateInfo>
did_change_visible_security_state_info_;
std::unique_ptr<web::TestUpdateFaviconUrlCandidatesInfo>
update_favicon_url_candidates_info_;
std::unique_ptr<web::TestWebFrameAvailabilityInfo> web_frame_available_info_;
std::unique_ptr<web::TestWebFrameAvailabilityInfo>
web_frame_unavailable_info_;
std::unique_ptr<web::TestRenderProcessGoneInfo> render_process_gone_info_;
std::unique_ptr<web::TestWebStateDestroyedInfo> web_state_destroyed_info_;
std::unique_ptr<web::TestStartLoadingInfo> start_loading_info_;
std::unique_ptr<web::TestStopLoadingInfo> stop_loading_info_;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_OBSERVER_H_
...@@ -21,31 +21,31 @@ ...@@ -21,31 +21,31 @@
namespace web { namespace web {
TestWebStateObserver::TestWebStateObserver(WebState* web_state) FakeWebStateObserver::FakeWebStateObserver(WebState* web_state)
: web_state_(web_state) { : web_state_(web_state) {
web_state_->AddObserver(this); web_state_->AddObserver(this);
} }
TestWebStateObserver::~TestWebStateObserver() { FakeWebStateObserver::~FakeWebStateObserver() {
if (web_state_) { if (web_state_) {
web_state_->RemoveObserver(this); web_state_->RemoveObserver(this);
web_state_ = nullptr; web_state_ = nullptr;
} }
} }
void TestWebStateObserver::WasShown(WebState* web_state) { void FakeWebStateObserver::WasShown(WebState* web_state) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
was_shown_info_ = std::make_unique<web::TestWasShownInfo>(); was_shown_info_ = std::make_unique<web::TestWasShownInfo>();
was_shown_info_->web_state = web_state; was_shown_info_->web_state = web_state;
} }
void TestWebStateObserver::WasHidden(WebState* web_state) { void FakeWebStateObserver::WasHidden(WebState* web_state) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
was_hidden_info_ = std::make_unique<web::TestWasHiddenInfo>(); was_hidden_info_ = std::make_unique<web::TestWasHiddenInfo>();
was_hidden_info_->web_state = web_state; was_hidden_info_->web_state = web_state;
} }
void TestWebStateObserver::PageLoaded( void FakeWebStateObserver::PageLoaded(
WebState* web_state, WebState* web_state,
PageLoadCompletionStatus load_completion_status) { PageLoadCompletionStatus load_completion_status) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
...@@ -55,7 +55,7 @@ void TestWebStateObserver::PageLoaded( ...@@ -55,7 +55,7 @@ void TestWebStateObserver::PageLoaded(
load_completion_status == PageLoadCompletionStatus::SUCCESS; load_completion_status == PageLoadCompletionStatus::SUCCESS;
} }
void TestWebStateObserver::LoadProgressChanged(WebState* web_state, void FakeWebStateObserver::LoadProgressChanged(WebState* web_state,
double progress) { double progress) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
change_loading_progress_info_ = change_loading_progress_info_ =
...@@ -64,7 +64,7 @@ void TestWebStateObserver::LoadProgressChanged(WebState* web_state, ...@@ -64,7 +64,7 @@ void TestWebStateObserver::LoadProgressChanged(WebState* web_state,
change_loading_progress_info_->progress = progress; change_loading_progress_info_->progress = progress;
} }
void TestWebStateObserver::DidStartNavigation(WebState* web_state, void FakeWebStateObserver::DidStartNavigation(WebState* web_state,
NavigationContext* navigation) { NavigationContext* navigation) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
ASSERT_TRUE(!navigation->GetError() || !navigation->IsSameDocument()); ASSERT_TRUE(!navigation->GetError() || !navigation->IsSameDocument());
...@@ -81,7 +81,7 @@ void TestWebStateObserver::DidStartNavigation(WebState* web_state, ...@@ -81,7 +81,7 @@ void TestWebStateObserver::DidStartNavigation(WebState* web_state,
did_start_navigation_info_->context = std::move(context); did_start_navigation_info_->context = std::move(context);
} }
void TestWebStateObserver::DidFinishNavigation(WebState* web_state, void FakeWebStateObserver::DidFinishNavigation(WebState* web_state,
NavigationContext* navigation) { NavigationContext* navigation) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
ASSERT_TRUE(!navigation->GetError() || !navigation->IsSameDocument()); ASSERT_TRUE(!navigation->GetError() || !navigation->IsSameDocument());
...@@ -98,13 +98,13 @@ void TestWebStateObserver::DidFinishNavigation(WebState* web_state, ...@@ -98,13 +98,13 @@ void TestWebStateObserver::DidFinishNavigation(WebState* web_state,
did_finish_navigation_info_->context = std::move(context); did_finish_navigation_info_->context = std::move(context);
} }
void TestWebStateObserver::TitleWasSet(WebState* web_state) { void FakeWebStateObserver::TitleWasSet(WebState* web_state) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
title_was_set_info_ = std::make_unique<web::TestTitleWasSetInfo>(); title_was_set_info_ = std::make_unique<web::TestTitleWasSetInfo>();
title_was_set_info_->web_state = web_state; title_was_set_info_->web_state = web_state;
} }
void TestWebStateObserver::DidChangeVisibleSecurityState(WebState* web_state) { void FakeWebStateObserver::DidChangeVisibleSecurityState(WebState* web_state) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
did_change_visible_security_state_info_ = did_change_visible_security_state_info_ =
std::make_unique<web::TestDidChangeVisibleSecurityStateInfo>(); std::make_unique<web::TestDidChangeVisibleSecurityStateInfo>();
...@@ -120,7 +120,7 @@ void TestWebStateObserver::DidChangeVisibleSecurityState(WebState* web_state) { ...@@ -120,7 +120,7 @@ void TestWebStateObserver::DidChangeVisibleSecurityState(WebState* web_state) {
} }
} }
void TestWebStateObserver::FaviconUrlUpdated( void FakeWebStateObserver::FaviconUrlUpdated(
WebState* web_state, WebState* web_state,
const std::vector<FaviconURL>& candidates) { const std::vector<FaviconURL>& candidates) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
...@@ -130,7 +130,7 @@ void TestWebStateObserver::FaviconUrlUpdated( ...@@ -130,7 +130,7 @@ void TestWebStateObserver::FaviconUrlUpdated(
update_favicon_url_candidates_info_->candidates = candidates; update_favicon_url_candidates_info_->candidates = candidates;
} }
void TestWebStateObserver::WebFrameDidBecomeAvailable(WebState* web_state, void FakeWebStateObserver::WebFrameDidBecomeAvailable(WebState* web_state,
WebFrame* web_frame) { WebFrame* web_frame) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
web_frame_available_info_ = web_frame_available_info_ =
...@@ -139,7 +139,7 @@ void TestWebStateObserver::WebFrameDidBecomeAvailable(WebState* web_state, ...@@ -139,7 +139,7 @@ void TestWebStateObserver::WebFrameDidBecomeAvailable(WebState* web_state,
web_frame_available_info_->web_frame = web_frame; web_frame_available_info_->web_frame = web_frame;
} }
void TestWebStateObserver::WebFrameWillBecomeUnavailable(WebState* web_state, void FakeWebStateObserver::WebFrameWillBecomeUnavailable(WebState* web_state,
WebFrame* web_frame) { WebFrame* web_frame) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
web_frame_unavailable_info_ = web_frame_unavailable_info_ =
...@@ -148,14 +148,14 @@ void TestWebStateObserver::WebFrameWillBecomeUnavailable(WebState* web_state, ...@@ -148,14 +148,14 @@ void TestWebStateObserver::WebFrameWillBecomeUnavailable(WebState* web_state,
web_frame_unavailable_info_->web_frame = web_frame; web_frame_unavailable_info_->web_frame = web_frame;
} }
void TestWebStateObserver::RenderProcessGone(WebState* web_state) { void FakeWebStateObserver::RenderProcessGone(WebState* web_state) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
render_process_gone_info_ = render_process_gone_info_ =
std::make_unique<web::TestRenderProcessGoneInfo>(); std::make_unique<web::TestRenderProcessGoneInfo>();
render_process_gone_info_->web_state = web_state; render_process_gone_info_->web_state = web_state;
} }
void TestWebStateObserver::WebStateDestroyed(WebState* web_state) { void FakeWebStateObserver::WebStateDestroyed(WebState* web_state) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
EXPECT_TRUE(web_state->IsBeingDestroyed()); EXPECT_TRUE(web_state->IsBeingDestroyed());
web_state_destroyed_info_ = web_state_destroyed_info_ =
...@@ -165,13 +165,13 @@ void TestWebStateObserver::WebStateDestroyed(WebState* web_state) { ...@@ -165,13 +165,13 @@ void TestWebStateObserver::WebStateDestroyed(WebState* web_state) {
web_state_ = nullptr; web_state_ = nullptr;
} }
void TestWebStateObserver::DidStartLoading(WebState* web_state) { void FakeWebStateObserver::DidStartLoading(WebState* web_state) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
start_loading_info_ = std::make_unique<web::TestStartLoadingInfo>(); start_loading_info_ = std::make_unique<web::TestStartLoadingInfo>();
start_loading_info_->web_state = web_state; start_loading_info_->web_state = web_state;
} }
void TestWebStateObserver::DidStopLoading(WebState* web_state) { void FakeWebStateObserver::DidStopLoading(WebState* web_state) {
ASSERT_EQ(web_state_, web_state); ASSERT_EQ(web_state_, web_state);
stop_loading_info_ = std::make_unique<web::TestStopLoadingInfo>(); stop_loading_info_ = std::make_unique<web::TestStopLoadingInfo>();
stop_loading_info_->web_state = web_state; stop_loading_info_->web_state = web_state;
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_OBSERVER_UTIL_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_OBSERVER_UTIL_H_
#include <memory>
#include "ios/web/public/favicon/favicon_url.h"
#include "url/gurl.h"
namespace web {
class NavigationContext;
struct SSLStatus;
class WebFrame;
class WebState;
// Arguments passed to |WasShown|.
struct TestWasShownInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |WasHidden|.
struct TestWasHiddenInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |DidStartNavigation|.
struct TestDidStartNavigationInfo {
TestDidStartNavigationInfo();
~TestDidStartNavigationInfo();
WebState* web_state = nullptr;
std::unique_ptr<web::NavigationContext> context;
};
// Arguments passed to |DidFinishNavigation|.
struct TestDidFinishNavigationInfo {
TestDidFinishNavigationInfo();
~TestDidFinishNavigationInfo();
WebState* web_state = nullptr;
std::unique_ptr<web::NavigationContext> context;
};
// Arguments passed to |PageLoaded|.
struct TestLoadPageInfo {
WebState* web_state = nullptr;
bool success;
};
// Arguments passed to |LoadProgressChanged|.
struct TestChangeLoadingProgressInfo {
WebState* web_state = nullptr;
double progress;
};
// Arguments passed to |TitleWasSet|.
struct TestTitleWasSetInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |DidChangeVisibleSecurityState| and SSLStatus of the
// visible navigation item.
struct TestDidChangeVisibleSecurityStateInfo {
TestDidChangeVisibleSecurityStateInfo();
~TestDidChangeVisibleSecurityStateInfo();
WebState* web_state = nullptr;
// SSLStatus of the visible navigation item when
// DidChangeVisibleSecurityState was called.
std::unique_ptr<SSLStatus> visible_ssl_status;
};
// Arguments passed to |FaviconUrlUpdated|.
struct TestUpdateFaviconUrlCandidatesInfo {
TestUpdateFaviconUrlCandidatesInfo();
~TestUpdateFaviconUrlCandidatesInfo();
WebState* web_state = nullptr;
std::vector<web::FaviconURL> candidates;
};
// Arguments passed to |WebFrameDidBecomeAvailable| or
// |WebFrameWillBecomeUnavailable|.
struct TestWebFrameAvailabilityInfo {
WebState* web_state = nullptr;
WebFrame* web_frame = nullptr;
};
// Arguments passed to |RenderProcessGone|.
struct TestRenderProcessGoneInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |WebStateDestroyed|.
struct TestWebStateDestroyedInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |DidStartLoading|.
struct TestStartLoadingInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |DidStopLoading|.
struct TestStopLoadingInfo {
WebState* web_state = nullptr;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_FAKE_WEB_STATE_OBSERVER_UTIL_H_
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_BROWSER_STATE_H_ #ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_BROWSER_STATE_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_TEST_BROWSER_STATE_H_ #define IOS_WEB_PUBLIC_TEST_FAKES_TEST_BROWSER_STATE_H_
#include "base/memory/ref_counted.h" #include "ios/web/public/test/fakes/fake_browser_state.h"
#include "ios/web/public/browser_state.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace web { // TODO(crbug.com/688063): Remove this file after updating all clients to import
class TestBrowserState : public BrowserState { // fake_browser_state.h and use FakeBrowserState class.
public:
static const char kCorsExemptTestHeaderName[];
TestBrowserState();
~TestBrowserState() override;
// BrowserState:
bool IsOffTheRecord() const override;
base::FilePath GetStatePath() const override;
net::URLRequestContextGetter* GetRequestContext() override;
void UpdateCorsExemptHeader(
network::mojom::NetworkContextParams* params) override;
scoped_refptr<network::SharedURLLoaderFactory> GetSharedURLLoaderFactory()
override;
// Sets a SharedURLLoaderFactory for test.
void SetSharedURLLoaderFactory(
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory);
// Makes |IsOffTheRecord| return the given flag value. namespace web {
void SetOffTheRecord(bool flag); using TestBrowserState = FakeBrowserState;
}
private:
scoped_refptr<net::URLRequestContextGetter> request_context_;
bool is_off_the_record_;
// A SharedURLLoaderFactory for test.
scoped_refptr<network::SharedURLLoaderFactory>
test_shared_url_loader_factory_;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_BROWSER_STATE_H_ #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_BROWSER_STATE_H_
// Copyright 2016 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_NAVIGATION_MANAGER_H_ #ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_NAVIGATION_MANAGER_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_TEST_NAVIGATION_MANAGER_H_ #define IOS_WEB_PUBLIC_TEST_FAKES_TEST_NAVIGATION_MANAGER_H_
#include "base/callback.h" #import "ios/web/public/test/fakes/fake_navigation_manager.h"
#include "ios/web/public/deprecated/navigation_item_list.h"
#import "ios/web/public/navigation/navigation_item.h"
#import "ios/web/public/navigation/navigation_manager.h"
#include "ui/base/page_transition_types.h"
namespace web { // TODO(crbug.com/688063): Remove this file after updating all clients to import
// fake_navigation_manager.h and use FakeNavigationManager class.
// A minimal implementation of web::NavigationManager that raises NOTREACHED()
// on most calls.
class TestNavigationManager : public NavigationManager {
public:
TestNavigationManager();
~TestNavigationManager() override;
BrowserState* GetBrowserState() const override;
WebState* GetWebState() const override;
NavigationItem* GetVisibleItem() const override;
NavigationItem* GetLastCommittedItem() const override;
NavigationItem* GetPendingItem() const override;
NavigationItem* GetTransientItem() const override;
void DiscardNonCommittedItems() override;
void LoadURLWithParams(const NavigationManager::WebLoadParams&) override;
void LoadIfNecessary() override;
void AddTransientURLRewriter(
BrowserURLRewriter::URLRewriter rewriter) override;
int GetItemCount() const override;
NavigationItem* GetItemAtIndex(size_t index) const override;
int GetIndexOfItem(const NavigationItem* item) const override;
int GetPendingItemIndex() const override;
int GetLastCommittedItemIndex() const override;
bool CanGoBack() const override;
bool CanGoForward() const override;
bool CanGoToOffset(int offset) const override;
void GoBack() override;
void GoForward() override;
void GoToIndex(int index) override;
void Reload(ReloadType reload_type, bool check_for_reposts) override;
void ReloadWithUserAgentType(UserAgentType user_agent_type) override;
NavigationItemList GetBackwardItems() const override;
NavigationItemList GetForwardItems() const override;
void Restore(int last_committed_item_index,
std::vector<std::unique_ptr<NavigationItem>> items) override;
bool IsRestoreSessionInProgress() const override;
void AddRestoreCompletionCallback(base::OnceClosure callback) override;
// Setters for test data.
// Sets a value for last committed item that will be returned by
// GetLastCommittedItem().
void SetLastCommittedItem(NavigationItem* item);
// Sets a value for pending item that will be returned by GetPendingItem().
void SetPendingItem(NavigationItem* item);
// Sets a value for the index that will be returned by GetPendingItemIndex().
void SetPendingItemIndex(int index);
// Sets a value for visible item that will be returned by GetVisibleItem().
void SetVisibleItem(NavigationItem* item);
// Adds an item to items_. Affects the return values for, GetItemCount(),
// GetItemAtIndex(), and GetCurrentItemIndex().
void AddItem(const GURL& url, ui::PageTransition transition);
// Sets the index to be returned by GetLastCommittedItemIndex(). |index| must namespace web {
// be either -1 or between 0 and GetItemCount()-1, inclusively. using TestNavigationManager = FakeNavigationManager;
void SetLastCommittedItemIndex(const int index); }
// Sets the index to be returned by GetBrowserState().
void SetBrowserState(web::BrowserState* browser_state);
// Returns whether LoadURLWithParams has been called.
bool LoadURLWithParamsWasCalled();
// Returns whether LoadIfNecessary has been called.
bool LoadIfNecessaryWasCalled();
// Returns whether Reload has been called;
bool ReloadWasCalled();
private:
// A list of items constructed by calling AddItem().
web::ScopedNavigationItemList items_;
int items_index_;
// Individual backing instance variables for Set* test set up methods.
NavigationItem* pending_item_;
int pending_item_index_;
NavigationItem* last_committed_item_;
NavigationItem* visible_item_;
web::BrowserState* browser_state_;
bool load_url_with_params_was_called_;
bool load_if_necessary_was_called_;
bool reload_was_called_;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_NAVIGATION_MANAGER_H_ #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_NAVIGATION_MANAGER_H_
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_CLIENT_H_ #ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_CLIENT_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_CLIENT_H_ #define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_CLIENT_H_
#import <Foundation/Foundation.h> #import "ios/web/public/test/fakes/fake_web_client.h"
#include <vector>
#include "base/compiler_specific.h" // TODO(crbug.com/688063): Remove this file after updating all clients to import
#import "ios/web/public/web_client.h" // fake_web_client.h and use FakeWebClient class.
#include "net/ssl/ssl_info.h"
#include "url/gurl.h"
namespace web { namespace web {
using TestWebClient = FakeWebClient;
class BrowserState; }
// A WebClient used for testing purposes.
class TestWebClient : public web::WebClient {
public:
TestWebClient();
~TestWebClient() override;
// WebClient implementation.
void AddAdditionalSchemes(Schemes* schemes) const override;
// Returns true for kTestWebUIScheme URL.
bool IsAppSpecificURL(const GURL& url) const override;
bool ShouldBlockUrlDuringRestore(const GURL& url,
WebState* web_state) const override;
void AddSerializableData(web::SerializableUserDataManager* user_data_manager,
web::WebState* web_state) override;
std::string GetUserAgent(UserAgentType type) const override;
// Returns |plugin_not_supported_text_| as the text to be displayed for an
// unsupported plugin.
base::string16 GetPluginNotSupportedText() const override;
base::RefCountedMemory* GetDataResourceBytes(int id) const override;
NSString* GetDocumentStartScriptForMainFrame(
BrowserState* browser_state) const override;
NSString* GetDocumentStartScriptForAllFrames(
BrowserState* browser_state) const override;
void AllowCertificateError(WebState*,
int cert_error,
const net::SSLInfo&,
const GURL&,
bool overridable,
int64_t navigation_id,
base::OnceCallback<void(bool)>) override;
void PrepareErrorPage(WebState* web_state,
const GURL& url,
NSError* error,
bool is_post,
bool is_off_the_record,
const base::Optional<net::SSLInfo>& info,
int64_t navigation_id,
base::OnceCallback<void(NSString*)> callback) override;
UIView* GetWindowedContainer() override;
UserAgentType GetDefaultUserAgent(id<UITraitEnvironment> web_view,
const GURL& url) override;
// Sets |plugin_not_supported_text_|.
void SetPluginNotSupportedText(const base::string16& text);
// Changes Early Page Script for testing purposes.
void SetEarlyPageScript(NSString* page_script);
// Overrides AllowCertificateError response.
void SetAllowCertificateErrors(bool flag);
// Accessors for last arguments passed to AllowCertificateError.
int last_cert_error_code() const { return last_cert_error_code_; }
const net::SSLInfo& last_cert_error_ssl_info() const {
return last_cert_error_ssl_info_;
}
const GURL& last_cert_error_request_url() const {
return last_cert_error_request_url_;
}
bool last_cert_error_overridable() { return last_cert_error_overridable_; }
void SetDefaultUserAgent(UserAgentType type) { default_user_agent_ = type; }
private:
base::string16 plugin_not_supported_text_;
NSString* early_page_script_ = nil;
// Last arguments passed to AllowCertificateError.
int last_cert_error_code_ = 0;
net::SSLInfo last_cert_error_ssl_info_;
GURL last_cert_error_request_url_;
bool last_cert_error_overridable_ = true;
bool allow_certificate_errors_ = false;
UserAgentType default_user_agent_ = UserAgentType::MOBILE;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_CLIENT_H_ #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_CLIENT_H_
// Copyright 2014 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_H_ #ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_H_ #define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_H_
#include <stdint.h> #import "ios/web/public/test/fakes/fake_web_state.h"
#include <memory> // TODO(crbug.com/688063): Remove this file after updating all clients to import
#include <string> // fake_web_state.h and use FakeWebState class.
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "ios/web/public/deprecated/url_verification_constants.h"
#import "ios/web/public/navigation/navigation_manager.h"
#import "ios/web/public/navigation/web_state_policy_decider.h"
#import "ios/web/public/web_state.h"
#include "ios/web/public/web_state_observer.h"
#include "url/gurl.h"
@class NSURLRequest;
@class NSURLResponse;
namespace web { namespace web {
using TestWebState = FakeWebState;
// Minimal implementation of WebState, to be used in tests. }
class TestWebState : public WebState {
public:
TestWebState();
~TestWebState() override;
// WebState implementation.
Getter CreateDefaultGetter() override;
OnceGetter CreateDefaultOnceGetter() override;
WebStateDelegate* GetDelegate() override;
void SetDelegate(WebStateDelegate* delegate) override;
bool IsWebUsageEnabled() const override;
void SetWebUsageEnabled(bool enabled) override;
UIView* GetView() override;
void DidCoverWebContent() override;
void DidRevealWebContent() override;
void WasShown() override;
void WasHidden() override;
void SetKeepRenderProcessAlive(bool keep_alive) override;
BrowserState* GetBrowserState() const override;
void OpenURL(const OpenURLParams& params) override {}
void Stop() override {}
const NavigationManager* GetNavigationManager() const override;
NavigationManager* GetNavigationManager() override;
const WebFramesManager* GetWebFramesManager() const override;
WebFramesManager* GetWebFramesManager() override;
const SessionCertificatePolicyCache* GetSessionCertificatePolicyCache()
const override;
SessionCertificatePolicyCache* GetSessionCertificatePolicyCache() override;
CRWSessionStorage* BuildSessionStorage() override;
CRWJSInjectionReceiver* GetJSInjectionReceiver() const override;
void LoadData(NSData* data, NSString* mime_type, const GURL& url) override;
void ExecuteJavaScript(const base::string16& javascript) override;
void ExecuteJavaScript(const base::string16& javascript,
JavaScriptResultCallback callback) override;
void ExecuteUserJavaScript(NSString* javaScript) override;
const std::string& GetContentsMimeType() const override;
bool ContentIsHTML() const override;
const base::string16& GetTitle() const override;
bool IsLoading() const override;
double GetLoadingProgress() const override;
bool IsVisible() const override;
bool IsCrashed() const override;
bool IsEvicted() const override;
bool IsBeingDestroyed() const override;
const GURL& GetVisibleURL() const override;
const GURL& GetLastCommittedURL() const override;
GURL GetCurrentURL(URLVerificationTrustLevel* trust_level) const override;
base::CallbackListSubscription AddScriptCommandCallback(
const ScriptCommandCallback& callback,
const std::string& command_prefix) override;
CRWWebViewProxyType GetWebViewProxy() const override;
bool IsShowingWebInterstitial() const override;
WebInterstitial* GetWebInterstitial() const override;
void AddObserver(WebStateObserver* observer) override;
void RemoveObserver(WebStateObserver* observer) override;
void CloseWebState() override;
void AddPolicyDecider(WebStatePolicyDecider* decider) override;
void RemovePolicyDecider(WebStatePolicyDecider* decider) override;
void DidChangeVisibleSecurityState() override;
bool HasOpener() const override;
void SetHasOpener(bool has_opener) override;
bool CanTakeSnapshot() const override;
void TakeSnapshot(const gfx::RectF& rect, SnapshotCallback callback) override;
void CreateFullPagePdf(base::OnceCallback<void(NSData*)> callback) override;
// Setters for test data.
void SetBrowserState(BrowserState* browser_state);
void SetJSInjectionReceiver(CRWJSInjectionReceiver* injection_receiver);
void SetTitle(const base::string16& title);
void SetContentIsHTML(bool content_is_html);
void SetContentsMimeType(const std::string& mime_type);
void SetLoading(bool is_loading);
void SetCurrentURL(const GURL& url);
void SetVisibleURL(const GURL& url);
void SetTrustLevel(URLVerificationTrustLevel trust_level);
void SetNavigationManager(
std::unique_ptr<NavigationManager> navigation_manager);
void SetWebFramesManager(
std::unique_ptr<WebFramesManager> web_frames_manager);
void SetView(UIView* view);
void SetIsCrashed(bool value);
void SetIsEvicted(bool value);
void SetWebViewProxy(CRWWebViewProxyType web_view_proxy);
void ClearLastExecutedJavascript();
void SetCanTakeSnapshot(bool can_take_snapshot);
// Getters for test data.
// Uses |policy_deciders| to return whether the navigation corresponding to
// |request| should be allowed. Defaults to PolicyDecision::Allow().
WebStatePolicyDecider::PolicyDecision ShouldAllowRequest(
NSURLRequest* request,
const WebStatePolicyDecider::RequestInfo& request_info);
// Uses |policy_deciders| to determine whether the navigation corresponding to
// |response| should be allowed. Calls |callback| with the decision. Defaults
// to PolicyDecision::Allow().
void ShouldAllowResponse(
NSURLResponse* response,
bool for_main_frame,
base::OnceCallback<void(WebStatePolicyDecider::PolicyDecision)> callback);
base::string16 GetLastExecutedJavascript() const;
NSData* GetLastLoadedData() const;
bool IsClosed() const;
// Notifier for tests.
void OnPageLoaded(PageLoadCompletionStatus load_completion_status);
void OnNavigationStarted(NavigationContext* navigation_context);
void OnNavigationRedirected(NavigationContext* context);
void OnNavigationFinished(NavigationContext* navigation_context);
void OnRenderProcessGone();
void OnBackForwardStateChanged();
void OnVisibleSecurityStateChanged();
void OnWebFrameDidBecomeAvailable(WebFrame* frame);
void OnWebFrameWillBecomeUnavailable(WebFrame* frame);
private:
BrowserState* browser_state_;
CRWJSInjectionReceiver* injection_receiver_;
bool web_usage_enabled_;
bool is_loading_;
bool is_visible_;
bool is_crashed_;
bool is_evicted_;
bool has_opener_;
bool can_take_snapshot_;
bool is_closed_;
GURL url_;
base::string16 title_;
base::string16 last_executed_javascript_;
URLVerificationTrustLevel trust_level_;
bool content_is_html_;
std::string mime_type_;
std::unique_ptr<NavigationManager> navigation_manager_;
std::unique_ptr<WebFramesManager> web_frames_manager_;
UIView* view_;
CRWWebViewProxyType web_view_proxy_;
NSData* last_loaded_data_;
base::RepeatingCallbackList<ScriptCommandCallbackSignature> callback_list_;
// A list of observers notified when page state changes. Weak references.
base::ObserverList<WebStateObserver, true>::Unchecked observers_;
// All the WebStatePolicyDeciders asked for navigation decision. Weak
// references.
base::ObserverList<WebStatePolicyDecider, true>::Unchecked policy_deciders_;
base::WeakPtrFactory<TestWebState> weak_factory_{this};
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_H_ #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_H_
// Copyright 2017 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_H_ #ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_H_ #define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_H_
#include "ios/web/public/test/fakes/test_web_state_observer_util.h" #include "ios/web/public/test/fakes/fake_web_state_observer.h"
#include "ios/web/public/web_state_observer.h"
namespace web { // TODO(crbug.com/688063): Remove this file after updating all clients to import
// fake_web_state_observer.h and use FakeWebStateObserver class.
class WebState;
// Test observer to check that the WebStateObserver methods are called as
// expected. Can only observe a single WebState.
// TODO(crbug.com/775684): fix this to allow observing multiple WebStates.
class TestWebStateObserver : public WebStateObserver {
public:
TestWebStateObserver(WebState* web_state);
~TestWebStateObserver() override;
WebState* web_state() { return web_state_; }
// Arguments passed to |WasShown|.
web::TestWasShownInfo* was_shown_info() { return was_shown_info_.get(); }
// Arguments passed to |WasHidden|.
web::TestWasHiddenInfo* was_hidden_info() { return was_hidden_info_.get(); }
// Arguments passed to |DidStartNavigation|.
web::TestDidStartNavigationInfo* did_start_navigation_info() {
return did_start_navigation_info_.get();
}
// Arguments passed to |DidFinishNavigation|.
web::TestDidFinishNavigationInfo* did_finish_navigation_info() {
return did_finish_navigation_info_.get();
}
// Arguments passed to |PageLoaded|.
web::TestLoadPageInfo* load_page_info() { return load_page_info_.get(); }
// Arguments passed to |LoadProgressChanged|.
web::TestChangeLoadingProgressInfo* change_loading_progress_info() {
return change_loading_progress_info_.get();
}
// Arguments passed to |TitleWasSet|.
web::TestTitleWasSetInfo* title_was_set_info() {
return title_was_set_info_.get();
}
// Arguments passed to |DidChangeVisibleSecurityState|.
web::TestDidChangeVisibleSecurityStateInfo*
did_change_visible_security_state_info() {
return did_change_visible_security_state_info_.get();
}
// Arguments passed to |FaviconUrlUpdated|.
web::TestUpdateFaviconUrlCandidatesInfo*
update_favicon_url_candidates_info() {
return update_favicon_url_candidates_info_.get();
}
// Arguments passed to |WebFrameDidBecomeAvailable|.
web::TestWebFrameAvailabilityInfo* web_frame_available_info() {
return web_frame_available_info_.get();
}
// Arguments passed to |WebFrameWillBecomeUnavailable|.
web::TestWebFrameAvailabilityInfo* web_frame_unavailable_info() {
return web_frame_unavailable_info_.get();
}
// Arguments passed to |RenderProcessGone|.
web::TestRenderProcessGoneInfo* render_process_gone_info() {
return render_process_gone_info_.get();
}
// Arguments passed to |WebStateDestroyed|.
web::TestWebStateDestroyedInfo* web_state_destroyed_info() {
return web_state_destroyed_info_.get();
}
// Arguments passed to |DidStartLoading|.
web::TestStopLoadingInfo* stop_loading_info() {
return stop_loading_info_.get();
}
// Arguments passed to |DidStopLoading|.
web::TestStartLoadingInfo* start_loading_info() {
return start_loading_info_.get();
}
private: namespace web {
// WebStateObserver implementation: using TestWebStateObserver = FakeWebStateObserver;
void WasShown(WebState* web_state) override; }
void WasHidden(WebState* web_state) override;
void PageLoaded(WebState* web_state,
PageLoadCompletionStatus load_completion_status) override;
void LoadProgressChanged(WebState* web_state, double progress) override;
void DidStartNavigation(WebState* web_state,
NavigationContext* context) override;
void DidFinishNavigation(WebState* web_state,
NavigationContext* context) override;
void TitleWasSet(WebState* web_state) override;
void DidChangeVisibleSecurityState(WebState* web_state) override;
void FaviconUrlUpdated(WebState* web_state,
const std::vector<FaviconURL>& candidates) override;
void WebFrameDidBecomeAvailable(WebState* web_state,
WebFrame* web_frame) override;
void WebFrameWillBecomeUnavailable(WebState* web_state,
WebFrame* web_frame) override;
void RenderProcessGone(WebState* web_state) override;
void WebStateDestroyed(WebState* web_state) override;
void DidStartLoading(WebState* web_state) override;
void DidStopLoading(WebState* web_state) override;
// The WebState this instance is observing. Will be null after
// WebStateDestroyed has been called.
web::WebState* web_state_ = nullptr;
std::unique_ptr<web::TestWasShownInfo> was_shown_info_;
std::unique_ptr<web::TestWasHiddenInfo> was_hidden_info_;
std::unique_ptr<web::TestLoadPageInfo> load_page_info_;
std::unique_ptr<web::TestChangeLoadingProgressInfo>
change_loading_progress_info_;
std::unique_ptr<web::TestDidStartNavigationInfo> did_start_navigation_info_;
std::unique_ptr<web::TestDidFinishNavigationInfo> did_finish_navigation_info_;
std::unique_ptr<web::TestTitleWasSetInfo> title_was_set_info_;
std::unique_ptr<web::TestDidChangeVisibleSecurityStateInfo>
did_change_visible_security_state_info_;
std::unique_ptr<web::TestUpdateFaviconUrlCandidatesInfo>
update_favicon_url_candidates_info_;
std::unique_ptr<web::TestWebFrameAvailabilityInfo> web_frame_available_info_;
std::unique_ptr<web::TestWebFrameAvailabilityInfo>
web_frame_unavailable_info_;
std::unique_ptr<web::TestRenderProcessGoneInfo> render_process_gone_info_;
std::unique_ptr<web::TestWebStateDestroyedInfo> web_state_destroyed_info_;
std::unique_ptr<web::TestStartLoadingInfo> start_loading_info_;
std::unique_ptr<web::TestStopLoadingInfo> stop_loading_info_;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_H_ #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_H_
// Copyright 2017 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_UTIL_H_ #ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_UTIL_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_UTIL_H_ #define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_UTIL_H_
#include <memory> #import "ios/web/public/test/fakes/fake_web_state_observer_util.h"
#include "ios/web/public/favicon/favicon_url.h" // TODO(crbug.com/688063): Remove this file after updating all clients to import
#include "url/gurl.h" // fake_web_state_observer_util.h.
namespace web {
class NavigationContext;
struct SSLStatus;
class WebFrame;
class WebState;
// Arguments passed to |WasShown|.
struct TestWasShownInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |WasHidden|.
struct TestWasHiddenInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |DidStartNavigation|.
struct TestDidStartNavigationInfo {
TestDidStartNavigationInfo();
~TestDidStartNavigationInfo();
WebState* web_state = nullptr;
std::unique_ptr<web::NavigationContext> context;
};
// Arguments passed to |DidFinishNavigation|.
struct TestDidFinishNavigationInfo {
TestDidFinishNavigationInfo();
~TestDidFinishNavigationInfo();
WebState* web_state = nullptr;
std::unique_ptr<web::NavigationContext> context;
};
// Arguments passed to |PageLoaded|.
struct TestLoadPageInfo {
WebState* web_state = nullptr;
bool success;
};
// Arguments passed to |LoadProgressChanged|.
struct TestChangeLoadingProgressInfo {
WebState* web_state = nullptr;
double progress;
};
// Arguments passed to |TitleWasSet|.
struct TestTitleWasSetInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |DidChangeVisibleSecurityState| and SSLStatus of the
// visible navigation item.
struct TestDidChangeVisibleSecurityStateInfo {
TestDidChangeVisibleSecurityStateInfo();
~TestDidChangeVisibleSecurityStateInfo();
WebState* web_state = nullptr;
// SSLStatus of the visible navigation item when
// DidChangeVisibleSecurityState was called.
std::unique_ptr<SSLStatus> visible_ssl_status;
};
// Arguments passed to |FaviconUrlUpdated|.
struct TestUpdateFaviconUrlCandidatesInfo {
TestUpdateFaviconUrlCandidatesInfo();
~TestUpdateFaviconUrlCandidatesInfo();
WebState* web_state = nullptr;
std::vector<web::FaviconURL> candidates;
};
// Arguments passed to |WebFrameDidBecomeAvailable| or
// |WebFrameWillBecomeUnavailable|.
struct TestWebFrameAvailabilityInfo {
WebState* web_state = nullptr;
WebFrame* web_frame = nullptr;
};
// Arguments passed to |RenderProcessGone|.
struct TestRenderProcessGoneInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |WebStateDestroyed|.
struct TestWebStateDestroyedInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |DidStartLoading|.
struct TestStartLoadingInfo {
WebState* web_state = nullptr;
};
// Arguments passed to |DidStopLoading|.
struct TestStopLoadingInfo {
WebState* web_state = nullptr;
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_UTIL_H_ #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_OBSERVER_UTIL_H_
...@@ -47,7 +47,7 @@ id GetObject(const std::string& json) { ...@@ -47,7 +47,7 @@ id GetObject(const std::string& json) {
error:nil]; error:nil];
} }
class FakeWebState : public TestWebState { class FakeWebStateWithMojoFacade : public TestWebState {
public: public:
void SetWatchId(int watch_id) { watch_id_ = watch_id; } void SetWatchId(int watch_id) { watch_id_ = watch_id; }
...@@ -87,7 +87,7 @@ class MojoFacadeTest : public WebTest { ...@@ -87,7 +87,7 @@ class MojoFacadeTest : public WebTest {
web_state_.SetFacade(facade_.get()); web_state_.SetFacade(facade_.get());
} }
FakeWebState* web_state() { return &web_state_; } FakeWebStateWithMojoFacade* web_state() { return &web_state_; }
MojoFacade* facade() { return facade_.get(); } MojoFacade* facade() { return facade_.get(); }
void CreateMessagePipe(uint32_t* handle0, uint32_t* handle1) { void CreateMessagePipe(uint32_t* handle0, uint32_t* handle1) {
...@@ -119,7 +119,7 @@ class MojoFacadeTest : public WebTest { ...@@ -119,7 +119,7 @@ class MojoFacadeTest : public WebTest {
} }
private: private:
FakeWebState web_state_; FakeWebStateWithMojoFacade web_state_;
std::unique_ptr<MojoFacade> facade_; std::unique_ptr<MojoFacade> facade_;
}; };
......
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