Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: ios/chrome/browser/chrome_url_util_unittest.mm

Issue 2364373002: Removed some URL Utility functions & improved unit tests (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/chrome_url_util.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/chrome_url_util.h" 5 #import "ios/chrome/browser/chrome_url_util.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/strings/sys_string_conversions.h"
8 #include "ios/chrome/browser/chrome_url_constants.h" 9 #include "ios/chrome/browser/chrome_url_constants.h"
9 #import "net/base/mac/url_conversions.h" 10 #import "net/base/mac/url_conversions.h"
10 #import "testing/gtest_mac.h" 11 #import "testing/gtest_mac.h"
11 #include "url/gurl.h" 12 #include "url/gurl.h"
12 13
13 namespace { 14 namespace {
14 15
15 TEST(ChromeURLUtilTest, TestIsExternalFileReference) { 16 TEST(ChromeURLUtilTest, TestIsExternalFileReference) {
16 GURL external_url("chrome://external-file/foo/bar"); 17 GURL external_url("chrome://external-file/foo/bar");
17 GURL not_external_url("chrome://foo/bar"); 18 GURL not_external_url("chrome://foo/bar");
18 GURL still_not_external_url("http://external-file/foo/bar"); 19 GURL still_not_external_url("http://external-file/foo/bar");
19 EXPECT_TRUE(UrlIsExternalFileReference(external_url)); 20 EXPECT_TRUE(UrlIsExternalFileReference(external_url));
20 EXPECT_FALSE(UrlIsExternalFileReference(not_external_url)); 21 EXPECT_FALSE(UrlIsExternalFileReference(not_external_url));
21 EXPECT_FALSE(UrlIsExternalFileReference(still_not_external_url)); 22 EXPECT_FALSE(UrlIsExternalFileReference(still_not_external_url));
22 } 23 }
23 24
24 TEST(ChromeURLUtilTest, TestRewriteURLChromium) {
25 [[ChromeAppConstants sharedInstance] setCallbackSchemeForTesting:@"chromium"];
26 NSURL* expected = [NSURL URLWithString:@"chromium://"];
27 NSURL* rewritten = UrlToLaunchChrome();
28 EXPECT_NSEQ([expected absoluteString], [rewritten absoluteString]);
29 }
30
31 TEST(ChromeURLUtilTest, TestRewriteURLGoogleChrome) {
32 [[ChromeAppConstants sharedInstance]
33 setCallbackSchemeForTesting:@"googlechrome"];
34 NSURL* expected = [NSURL URLWithString:@"googlechrome://"];
35 NSURL* rewritten = UrlToLaunchChrome();
36 EXPECT_NSEQ([expected absoluteString], [rewritten absoluteString]);
37 }
38
39 TEST(ChromeURLUtilTest, TestAppIconURL) {
40 [[ChromeAppConstants sharedInstance] setAppIconURLProviderForTesting:nil];
41 NSURL* url = UrlOfChromeAppIcon(29, 29);
42 EXPECT_TRUE(url);
43 GURL gurl(net::GURLWithNSURL(url));
44 EXPECT_TRUE(gurl.is_valid());
45 }
46
47 const char* kSchemeTestData[] = { 25 const char* kSchemeTestData[] = {
48 "http://foo.com", 26 "http://foo.com",
49 "https://foo.com", 27 "https://foo.com",
50 "data:text/html;charset=utf-8,Hello", 28 "data:text/html;charset=utf-8,Hello",
51 "about:blank", 29 "about:blank",
52 "chrome://settings", 30 "chrome://settings",
53 }; 31 };
54 32
33 // Tests UrlHasChromeScheme with NSURL* parameter.
55 TEST(ChromeURLUtilTest, NSURLHasChromeScheme) { 34 TEST(ChromeURLUtilTest, NSURLHasChromeScheme) {
56 for (unsigned int i = 0; i < arraysize(kSchemeTestData); ++i) { 35 for (unsigned int i = 0; i < arraysize(kSchemeTestData); ++i) {
57 const char* url = kSchemeTestData[i]; 36 const char* url = kSchemeTestData[i];
58 bool nsurl_result = UrlHasChromeScheme( 37 NSURL* nsurl = [NSURL URLWithString:base::SysUTF8ToNSString(url)];
59 [NSURL URLWithString:[NSString stringWithUTF8String:url]]); 38 bool nsurl_result = UrlHasChromeScheme(nsurl);
60 bool gurl_result = GURL(url).SchemeIs(kChromeUIScheme); 39 EXPECT_EQ(GURL(url).SchemeIs(kChromeUIScheme), nsurl_result)
61 EXPECT_EQ(gurl_result, nsurl_result) << "Scheme check failed for " << url; 40 << "Scheme check failed for " << url;
62 } 41 }
63 } 42 }
64 43
44 // Tests UrlHasChromeScheme with const GURL& paramter.
45 TEST(ChromeURLUtilTest, GURLHasChromeScheme) {
46 for (unsigned int i = 0; i < arraysize(kSchemeTestData); ++i) {
47 GURL gurl(kSchemeTestData[i]);
48 bool result = UrlHasChromeScheme(gurl);
49 EXPECT_EQ(gurl.SchemeIs(kChromeUIScheme), result)
50 << "Scheme check failed for " << gurl.spec();
51 }
52 }
53
54 TEST(ChromeURLUtilTest, GetBundleURLScheme) {
55 // Verifies that there is some default values.
56 ChromeAppConstants* constants = [ChromeAppConstants sharedInstance];
57 NSString* originalScheme = [constants getBundleURLScheme];
58 EXPECT_GT([originalScheme length], 0U);
59
60 // Verifies that Chrome scheme can be reset for testing.
61 [constants setCallbackSchemeForTesting:@"blah"];
62 EXPECT_NSEQ(@"blah", [constants getBundleURLScheme]);
63
64 // Resets state in case of further tests.
65 [constants setCallbackSchemeForTesting:originalScheme];
66 }
67
65 } // namespace 68 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/chrome_url_util.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698