Index: chrome/browser/android/webapk/webapk_builder_unittest.cc |
diff --git a/chrome/browser/android/webapk/webapk_builder_unittest.cc b/chrome/browser/android/webapk/webapk_builder_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..78caf9f76846514da66b6236201af0a60acf1e2b |
--- /dev/null |
+++ b/chrome/browser/android/webapk/webapk_builder_unittest.cc |
@@ -0,0 +1,78 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/android/webapk/webapk_builder.h" |
+#include "content/public/common/manifest.h" |
+#include "content/renderer/manifest/manifest_parser.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
+ |
+TEST(WebApkBuilderTest, DisplayToString) { |
+ for (int display = 0; display < blink::WebDisplayModeLast; ++display) { |
+ if (display == blink::WebDisplayModeUndefined) |
+ continue; |
+ |
+ std::string display_string = WebApkBuilder::DisplayToString( |
+ static_cast<blink::WebDisplayMode>(display)); |
+ content::ManifestParser parser("{\"display\":\"" + display_string + "\"}", |
+ GURL(), GURL()); |
+ parser.Parse(); |
+ EXPECT_FALSE(parser.failed()); |
+ EXPECT_EQ(parser.manifest().display, display) |
+ << "Incorrect conversion from display enum value to string: " << display |
+ << " " << display_string; |
+ } |
+} |
+ |
+TEST(WebApkBuilderTest, OrientationToString) { |
+ for (int orientation = 0; |
+ orientation < blink::WebScreenOrientationLockNatural; ++orientation) { |
+ std::string orientation_string = WebApkBuilder::OrientationToString( |
+ static_cast<blink::WebScreenOrientationLockType>(orientation)); |
+ content::ManifestParser parser( |
+ "{\"orientation\":\"" + orientation_string + "\"}", GURL(), GURL()); |
+ parser.Parse(); |
+ EXPECT_FALSE(parser.failed()); |
+ EXPECT_EQ(parser.manifest().orientation, orientation) |
+ << "Incorrect conversion from display enum value to string: " |
+ << orientation << " " << orientation_string; |
+ } |
+} |
+ |
+TEST(WebApkBuilderTest, ColorToString) { |
+ // Non rgba() format. |
+ { |
+ content::ManifestParser parser("{\"theme_color\":\"#AABBCC\"}", GURL(), |
+ GURL()); |
+ parser.Parse(); |
+ ASSERT_FALSE(parser.failed()); |
+ std::string css_string = |
+ WebApkBuilder::ColorToString(parser.manifest().theme_color); |
+ EXPECT_EQ("rgba(170,187,204,1.00)", css_string); |
+ } |
+ |
+ // rgba() format with non opaque alpha. |
+ { |
+ content::ManifestParser parser("{\"theme_color\":\"rgba(10,20,30,0.2)\"}", |
+ GURL(), GURL()); |
+ parser.Parse(); |
+ ASSERT_FALSE(parser.failed()); |
+ std::string css_string = |
+ WebApkBuilder::ColorToString(parser.manifest().theme_color); |
+ EXPECT_EQ("rgba(10,20,30,0.20)", css_string); |
+ } |
+ |
+ // Invalid color. |
+ { |
+ content::ManifestParser parser("{\"theme_color\":\"falu\"}", GURL(), |
+ GURL()); |
+ parser.Parse(); |
+ ASSERT_FALSE(parser.failed()); |
+ ASSERT_EQ(content::Manifest::kInvalidOrMissingColor, |
+ parser.manifest().theme_color); |
+ std::string css_string = |
+ WebApkBuilder::ColorToString(parser.manifest().theme_color); |
+ EXPECT_EQ("", css_string); |
+ } |
+} |