OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/chrome_url_util.h" |
| 6 |
| 7 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 8 #import "net/base/mac/url_conversions.h" |
| 9 #import "testing/gtest_mac.h" |
| 10 #include "url/gurl.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 TEST(ChromeURLUtilTest, TestIsExternalFileReference) { |
| 15 GURL external_url("uischeme://external-file/foo/bar"); |
| 16 GURL not_external_url("uischeme://foo/bar"); |
| 17 GURL still_not_external_url("http://external-file/foo/bar"); |
| 18 EXPECT_TRUE(UrlIsExternalFileReference(external_url)); |
| 19 EXPECT_FALSE(UrlIsExternalFileReference(not_external_url)); |
| 20 EXPECT_FALSE(UrlIsExternalFileReference(still_not_external_url)); |
| 21 } |
| 22 |
| 23 TEST(ChromeURLUtilTest, TestRewriteURLChromium) { |
| 24 [[ChromeAppConstants sharedInstance] setCallbackSchemeForTesting:@"chromium"]; |
| 25 NSURL* expected = [NSURL URLWithString:@"chromium://"]; |
| 26 NSURL* rewritten = UrlToLaunchChrome(); |
| 27 EXPECT_NSEQ([expected absoluteString], [rewritten absoluteString]); |
| 28 } |
| 29 |
| 30 TEST(ChromeURLUtilTest, TestRewriteURLGoogleChrome) { |
| 31 [[ChromeAppConstants sharedInstance] |
| 32 setCallbackSchemeForTesting:@"googlechrome"]; |
| 33 NSURL* expected = [NSURL URLWithString:@"googlechrome://"]; |
| 34 NSURL* rewritten = UrlToLaunchChrome(); |
| 35 EXPECT_NSEQ([expected absoluteString], [rewritten absoluteString]); |
| 36 } |
| 37 |
| 38 TEST(ChromeURLUtilTest, TestAppIconURL) { |
| 39 [[ChromeAppConstants sharedInstance] setAppIconURLProviderForTesting:nil]; |
| 40 NSURL* url = UrlOfChromeAppIcon(29, 29); |
| 41 EXPECT_TRUE(url); |
| 42 GURL gurl(net::GURLWithNSURL(url)); |
| 43 EXPECT_TRUE(gurl.is_valid()); |
| 44 } |
| 45 |
| 46 const char* kSchemeTestData[] = { |
| 47 "http://foo.com", |
| 48 "https://foo.com", |
| 49 "data:text/html;charset=utf-8,Hello", |
| 50 "about:blank", |
| 51 "uischeme://settings", |
| 52 }; |
| 53 |
| 54 TEST(ChromeURLUtilTest, NSURLHasChromeScheme) { |
| 55 for (unsigned int i = 0; i < arraysize(kSchemeTestData); ++i) { |
| 56 const char* url = kSchemeTestData[i]; |
| 57 bool nsurl_result = UrlHasChromeScheme( |
| 58 [NSURL URLWithString:[NSString stringWithUTF8String:url]]); |
| 59 bool gurl_result = GURL(url).SchemeIs( |
| 60 ios::GetChromeBrowserProvider()->GetChromeUIScheme()); |
| 61 EXPECT_EQ(gurl_result, nsurl_result) << "Scheme check failed for " << url; |
| 62 } |
| 63 } |
| 64 |
| 65 } // namespace |
OLD | NEW |