Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 #include "chrome/browser/android/webapk/webapk_web_manifest_checker.h" | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "content/public/common/manifest.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "third_party/WebKit/public/platform/WebDisplayMode.h" | |
| 11 #include "url/gurl.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 base::NullableString16 ToNullableUTF16(const std::string& str) { | |
| 16 return base::NullableString16(base::UTF8ToUTF16(str), false); | |
| 17 } | |
| 18 | |
| 19 content::Manifest GetValidManifest() { | |
| 20 content::Manifest manifest; | |
| 21 manifest.name = ToNullableUTF16("foo"); | |
| 22 manifest.short_name = ToNullableUTF16("bar"); | |
| 23 manifest.start_url = GURL("http://example.com"); | |
| 24 manifest.display = blink::WebDisplayModeStandalone; | |
| 25 | |
| 26 content::Manifest::Icon icon; | |
| 27 icon.type = ToNullableUTF16("image/png"); | |
| 28 icon.sizes.push_back(gfx::Size(144, 144)); | |
| 29 manifest.icons.push_back(icon); | |
| 30 | |
| 31 return manifest; | |
| 32 } | |
| 33 | |
| 34 } // anonymous namespace | |
| 35 | |
| 36 TEST(WebApkWebManifestCheckerTest, Compatible) { | |
| 37 content::Manifest manifest = GetValidManifest(); | |
| 38 EXPECT_TRUE(AreWebManifestUrlsWebApkCompatible(manifest)); | |
| 39 } | |
| 40 | |
| 41 TEST(WebApkWebManifestCheckerTest, CompatibleURLHasNoPassword) { | |
| 42 const GURL kUrlWithPassword("http://answer:42@life/universe/and/everything"); | |
| 43 | |
| 44 content::Manifest manifest = GetValidManifest(); | |
| 45 manifest.start_url = kUrlWithPassword; | |
| 46 EXPECT_FALSE(AreWebManifestUrlsWebApkCompatible(manifest)); | |
| 47 | |
| 48 manifest = GetValidManifest(); | |
| 49 manifest.icons[0].src = kUrlWithPassword; | |
| 50 EXPECT_FALSE(AreWebManifestUrlsWebApkCompatible(manifest)); | |
| 51 } | |
| 52 | |
| 53 TEST(WebApkWebManifestCheckerTest, CompatibleURLHasNoPort) { | |
|
dominickn
2016/08/24 15:36:54
Minor nit - you should test manifest.scope as well
| |
| 54 const GURL kUrlWithPort("http://www.google.com:42"); | |
| 55 | |
| 56 content::Manifest manifest = GetValidManifest(); | |
| 57 manifest.start_url = kUrlWithPort; | |
| 58 EXPECT_FALSE(AreWebManifestUrlsWebApkCompatible(manifest)); | |
| 59 | |
| 60 manifest = GetValidManifest(); | |
| 61 manifest.icons[0].src = kUrlWithPort; | |
| 62 EXPECT_FALSE(AreWebManifestUrlsWebApkCompatible(manifest)); | |
| 63 } | |
| OLD | NEW |