Commit 3bd6f644 authored by Christos Froussios's avatar Christos Froussios Committed by Commit Bot

Revert "[ios] Add FindInPageManager Inttests"

This reverts commit 21a4eef0.

Reason for revert: ios_web_inttests is broken on ios-webview
Example failure:
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/ios-webview/6599

Original change's description:
> [ios] Add FindInPageManager Inttests
> 
> Creates FindInPageManagerTest to test FindInPageManager and FindInPageManagerDelegate.
> 
> Bug: 919685
> Change-Id: Ia9b680582677f984dd9b775155f8f21b0285b768
> Reviewed-on: https://chromium-review.googlesource.com/c/1448912
> Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
> Reviewed-by: Eugene But <eugenebut@chromium.org>
> Reviewed-by: Mike Dougherty <michaeldo@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#634434}

TBR=eugenebut@chromium.org,michaeldo@chromium.org,thegreenfrog@chromium.org

Change-Id: I4c1829451a7e68e2fbde2a9e8badbfe644389048
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 919685
Reviewed-on: https://chromium-review.googlesource.com/c/1482951Reviewed-by: default avatarChristos Froussios <cfroussios@chromium.org>
Commit-Queue: Christos Froussios <cfroussios@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634595}
parent 80d2d8ab
......@@ -78,18 +78,9 @@ std::unique_ptr<net::test_server::HttpResponse> HandleIFrame(
const net::test_server::HttpRequest& request) {
auto http_response = std::make_unique<net::test_server::BasicHttpResponse>();
http_response->set_content_type("text/html");
http_response->set_content(
base::StringPrintf("<html><head></head><body><iframe "
"src='%s'></iframe>Main frame text</body></html>",
ExtractUlrSpecFromQuery(request).c_str()));
return std::move(http_response);
}
std::unique_ptr<net::test_server::HttpResponse> HandlePageWithContents(
const net::test_server::HttpRequest& request) {
auto http_response = std::make_unique<net::test_server::BasicHttpResponse>();
http_response->set_content_type("text/html");
http_response->set_content(request.GetURL().query());
http_response->set_content(base::StringPrintf(
"<html><head></head><body><iframe src='%s'></iframe></body></html>",
ExtractUlrSpecFromQuery(request).c_str()));
return std::move(http_response);
}
......
......@@ -26,10 +26,6 @@ extern const char kTestDownloadMimeType[];
std::unique_ptr<net::test_server::HttpResponse> HandleIFrame(
const net::test_server::HttpRequest& request);
// Returns a page with contetns of URL request query.
std::unique_ptr<net::test_server::HttpResponse> HandlePageWithContents(
const net::test_server::HttpRequest& request);
// Returns a page with content of URL request query if |responds_with_content|
// is true. Closes the socket otherwise. Can be used to simulate the state where
// there is no internet connection.
......
......@@ -566,7 +566,6 @@ test("ios_web_inttests") {
"//ios/web:resources_grit",
"//ios/web/download:download_inttests",
"//ios/web/navigation:core",
"//ios/web/public/find_in_page",
"//ios/web/public/test",
"//ios/web/public/test/fakes",
"//ios/web/public/test/http_server",
......@@ -586,7 +585,6 @@ test("ios_web_inttests") {
]
sources = [
"browser_state_web_view_partition_inttest.mm",
"find_in_page/find_in_page_manager_inttest.mm",
"navigation/history_state_operations_inttest.mm",
"navigation/window_location_inttest.mm",
"public/test/http_server_inttest.mm",
......
......@@ -6,7 +6,6 @@ source_set("find_in_page") {
deps = [
"//base",
"//ios/web/public/",
"//ios/web/public/find_in_page",
"//ios/web/web_state:web_frame",
"//ios/web/web_state:web_state_impl_header",
]
......
// Copyright 2019 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.
#import "base/test/ios/wait_util.h"
#include "ios/testing/embedded_test_server_handlers.h"
#import "ios/web/public/find_in_page/find_in_page_manager.h"
#import "ios/web/public/test/fakes/fake_find_in_page_manager_delegate.h"
#import "ios/web/public/test/navigation_test_util.h"
#import "ios/web/public/test/web_test_with_web_state.h"
#include "ios/web/public/web_state/web_frame_util.h"
#include "net/base/escape.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using base::test::ios::kWaitForJSCompletionTimeout;
using base::test::ios::WaitUntilConditionOrTimeout;
using base::test::ios::kWaitForPageLoadTimeout;
namespace {
// Page with text "Main frame body" and iframe with src URL equal to the URL
// query string.
const char kFindPageUrl[] = "/iframe?";
// URL of iframe with text contents "iframe body".
const char kFindInPageIFrameUrl[] = "/echo-query?iframe text";
}
namespace web {
// Tests the FindInPageManager and verifies that values passed to
// FindInPageManagerDelegate are correct.
class FindInPageManagerTest : public WebTestWithWebState {
protected:
void SetUp() override {
WebTestWithWebState::SetUp();
test_server_.RegisterRequestHandler(base::BindRepeating(
&net::test_server::HandlePrefixedRequest, "/echo-query",
base::BindRepeating(&testing::HandlePageWithContents)));
test_server_.RegisterRequestHandler(
base::BindRepeating(&net::test_server::HandlePrefixedRequest, "/iframe",
base::BindRepeating(&testing::HandleIFrame)));
ASSERT_TRUE(test_server_.Start());
GetFindInPageManager()->SetDelegate(&delegate_);
}
// Returns the FindInPageManager associated with |web_state()|.
FindInPageManager* GetFindInPageManager() {
return web::FindInPageManager::FromWebState(web_state());
}
net::EmbeddedTestServer test_server_;
FakeFindInPageManagerDelegate delegate_;
};
// Tests that find in page returns a single match for text which exists only in
// the main frame.
TEST_F(FindInPageManagerTest, FindMatchInMainFrame) {
std::string url_spec =
kFindPageUrl +
net::EscapeQueryParamValue(kFindInPageIFrameUrl, /*use_plus=*/true);
test::LoadUrl(web_state(), test_server_.GetURL(url_spec));
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^{
return GetAllWebFrames(web_state()).size() == 2;
}));
GetFindInPageManager()->Find(@"Main frame text",
FindInPageOptions::FindInPageSearch);
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool {
return delegate_.state();
}));
EXPECT_EQ(1, delegate_.state()->match_count);
EXPECT_EQ(web_state(), delegate_.state()->web_state);
};
// Checks that find in page finds text that exists within the main frame and
// an iframe.
TEST_F(FindInPageManagerTest, FindMatchInMainFrameAndIFrame) {
std::string url_spec =
kFindPageUrl +
net::EscapeQueryParamValue(kFindInPageIFrameUrl, /*use_plus=*/true);
test::LoadUrl(web_state(), test_server_.GetURL(url_spec));
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^{
return GetAllWebFrames(web_state()).size() == 2;
}));
GetFindInPageManager()->Find(@"frame", FindInPageOptions::FindInPageSearch);
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool {
return delegate_.state();
}));
EXPECT_EQ(2, delegate_.state()->match_count);
EXPECT_EQ(web_state(), delegate_.state()->web_state);
};
// Checks that find in page returns no matches for text not contained on the
// page.
TEST_F(FindInPageManagerTest, FindNoMatch) {
std::string url_spec =
kFindPageUrl +
net::EscapeQueryParamValue(kFindInPageIFrameUrl, /*use_plus=*/true);
test::LoadUrl(web_state(), test_server_.GetURL(url_spec));
ASSERT_TRUE(WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^{
return GetAllWebFrames(web_state()).size() == 2;
}));
GetFindInPageManager()->Find(@"foobar", FindInPageOptions::FindInPageSearch);
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout, ^bool {
return delegate_.state();
}));
EXPECT_EQ(0, delegate_.state()->match_count);
EXPECT_EQ(web_state(), delegate_.state()->web_state);
};
} // namespace web
......@@ -7,8 +7,6 @@
#include <string>
#include "base/macros.h"
namespace web {
class WebState;
......
......@@ -9,7 +9,6 @@ source_set("fakes") {
deps = [
"//base",
"//ios/web/public/download",
"//ios/web/public/find_in_page",
"//ios/web/test:test_constants",
"//ios/web/web_state:navigation_context",
"//ios/web/web_state:web_frame",
......@@ -36,8 +35,6 @@ source_set("fakes") {
"fake_download_controller_delegate.mm",
"fake_download_task.h",
"fake_download_task.mm",
"fake_find_in_page_manager_delegate.h",
"fake_find_in_page_manager_delegate.mm",
"fake_navigation_context.h",
"fake_navigation_context.mm",
"fake_web_frame.cc",
......
// Copyright 2019 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_FIND_IN_PAGE_MANAGER_DELEGATE_H_
#define IOS_WEB_PUBLIC_TEST_FAKES_FAKE_FIND_IN_PAGE_MANAGER_DELEGATE_H_
#include <memory>
#include <string>
#import "ios/web/public/find_in_page/find_in_page_manager_delegate.h"
namespace web {
class WebState;
// Use this as the delegate for FindInPageManager responses in test suites.
class FakeFindInPageManagerDelegate : public FindInPageManagerDelegate {
public:
FakeFindInPageManagerDelegate();
~FakeFindInPageManagerDelegate() override;
// FindInPageManagerDelegate override
void DidCountMatches(WebState* web_state,
int match_count,
const std::string& query) override;
void DidHighlightMatch(WebState* web_state, int index) override;
// Holds the last response values passed to DidCountMatches.
struct State {
State();
~State();
WebState* web_state = nullptr;
int match_count = -1;
std::string query;
};
// Returns the current State.
const State* state() const { return delegate_state_.get(); }
private:
std::unique_ptr<State> delegate_state_;
DISALLOW_COPY_AND_ASSIGN(FakeFindInPageManagerDelegate);
};
} // namespace web
#endif // IOS_WEB_PUBLIC_TEST_FAKES_FAKE_FIND_IN_PAGE_MANAGER_DELEGATE_H_
// Copyright 2019 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.
#import "ios/web/public/test/fakes/fake_find_in_page_manager_delegate.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web {
FakeFindInPageManagerDelegate::State::State() = default;
FakeFindInPageManagerDelegate::State::~State() = default;
FakeFindInPageManagerDelegate::FakeFindInPageManagerDelegate() = default;
FakeFindInPageManagerDelegate::~FakeFindInPageManagerDelegate() = default;
void FakeFindInPageManagerDelegate::DidCountMatches(WebState* web_state,
int match_count,
const std::string& query) {
delegate_state_ = std::make_unique<State>();
delegate_state_->web_state = web_state;
delegate_state_->match_count = match_count;
delegate_state_->query = query;
}
void FakeFindInPageManagerDelegate::DidHighlightMatch(WebState* web_state,
int index) {}
} // namespace web
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