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_builder.h" |
| 6 #include "content/public/common/manifest.h" |
| 7 #include "content/renderer/manifest/manifest_parser.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" |
| 10 |
| 11 TEST(WebApkBuilderTest, DisplayToString) { |
| 12 for (int display = 0; display < blink::WebDisplayModeLast; ++display) { |
| 13 if (display == blink::WebDisplayModeUndefined) |
| 14 continue; |
| 15 |
| 16 std::string display_string = WebApkBuilder::DisplayToString( |
| 17 static_cast<blink::WebDisplayMode>(display)); |
| 18 content::ManifestParser parser("{\"display\":\"" + display_string + "\"}", |
| 19 GURL(), GURL()); |
| 20 parser.Parse(); |
| 21 EXPECT_FALSE(parser.failed()); |
| 22 EXPECT_EQ(parser.manifest().display, display) |
| 23 << "Incorrect conversion from display enum value to string: " << display |
| 24 << " " << display_string; |
| 25 } |
| 26 } |
| 27 |
| 28 TEST(WebApkBuilderTest, OrientationToString) { |
| 29 for (int orientation = 0; |
| 30 orientation < blink::WebScreenOrientationLockNatural; ++orientation) { |
| 31 std::string orientation_string = WebApkBuilder::OrientationToString( |
| 32 static_cast<blink::WebScreenOrientationLockType>(orientation)); |
| 33 content::ManifestParser parser( |
| 34 "{\"orientation\":\"" + orientation_string + "\"}", GURL(), GURL()); |
| 35 parser.Parse(); |
| 36 EXPECT_FALSE(parser.failed()); |
| 37 EXPECT_EQ(parser.manifest().orientation, orientation) |
| 38 << "Incorrect conversion from display enum value to string: " |
| 39 << orientation << " " << orientation_string; |
| 40 } |
| 41 } |
| 42 |
| 43 TEST(WebApkBuilderTest, ColorToString) { |
| 44 // Non rgba() format. |
| 45 { |
| 46 content::ManifestParser parser("{\"theme_color\":\"#AABBCC\"}", GURL(), |
| 47 GURL()); |
| 48 parser.Parse(); |
| 49 ASSERT_FALSE(parser.failed()); |
| 50 std::string css_string = |
| 51 WebApkBuilder::ColorToString(parser.manifest().theme_color); |
| 52 EXPECT_EQ("rgba(170,187,204,1.00)", css_string); |
| 53 } |
| 54 |
| 55 // rgba() format with non opaque alpha. |
| 56 { |
| 57 content::ManifestParser parser("{\"theme_color\":\"rgba(10,20,30,0.2)\"}", |
| 58 GURL(), GURL()); |
| 59 parser.Parse(); |
| 60 ASSERT_FALSE(parser.failed()); |
| 61 std::string css_string = |
| 62 WebApkBuilder::ColorToString(parser.manifest().theme_color); |
| 63 EXPECT_EQ("rgba(10,20,30,0.20)", css_string); |
| 64 } |
| 65 |
| 66 // Invalid color. |
| 67 { |
| 68 content::ManifestParser parser("{\"theme_color\":\"falu\"}", GURL(), |
| 69 GURL()); |
| 70 parser.Parse(); |
| 71 ASSERT_FALSE(parser.failed()); |
| 72 ASSERT_EQ(content::Manifest::kInvalidOrMissingColor, |
| 73 parser.manifest().theme_color); |
| 74 std::string css_string = |
| 75 WebApkBuilder::ColorToString(parser.manifest().theme_color); |
| 76 EXPECT_EQ("", css_string); |
| 77 } |
| 78 } |
OLD | NEW |