Chromium Code Reviews| 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..bd47d68e0046c34d1be698de57322ee4389431af |
| --- /dev/null |
| +++ b/chrome/renderer/app_categorizer_unittest.cc |
| @@ -0,0 +1,125 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
sky
2016/05/19 15:43:10
2016 (and no (c)).
AlexZ
2016/05/19 16:18:52
Done.
|
| +// 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://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://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 |
| + |
| +typedef testing::Test AppCategorizerTest; |
|
sky
2016/05/19 15:43:10
Remove this and use TEST rather than TEST_F
AlexZ
2016/05/19 16:18:52
Done.
|
| + |
| +TEST_F(AppCategorizerTest, IsHangoutsUrl) { |
| + for (size_t i = 0; i < arraysize(kChatAppURLs); ++i) { |
| + EXPECT_TRUE(app_categorizer::IsHangoutsUrl(GURL(kChatAppURLs[i]))); |
| + } |
| + |
| + for (size_t i = 0; i < arraysize(kBadChatAppURLs); ++i) { |
| + EXPECT_FALSE(app_categorizer::IsHangoutsUrl(GURL(kBadChatAppURLs[i]))); |
| + } |
| +} |
| + |
| +TEST_F(AppCategorizerTest, IsWhitelistedApp) { |
| + // Hangouts app |
| + { |
| + EXPECT_EQ(arraysize(kChatAppURLs), arraysize(kChatManifestFSs)); |
| + for (size_t i = 0; i < arraysize(kChatAppURLs); ++i) { |
| + EXPECT_TRUE(app_categorizer::IsWhitelistedApp( |
| + GURL(kChatManifestFSs[i]), GURL(kChatAppURLs[i]))); |
| + } |
| + for (size_t i = 0; i < arraysize(kBadChatAppURLs); ++i) { |
| + EXPECT_FALSE(app_categorizer::IsWhitelistedApp( |
| + GURL("filesystem:https://irrelevant.com/"), |
| + GURL(kBadChatAppURLs[i]))); |
| + } |
| + |
| + // Manifest URL not filesystem |
| + EXPECT_FALSE(app_categorizer::IsWhitelistedApp( |
| + GURL("https://hangouts.google.com/foo"), |
| + GURL("https://hangouts.google.com/hangouts/foo"))); |
| + |
| + // Manifest URL not https |
| + EXPECT_FALSE(app_categorizer::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(app_categorizer::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(app_categorizer::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(app_categorizer::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(app_categorizer::IsWhitelistedApp( |
| + GURL(kBadPhotosManifestURLs[i]), GURL(kBadPhotosAppURLs[i]))); |
| + } |
| + } |
| +} |