Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ios / chrome / browser / chrome_url_util_unittest.mm
blobc12b155de2bc2c7327f791fe5ff3005a26d3c145
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.
5 #import "ios/chrome/browser/chrome_url_util.h"
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"
12 namespace {
14 TEST(ChromeURLUtilTest, TestIsExternalFileReference) {
15   GURL external_url("chrome://external-file/foo/bar");
16   GURL not_external_url("chrome://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));
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]);
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]);
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());
46 const char* kSchemeTestData[] = {
47     "http://foo.com",
48     "https://foo.com",
49     "data:text/html;charset=utf-8,Hello",
50     "about:blank",
51     "chrome://settings",
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   }
65 }  // namespace