Commit 02798ab0 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Migrate meta_tags_egtest.mm to meta_tag_inttest.mm.

This CL converts ios_web_shell_egtests.MetaTagTestCase to
ios_web_inttests.MetaTagTest, because it doesn't require UI for testing.

Bug: 930859
Change-Id: Idad9e27707ded89a180d9e47e127a8e3cf5260d1
Reviewed-on: https://chromium-review.googlesource.com/c/1488917
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636752}
parent d7f9e639
...@@ -593,6 +593,7 @@ test("ios_web_inttests") { ...@@ -593,6 +593,7 @@ test("ios_web_inttests") {
"browser_state_web_view_partition_inttest.mm", "browser_state_web_view_partition_inttest.mm",
"find_in_page/find_in_page_manager_inttest.mm", "find_in_page/find_in_page_manager_inttest.mm",
"navigation/history_state_operations_inttest.mm", "navigation/history_state_operations_inttest.mm",
"navigation/meta_tag_inttest.mm",
"navigation/window_location_inttest.mm", "navigation/window_location_inttest.mm",
"plugin_placeholder_inttest.mm", "plugin_placeholder_inttest.mm",
"public/test/http_server_inttest.mm", "public/test/http_server_inttest.mm",
......
// 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.
#include "base/bind.h"
#include "base/strings/stringprintf.h"
#import "ios/testing/embedded_test_server_handlers.h"
#import "ios/web/public/test/navigation_test_util.h"
#import "ios/web/public/test/web_test_with_web_state.h"
#import "ios/web/public/test/web_view_content_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// A simple test page with generic content.
const char kDestinationPage[] = "You've arrived!";
// Template for a test page with META refresh tag. Required template arguments
// are: refresh time in seconds (integer) and destination URL for redirect
// (string).
const char kRefreshMetaPageTemplate[] =
"<!DOCTYPE html>"
"<html>"
" <head><meta HTTP-EQUIV='REFRESH' content='%d;url=%s'></head>"
" <body></body>"
"</html>";
const char kOriginRelativeUrl[] = "/origin";
const char kDestinationRelativeUrl[] = "/destination";
} // namespace
using base::test::ios::kWaitForUIElementTimeout;
namespace web {
// Test fixture for integration tests involving page navigation triggered by
// meta-tag.
class MetaTagTest : public WebTestWithWebState,
public ::testing::WithParamInterface<int> {
protected:
void SetUp() override {
WebTestWithWebState::SetUp();
std::string refresh_meta_page = base::StringPrintf(
kRefreshMetaPageTemplate, GetParam(), kDestinationRelativeUrl);
server_.RegisterRequestHandler(base::BindRepeating(
net::test_server::HandlePrefixedRequest, kOriginRelativeUrl,
base::BindRepeating(::testing::HandlePageWithHtml, refresh_meta_page)));
server_.RegisterDefaultHandler(
base::BindRepeating(::testing::HandlePageWithHtml, kDestinationPage));
ASSERT_TRUE(server_.Start());
}
net::test_server::EmbeddedTestServer server_;
};
// Tests that if a page contains <meta HTTP-EQUIV='REFRESH' content='time;url'>,
// the page will redirect to |url| after |time| seconds.
TEST_P(MetaTagTest, HttpEquivRefresh) {
const GURL origin_url = server_.GetURL(kOriginRelativeUrl);
const GURL destination_url = server_.GetURL(kDestinationRelativeUrl);
test::LoadUrl(web_state(), origin_url);
ASSERT_TRUE(test::WaitForPageToFinishLoading(web_state()));
EXPECT_TRUE(test::WaitForWebViewContainingText(
web_state(), kDestinationPage, GetParam() + kWaitForUIElementTimeout));
}
INSTANTIATE_TEST_SUITE_P(/* No InstantiationName */,
MetaTagTest,
::testing::Values(1, 3));
} // namespace web
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef IOS_WEB_PUBLIC_TEST_WEB_VIEW_CONTENT_TEST_UTIL_H_ #ifndef IOS_WEB_PUBLIC_TEST_WEB_VIEW_CONTENT_TEST_UTIL_H_
#define IOS_WEB_PUBLIC_TEST_WEB_VIEW_CONTENT_TEST_UTIL_H_ #define IOS_WEB_PUBLIC_TEST_WEB_VIEW_CONTENT_TEST_UTIL_H_
#import "base/test/ios/wait_util.h"
#include "ios/web/public/test/element_selector.h" #include "ios/web/public/test/element_selector.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
...@@ -24,9 +25,12 @@ enum ImageStateElement { ...@@ -24,9 +25,12 @@ enum ImageStateElement {
bool IsWebViewContainingText(web::WebState* web_state, const std::string& text); bool IsWebViewContainingText(web::WebState* web_state, const std::string& text);
// Waits for the given web state to contain |text|. If the condition is not met // Waits for the given web state to contain |text|. If the condition is not met
// within a timeout false is returned. // within |timeout| false is returned.
bool WaitForWebViewContainingText(web::WebState* web_state, bool WaitForWebViewContainingText(
std::string text) WARN_UNUSED_RESULT; web::WebState* web_state,
std::string text,
NSTimeInterval timeout = base::test::ios::kWaitForPageLoadTimeout)
WARN_UNUSED_RESULT;
// Waits for a web view with the corresponding |image_id| and |image_state|, in // Waits for a web view with the corresponding |image_id| and |image_state|, in
// the given |web_state|. // the given |web_state|.
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "base/values.h" #include "base/values.h"
#import "ios/web/public/test/web_view_interaction_test_util.h" #import "ios/web/public/test/web_view_interaction_test_util.h"
#import "net/base/mac/url_conversions.h" #import "net/base/mac/url_conversions.h"
...@@ -95,8 +94,10 @@ bool IsWebViewContainingText(web::WebState* web_state, ...@@ -95,8 +94,10 @@ bool IsWebViewContainingText(web::WebState* web_state,
return false; return false;
} }
bool WaitForWebViewContainingText(web::WebState* web_state, std::string text) { bool WaitForWebViewContainingText(web::WebState* web_state,
return WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{ std::string text,
NSTimeInterval timeout) {
return WaitUntilConditionOrTimeout(timeout, ^{
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
return IsWebViewContainingText(web_state, text); return IsWebViewContainingText(web_state, text);
}); });
......
...@@ -19,7 +19,6 @@ ios_eg_test("ios_web_shell_egtests") { ...@@ -19,7 +19,6 @@ ios_eg_test("ios_web_shell_egtests") {
info_plist = "//ios/web/shell/Info.plist" info_plist = "//ios/web/shell/Info.plist"
sources = [ sources = [
"context_menu_egtest.mm", "context_menu_egtest.mm",
"meta_tags_egtest.mm",
"page_state_egtest.mm", "page_state_egtest.mm",
"redirect_egtest.mm", "redirect_egtest.mm",
"service_manager_egtest.mm", "service_manager_egtest.mm",
......
// 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.
#import <EarlGrey/EarlGrey.h>
#include <map>
#include "base/strings/stringprintf.h"
#import "base/test/ios/wait_util.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h"
#import "ios/web/shell/test/earl_grey/shell_earl_grey.h"
#import "ios/web/shell/test/earl_grey/shell_matchers.h"
#import "ios/web/shell/test/earl_grey/shell_matchers_shorthand.h"
#import "ios/web/shell/test/earl_grey/web_shell_test_case.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// A simple test page with generic content.
const char kDestinationPage[] = "You've arrived!";
// Template for a test page with META refresh tag. Required template arguments
// are: refresh time in seconds (integer) and destination URL for redirect
// (string).
const char kRefreshMetaPageTemplate[] =
"<!DOCTYPE html>"
"<html>"
" <head><meta HTTP-EQUIV='REFRESH' content='%d;url=%s'></head>"
" <body></body>"
"</html>";
} // namespace
using web::test::HttpServer;
using web::AddressFieldText;
// META tag test cases for the web shell.
@interface MetaTagsTestCase : WebShellTestCase
@end
@implementation MetaTagsTestCase
// Tests loading of a page with a META tag having a refresh value of 0 seconds.
- (void)testMetaRefresh0Seconds {
[self runMetaRefreshTestWithRefreshInterval:0];
}
// Tests loading of a page with a META tag having a refresh value of 3 seconds.
- (void)testMetaRefresh3Seconds {
[self runMetaRefreshTestWithRefreshInterval:3];
}
// Loads a page with a META tag having a refresh value of |refreshInterval|
// seconds and verifies that redirect happens.
- (void)runMetaRefreshTestWithRefreshInterval:(int)refreshIntervalInSeconds {
// Create map of canned responses and set up the test HTML server.
std::map<GURL, std::string> responses;
const GURL originURL = HttpServer::MakeUrl("http://origin");
const GURL destinationURL = HttpServer::MakeUrl("http://destination");
responses[originURL] =
base::StringPrintf(kRefreshMetaPageTemplate, refreshIntervalInSeconds,
destinationURL.spec().c_str());
responses[destinationURL] = kDestinationPage;
web::test::SetUpSimpleHttpServer(responses);
[ShellEarlGrey loadURL:originURL];
// Wait for redirect.
base::test::ios::SpinRunLoopWithMinDelay(
base::TimeDelta::FromSecondsD(refreshIntervalInSeconds));
// Verify that redirect happened.
[[EarlGrey selectElementWithMatcher:AddressFieldText(destinationURL.spec())]
assertWithMatcher:grey_notNil()];
[ShellEarlGrey waitForWebViewContainingText:kDestinationPage];
}
@end
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