[go: nahoru, domu]

[ios] Moves GetContentAndFragmentForUrl() into ios/net.

For EG2 tests, we'd like to use ios/web/public/test/http_server from the
test process, but without pulling in all of //ios/web.  Moving this
utility function allows http_server to depend only on //base, //net, and
//url.

BUG=930859

Change-Id: Ia1e35b04089a3bd2cf00ee0e7a663783ac2762a7
Reviewed-on: https://chromium-review.googlesource.com/c/1473616
Reviewed-by: Eugene But <eugenebut@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632352}
diff --git a/ios/chrome/browser/web/BUILD.gn b/ios/chrome/browser/web/BUILD.gn
index 0fbb06adc..b8b51c7b 100644
--- a/ios/chrome/browser/web/BUILD.gn
+++ b/ios/chrome/browser/web/BUILD.gn
@@ -108,6 +108,7 @@
     "//ios/chrome/browser/browser_state:test_support",
     "//ios/chrome/browser/snapshots",
     "//ios/chrome/test:test_support",
+    "//ios/net:test_support",
     "//ios/web",
     "//ios/web/public/test",
     "//ios/web/public/test/fakes",
@@ -339,6 +340,7 @@
     "//ios/chrome/test:test_support",
     "//ios/chrome/test/app:test_support",
     "//ios/chrome/test/earl_grey:test_support",
+    "//ios/net:test_support",
     "//ios/testing:embedded_test_server_support",
     "//ios/testing/earl_grey:earl_grey_support",
     "//ios/third_party/earl_grey:earl_grey+link",
diff --git a/ios/chrome/browser/web/browsing_egtest.mm b/ios/chrome/browser/web/browsing_egtest.mm
index 06e82ebc..9aed63b 100644
--- a/ios/chrome/browser/web/browsing_egtest.mm
+++ b/ios/chrome/browser/web/browsing_egtest.mm
@@ -18,12 +18,12 @@
 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
 #include "ios/chrome/test/scoped_block_popups_pref.h"
+#include "ios/net/url_test_util.h"
 #import "ios/web/public/test/earl_grey/web_view_actions.h"
 #import "ios/web/public/test/earl_grey/web_view_matchers.h"
 #include "ios/web/public/test/http_server/data_response_provider.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/public/test/url_test_util.h"
 #import "ios/web/public/web_client.h"
 #include "net/http/http_response_headers.h"
 #include "ui/base/l10n/l10n_util.h"
@@ -228,7 +228,7 @@
 
   // Verify the new tab was opened with the expected URL.
   const std::string omniboxText =
-      web::GetContentAndFragmentForUrl(destinationURL);
+      net::GetContentAndFragmentForUrl(destinationURL);
   [[EarlGrey selectElementWithMatcher:OmniboxText(omniboxText)]
       assertWithMatcher:grey_notNil()];
 }
diff --git a/ios/chrome/browser/web/navigation_egtest.mm b/ios/chrome/browser/web/navigation_egtest.mm
index 59b25c15..4531e4f 100644
--- a/ios/chrome/browser/web/navigation_egtest.mm
+++ b/ios/chrome/browser/web/navigation_egtest.mm
@@ -13,8 +13,8 @@
 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
+#include "ios/net/url_test_util.h"
 #include "ios/web/public/features.h"
-#import "ios/web/public/test/url_test_util.h"
 #include "net/test/embedded_test_server/http_request.h"
 #include "net/test/embedded_test_server/http_response.h"
 #include "ui/base/l10n/l10n_util.h"
@@ -368,7 +368,7 @@
   [self addHashChangeListenerWithContent:backHashChangeContent];
   [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()];
   const std::string page1OmniboxText =
-      web::GetContentAndFragmentForUrl(page1URL);
+      net::GetContentAndFragmentForUrl(page1URL);
   [[EarlGrey selectElementWithMatcher:OmniboxText(page1OmniboxText)]
       assertWithMatcher:grey_notNil()];
   [ChromeEarlGrey waitForWebViewContainingText:backHashChangeContent];
@@ -379,7 +379,7 @@
   [[EarlGrey selectElementWithMatcher:ForwardButton()]
       performAction:grey_tap()];
   const std::string hashChangedWithHistoryOmniboxText =
-      web::GetContentAndFragmentForUrl(hashChangedWithHistoryURL);
+      net::GetContentAndFragmentForUrl(hashChangedWithHistoryURL);
   [[EarlGrey
       selectElementWithMatcher:OmniboxText(hashChangedWithHistoryOmniboxText)]
       assertWithMatcher:grey_notNil()];
@@ -410,7 +410,7 @@
   GREYAssert(TapWebViewElementWithId(kHashChangeWithoutHistoryLabel),
              @"Failed to tap %s", kHashChangeWithoutHistoryLabel);
   const std::string hashChangedWithoutHistoryOmniboxText =
-      web::GetContentAndFragmentForUrl(hashChangedWithoutHistoryURL);
+      net::GetContentAndFragmentForUrl(hashChangedWithoutHistoryURL);
   [[EarlGrey selectElementWithMatcher:OmniboxText(
                                           hashChangedWithoutHistoryOmniboxText)]
       assertWithMatcher:grey_notNil()];
@@ -419,7 +419,7 @@
   GREYAssert(TapWebViewElementWithId(kHashChangeWithHistoryLabel),
              @"Failed to tap %s", kHashChangeWithHistoryLabel);
   const std::string hashChangedWithHistoryOmniboxText =
-      web::GetContentAndFragmentForUrl(hashChangedWithHistoryURL);
+      net::GetContentAndFragmentForUrl(hashChangedWithHistoryURL);
   [[EarlGrey
       selectElementWithMatcher:OmniboxText(hashChangedWithHistoryOmniboxText)]
       assertWithMatcher:grey_notNil()];
@@ -448,7 +448,7 @@
   GREYAssert(TapWebViewElementWithId(kHashChangeWithHistoryLabel),
              @"Failed to tap %s", kHashChangeWithHistoryLabel);
   const std::string hashChangedWithHistoryOmniboxText =
-      web::GetContentAndFragmentForUrl(hashChangedWithHistoryURL);
+      net::GetContentAndFragmentForUrl(hashChangedWithHistoryURL);
   [[EarlGrey
       selectElementWithMatcher:OmniboxText(hashChangedWithHistoryOmniboxText)]
       assertWithMatcher:grey_notNil()];
@@ -460,7 +460,7 @@
   // Tap back once to return to original URL.
   [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()];
   const std::string page1OmniboxText =
-      web::GetContentAndFragmentForUrl(page1URL);
+      net::GetContentAndFragmentForUrl(page1URL);
   [[EarlGrey selectElementWithMatcher:OmniboxText(page1OmniboxText)]
       assertWithMatcher:grey_notNil()];
 
diff --git a/ios/chrome/browser/web/push_and_replace_state_navigation_egtest.mm b/ios/chrome/browser/web/push_and_replace_state_navigation_egtest.mm
index 9206d167..d26c02b 100644
--- a/ios/chrome/browser/web/push_and_replace_state_navigation_egtest.mm
+++ b/ios/chrome/browser/web/push_and_replace_state_navigation_egtest.mm
@@ -11,9 +11,9 @@
 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
+#include "ios/net/url_test_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/public/test/url_test_util.h"
 #import "ios/web/public/web_client.h"
 
 #if !defined(__has_feature) || !__has_feature(objc_arc)
@@ -52,15 +52,15 @@
   const GURL pushStateHashWithObjectURL = web::test::HttpServer::MakeUrl(
       "http://ios/testing/data/http_server_files/history.html#pushWithObject");
   const std::string pushStateHashWithObjectOmniboxText =
-      web::GetContentAndFragmentForUrl(pushStateHashWithObjectURL);
+      net::GetContentAndFragmentForUrl(pushStateHashWithObjectURL);
   const GURL pushStateRootPathURL =
       web::test::HttpServer::MakeUrl("http://ios/rootpath");
   const std::string pushStateRootPathOmniboxText =
-      web::GetContentAndFragmentForUrl(pushStateRootPathURL);
+      net::GetContentAndFragmentForUrl(pushStateRootPathURL);
   const GURL pushStatePathSpaceURL =
       web::test::HttpServer::MakeUrl("http://ios/pa%20th");
   const std::string pushStatePathSpaceOmniboxText =
-      web::GetContentAndFragmentForUrl(pushStatePathSpaceURL);
+      net::GetContentAndFragmentForUrl(pushStatePathSpaceURL);
   web::test::SetUpFileBasedHttpServer();
   [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kHistoryTestUrl)];
 
@@ -95,7 +95,7 @@
   [ChromeEarlGrey tapWebViewElementWithID:@"goBack"];
   const GURL historyTestURL = web::test::HttpServer::MakeUrl(kHistoryTestUrl);
   [self assertStatusText:nil
-         withOmniboxText:web::GetContentAndFragmentForUrl(historyTestURL)
+         withOmniboxText:net::GetContentAndFragmentForUrl(historyTestURL)
               pageLoaded:NO];
 
   // Go forward 2 pages and check that the page doesn't load and the status text
@@ -111,7 +111,7 @@
   web::test::SetUpFileBasedHttpServer();
   const GURL initialURL = web::test::HttpServer::MakeUrl(kNonPushedUrl);
   const std::string initialOmniboxText =
-      web::GetContentAndFragmentForUrl(initialURL);
+      net::GetContentAndFragmentForUrl(initialURL);
   [ChromeEarlGrey loadURL:initialURL];
   [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kHistoryTestUrl)];
 
@@ -119,7 +119,7 @@
   const GURL replaceStateHashWithObjectURL =
       web::test::HttpServer::MakeUrl(kReplaceStateHashWithObjectURL);
   const std::string replaceStateHashWithObjectOmniboxText =
-      web::GetContentAndFragmentForUrl(replaceStateHashWithObjectURL);
+      net::GetContentAndFragmentForUrl(replaceStateHashWithObjectURL);
   [ChromeEarlGrey tapWebViewElementWithID:@"replaceStateHashWithObject"];
   [self assertStatusText:@"replaceStateHashWithObject"
          withOmniboxText:replaceStateHashWithObjectOmniboxText
@@ -143,7 +143,7 @@
   const GURL pushStateHashStringURL =
       web::test::HttpServer::MakeUrl(kPushStateHashStringURL);
   const std::string pushStateHashStringOmniboxText =
-      web::GetContentAndFragmentForUrl(pushStateHashStringURL);
+      net::GetContentAndFragmentForUrl(pushStateHashStringURL);
   [ChromeEarlGrey tapWebViewElementWithID:@"pushStateHashString"];
   [self assertStatusText:@"pushStateHashString"
          withOmniboxText:pushStateHashStringOmniboxText
@@ -152,7 +152,7 @@
   const GURL replaceStateHashStringURL =
       web::test::HttpServer::MakeUrl(kReplaceStateHashStringURL);
   const std::string replaceStateHashStringOmniboxText =
-      web::GetContentAndFragmentForUrl(replaceStateHashStringURL);
+      net::GetContentAndFragmentForUrl(replaceStateHashStringURL);
   [ChromeEarlGrey tapWebViewElementWithID:@"replaceStateHashString"];
   [self assertStatusText:@"replaceStateHashString"
          withOmniboxText:replaceStateHashStringOmniboxText
@@ -161,7 +161,7 @@
   const GURL pushStatePathURL =
       web::test::HttpServer::MakeUrl(kPushStatePathURL);
   const std::string pushStatePathOmniboxText =
-      web::GetContentAndFragmentForUrl(pushStatePathURL);
+      net::GetContentAndFragmentForUrl(pushStatePathURL);
   [ChromeEarlGrey tapWebViewElementWithID:@"pushStatePath"];
   [self assertStatusText:@"pushStatePath"
          withOmniboxText:pushStatePathOmniboxText
@@ -170,7 +170,7 @@
   const GURL replaceStateRootPathSpaceURL =
       web::test::HttpServer::MakeUrl(kReplaceStateRootPathSpaceURL);
   const std::string replaceStateRootPathSpaceOmniboxText =
-      web::GetContentAndFragmentForUrl(replaceStateRootPathSpaceURL);
+      net::GetContentAndFragmentForUrl(replaceStateRootPathSpaceURL);
   [ChromeEarlGrey tapWebViewElementWithID:@"replaceStateRootPathSpace"];
   [self assertStatusText:@"replaceStateRootPathSpace"
          withOmniboxText:replaceStateRootPathSpaceOmniboxText
@@ -200,13 +200,13 @@
   const GURL historyTestURL = web::test::HttpServer::MakeUrl(kHistoryTestUrl);
   [ChromeEarlGrey loadURL:historyTestURL];
   const std::string historyTestOmniboxText =
-      web::GetContentAndFragmentForUrl(historyTestURL);
+      net::GetContentAndFragmentForUrl(historyTestURL);
 
   // Push same URL twice. Verify that URL changed and the status was updated.
   const GURL pushStateHashStringURL =
       web::test::HttpServer::MakeUrl(kPushStateHashStringURL);
   const std::string pushStateHashStringOmniboxText =
-      web::GetContentAndFragmentForUrl(pushStateHashStringURL);
+      net::GetContentAndFragmentForUrl(pushStateHashStringURL);
   [ChromeEarlGrey tapWebViewElementWithID:@"pushStateHashString"];
   [self assertStatusText:@"pushStateHashString"
          withOmniboxText:pushStateHashStringOmniboxText
@@ -271,12 +271,12 @@
   // The GURL object %-escapes Unicode characters in the URL's fragment,
   // but the omnibox decodes them back to Unicode for display.
   std::string pushStateUnicode =
-      web::GetContentAndFragmentForUrl(web::test::HttpServer::MakeUrl(
+      net::GetContentAndFragmentForUrl(web::test::HttpServer::MakeUrl(
           "http://ios/testing/data/http_server_files/"
           "history.html#unicode")) +
       "\xe1\x84\x91";
   std::string pushStateUnicode2 =
-      web::GetContentAndFragmentForUrl(web::test::HttpServer::MakeUrl(
+      net::GetContentAndFragmentForUrl(web::test::HttpServer::MakeUrl(
           "http://ios/testing/data/http_server_files/"
           "history.html#unicode2")) +
       "\xe2\x88\xa2";
@@ -305,7 +305,7 @@
   const GURL pushStatePathURL =
       web::test::HttpServer::MakeUrl(kPushStatePathURL);
   const std::string pushStatePathOmniboxText =
-      web::GetContentAndFragmentForUrl(pushStatePathURL);
+      net::GetContentAndFragmentForUrl(pushStatePathURL);
   [ChromeEarlGrey tapWebViewElementWithID:@"pushStatePath"];
 
   [self assertStatusText:@"pushStatePath"
@@ -331,11 +331,11 @@
       web::test::HttpServer::MakeUrl("http://foo.com/foo/bar.html");
   GURL pushResultURL = originURL.GetOrigin().Resolve("pushed/relative/url");
   const std::string pushResultOmniboxText =
-      web::GetContentAndFragmentForUrl(pushResultURL);
+      net::GetContentAndFragmentForUrl(pushResultURL);
   GURL replaceResultURL =
       originURL.GetOrigin().Resolve("replaced/relative/url");
   const std::string replaceResultOmniboxText =
-      web::GetContentAndFragmentForUrl(replaceResultURL);
+      net::GetContentAndFragmentForUrl(replaceResultURL);
 
   // A simple HTML page with a base tag that makes all relative URLs
   // domain-relative, a button to trigger a relative pushState, and a button
diff --git a/ios/chrome/browser/web/window_open_by_dom_egtest.mm b/ios/chrome/browser/web/window_open_by_dom_egtest.mm
index 2c5c2d84..e155fe8 100644
--- a/ios/chrome/browser/web/window_open_by_dom_egtest.mm
+++ b/ios/chrome/browser/web/window_open_by_dom_egtest.mm
@@ -18,12 +18,12 @@
 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
+#include "ios/net/url_test_util.h"
 #import "ios/web/public/test/earl_grey/web_view_actions.h"
 #import "ios/web/public/test/earl_grey/web_view_matchers.h"
 #include "ios/web/public/test/element_selector.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/public/test/url_test_util.h"
 #include "ui/base/l10n/l10n_util.h"
 
 #if !defined(__has_feature) || !__has_feature(objc_arc)
@@ -167,7 +167,7 @@
   const GURL targetURL =
       HttpServer::MakeUrl(std::string(kTestURL) + "#assigned");
   const std::string targetOmniboxText =
-      web::GetContentAndFragmentForUrl(targetURL);
+      net::GetContentAndFragmentForUrl(targetURL);
   [[EarlGrey selectElementWithMatcher:OmniboxText(targetOmniboxText)]
       assertWithMatcher:grey_notNil()];
 }
@@ -184,7 +184,7 @@
   const GURL targetURL =
       HttpServer::MakeUrl(std::string(kTestURL) + "#updated");
   const std::string targetOmniboxText =
-      web::GetContentAndFragmentForUrl(targetURL);
+      net::GetContentAndFragmentForUrl(targetURL);
   [[EarlGrey selectElementWithMatcher:OmniboxText(targetOmniboxText)]
       assertWithMatcher:grey_notNil()];
 }
diff --git a/ios/net/BUILD.gn b/ios/net/BUILD.gn
index bed74bbc..0861b62 100644
--- a/ios/net/BUILD.gn
+++ b/ios/net/BUILD.gn
@@ -94,6 +94,8 @@
     "cookies/cookie_store_ios_test_util.h",
     "cookies/cookie_store_ios_test_util.mm",
     "cookies/system_cookie_store_unittest_template.h",
+    "url_test_util.cc",
+    "url_test_util.h",
   ]
 }
 
diff --git a/ios/net/url_test_util.cc b/ios/net/url_test_util.cc
new file mode 100644
index 0000000..04528b6
--- /dev/null
+++ b/ios/net/url_test_util.cc
@@ -0,0 +1,15 @@
+// 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 "ios/net/url_test_util.h"
+
+#include "url/gurl.h"
+
+namespace net {
+
+std::string GetContentAndFragmentForUrl(const GURL& url) {
+  return url.GetContent() + (url.has_ref() ? "#" + url.ref() : "");
+}
+
+}  // namespace net
diff --git a/ios/net/url_test_util.h b/ios/net/url_test_util.h
new file mode 100644
index 0000000..ea3e54c
--- /dev/null
+++ b/ios/net/url_test_util.h
@@ -0,0 +1,23 @@
+// 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_NET_URL_TEST_UTIL_H_
+#define IOS_NET_URL_TEST_UTIL_H_
+
+#include <string>
+
+class GURL;
+
+namespace net {
+
+// Returns the content and frament of |url| concatenated together. For example:
+//
+//  http://www.example.com/some/content.html?param1=foo#fragment_data
+//
+//  Returns "www.example.com/some/content.html?param1=foo#fragment_data".
+std::string GetContentAndFragmentForUrl(const GURL& url);
+
+}  // namespace net
+
+#endif  // IOS_NET_URL_TEST_UTIL_H_
diff --git a/ios/web/public/test/http_server/BUILD.gn b/ios/web/public/test/http_server/BUILD.gn
index bb85b48..61885e0 100644
--- a/ios/web/public/test/http_server/BUILD.gn
+++ b/ios/web/public/test/http_server/BUILD.gn
@@ -9,7 +9,7 @@
   deps = [
     "//base",
     "//base/test:test_support",
-    "//ios/web/public/test:util",
+    "//ios/net:test_support",
     "//net",
     "//net:test_support",
     "//url",
diff --git a/ios/web/public/test/http_server/http_server.mm b/ios/web/public/test/http_server/http_server.mm
index 59b844b8..b11c567 100644
--- a/ios/web/public/test/http_server/http_server.mm
+++ b/ios/web/public/test/http_server/http_server.mm
@@ -13,7 +13,7 @@
 #include "base/path_service.h"
 #include "base/strings/string_number_conversions.h"
 #include "base/strings/sys_string_conversions.h"
-#import "ios/web/public/test/url_test_util.h"
+#include "ios/net/url_test_util.h"
 #import "net/base/mac/url_conversions.h"
 #include "net/test/embedded_test_server/embedded_test_server.h"
 #include "net/test/embedded_test_server/http_request.h"
@@ -158,7 +158,7 @@
   GURL result(url);
   DCHECK(result.is_valid());
   return embedded_test_server_->GetURL(
-      "/" + web::GetContentAndFragmentForUrl(result));
+      "/" + net::GetContentAndFragmentForUrl(result));
 }
 
 scoped_refptr<RefCountedResponseProviderWrapper>
diff --git a/ios/web/public/test/url_test_util.h b/ios/web/public/test/url_test_util.h
index f5c8390..ac159c6 100644
--- a/ios/web/public/test/url_test_util.h
+++ b/ios/web/public/test/url_test_util.h
@@ -15,13 +15,6 @@
 // for a page with that URL.
 base::string16 GetDisplayTitleForUrl(const GURL& url);
 
-// Returns the content and frament of |url| concatenated together. For example:
-//
-//  http://www.example.com/some/content.html?param1=foo#fragment_data
-//
-//  Returns "www.example.com/some/content.html?param1=foo#fragment_data".
-std::string GetContentAndFragmentForUrl(const GURL& url);
-
 }  // namespace web
 
 #endif  // IOS_WEB_PUBLIC_TEST_URL_TEST_UTIL_H_
diff --git a/ios/web/test/url_test_util.mm b/ios/web/test/url_test_util.mm
index c2a2b8a..f0ed6343 100644
--- a/ios/web/test/url_test_util.mm
+++ b/ios/web/test/url_test_util.mm
@@ -16,8 +16,4 @@
   return NavigationItemImpl::GetDisplayTitleForURL(url);
 }
 
-std::string GetContentAndFragmentForUrl(const GURL& url) {
-  return url.GetContent() + (url.has_ref() ? "#" + url.ref() : "");
-}
-
 }  // namespace web