Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10822)

Unified Diff: chrome/renderer/app_categorizer_unittest.cc

Issue 2001233002: Cherry-picking hangouts.google.com whitelisting change into M51 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/app_categorizer.cc ('k') | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/app_categorizer_unittest.cc
diff --git a/chrome/renderer/app_categorizer_unittest.cc b/chrome/renderer/app_categorizer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8a882aa555e37e3541669d523e25bc2161da4177
--- /dev/null
+++ b/chrome/renderer/app_categorizer_unittest.cc
@@ -0,0 +1,125 @@
+// 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/renderer/app_categorizer.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace {
+
+const char* kChatAppURLs[] = {
+ "https://hangouts.google.com/hangouts/foo",
+ "https://hAnGoUtS.gOoGlE.com/HaNgOuTs/foo",
+ "https://meet.google.com/hangouts/foo",
+ "https://talkgadget.google.com/hangouts/foo",
+ "https://staging.talkgadget.google.com/hangouts/foo",
+ "https://plus.google.com/hangouts/foo",
+ "https://plus.sandbox.google.com/hangouts/foo"
+};
+
+const char* kChatManifestFSs[] = {
+ "filesystem:https://hangouts.google.com/foo",
+ "filesystem:https://hAnGoUtS.gOoGlE.com/foo",
+ "filesystem:https://meet.google.com/foo",
+ "filesystem:https://talkgadget.google.com/foo",
+ "filesystem:https://staging.talkgadget.google.com/foo",
+ "filesystem:https://plus.google.com/foo",
+ "filesystem:https://plus.sandbox.google.com/foo"
+};
+
+const char* kBadChatAppURLs[] = {
+ "http://talkgadget.google.com/hangouts/foo", // not https
+ "https://talkgadget.evil.com/hangouts/foo" // domain not whitelisted
+};
+
+const char* kPhotosAppURLs[] = {
+ "https://foo.plus.google.com",
+ "https://foo.plus.sandbox.google.com"
+};
+
+const char* kPhotosManifestURLs[] = {
+ "https://ssl.gstatic.com/photos/nacl/foo",
+ "https://ssl.gstatic.com/s2/oz/nacl/foo"
+};
+
+const char* kBadPhotosAppURLs[] = {
+ "https://plus.google.com/foo",
+ "https://plus.google.com/foo",
+ "https://plus.google.com/foo",
+ "http://plus.google.com/foo", // http scheme
+ "https://plus.evil.com/foo", // domain not whitelisted
+};
+
+const char* kBadPhotosManifestURLs[] = {
+ "http://ssl.gstatic.com/photos/nacl/foo", // http scheme
+ "https://lss.gstatic.com/photos/nacl/foo", // bad hostname
+ "https://ssl.gstatic.com/wrong/photos/nacl/foo", // bad path
+ "https://ssl.gstatic.com/photos/nacl/foo",
+ "https://ssl.gstatic.com/photos/nacl/foo",
+};
+
+} // namespace
+
+TEST(AppCategorizerTest, IsHangoutsUrl) {
+ for (size_t i = 0; i < arraysize(kChatAppURLs); ++i) {
+ EXPECT_TRUE(AppCategorizer::IsHangoutsUrl(GURL(kChatAppURLs[i])));
+ }
+
+ for (size_t i = 0; i < arraysize(kBadChatAppURLs); ++i) {
+ EXPECT_FALSE(AppCategorizer::IsHangoutsUrl(GURL(kBadChatAppURLs[i])));
+ }
+}
+
+TEST(AppCategorizerTest, IsWhitelistedApp) {
+ // Hangouts app
+ {
+ EXPECT_EQ(arraysize(kChatAppURLs), arraysize(kChatManifestFSs));
+ for (size_t i = 0; i < arraysize(kChatAppURLs); ++i) {
+ EXPECT_TRUE(AppCategorizer::IsWhitelistedApp(
+ GURL(kChatManifestFSs[i]), GURL(kChatAppURLs[i])));
+ }
+ for (size_t i = 0; i < arraysize(kBadChatAppURLs); ++i) {
+ EXPECT_FALSE(AppCategorizer::IsWhitelistedApp(
+ GURL("filesystem:https://irrelevant.com/"),
+ GURL(kBadChatAppURLs[i])));
+ }
+
+ // Manifest URL not filesystem
+ EXPECT_FALSE(AppCategorizer::IsWhitelistedApp(
+ GURL("https://hangouts.google.com/foo"),
+ GURL("https://hangouts.google.com/hangouts/foo")));
+
+ // Manifest URL not https
+ EXPECT_FALSE(AppCategorizer::IsWhitelistedApp(
+ GURL("filesystem:http://hangouts.google.com/foo"),
+ GURL("https://hangouts.google.com/hangouts/foo")));
+
+ // Manifest URL hostname does not match that of the app URL
+ EXPECT_FALSE(AppCategorizer::IsWhitelistedApp(
+ GURL("filesystem:https://meet.google.com/foo"),
+ GURL("https://hangouts.google.com/hangouts/foo")));
+ }
+
+ // Photos app
+ {
+ EXPECT_EQ(arraysize(kPhotosAppURLs), arraysize(kPhotosManifestURLs));
+ for (size_t i = 0; i < arraysize(kPhotosAppURLs); ++i) {
+ EXPECT_TRUE(AppCategorizer::IsWhitelistedApp(
+ GURL(kPhotosManifestURLs[i]), GURL(kPhotosAppURLs[i])));
+ }
+ // The app/manifest two sides do not have any coorelation for the Photos app
+ for (size_t i = 0; i < arraysize(kPhotosAppURLs); ++i) {
+ EXPECT_TRUE(AppCategorizer::IsWhitelistedApp(
+ GURL(kPhotosManifestURLs[(i + 1) % arraysize(kPhotosAppURLs)]),
+ GURL(kPhotosAppURLs[i])));
+ }
+
+ EXPECT_EQ(arraysize(kBadPhotosAppURLs), arraysize(kBadPhotosManifestURLs));
+ for (size_t i = 0; i < arraysize(kBadPhotosAppURLs); ++i) {
+ EXPECT_FALSE(AppCategorizer::IsWhitelistedApp(
+ GURL(kBadPhotosManifestURLs[i]), GURL(kBadPhotosAppURLs[i])));
+ }
+ }
+}
« no previous file with comments | « chrome/renderer/app_categorizer.cc ('k') | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698