Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 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/renderer/app_categorizer.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 #include "url/gurl.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 const char* kChatAppURLs[] = { | |
| 13 "https://hangouts.google.com/hangouts/foo", | |
| 14 "https://meet.google.com/hangouts/foo", | |
| 15 "https://talkgadget.google.com/hangouts/foo", | |
| 16 "https://staging.talkgadget.google.com/hangouts/foo", | |
| 17 "https://plus.google.com/hangouts/foo", | |
| 18 "https://plus.sandbox.google.com/hangouts/foo" | |
| 19 }; | |
| 20 | |
| 21 const char* kChatManifestFSs[] = { | |
| 22 "filesystem:https://hangouts.google.com/foo", | |
| 23 "filesystem:https://meet.google.com/foo", | |
| 24 "filesystem:https://talkgadget.google.com/foo", | |
| 25 "filesystem:https://staging.talkgadget.google.com/foo", | |
| 26 "filesystem:https://plus.google.com/foo", | |
| 27 "filesystem:https://plus.sandbox.google.com/foo" | |
| 28 }; | |
| 29 | |
| 30 const char* kBadChatAppURLs[] = { | |
| 31 "http://talkgadget.google.com/hangouts/foo", // not https | |
| 32 "https://talkgadget.evil.com/hangouts/foo" // domain not whitelisted | |
| 33 }; | |
| 34 | |
| 35 const char* kPhotosAppURLs[] = { | |
| 36 "https://foo.plus.google.com", | |
| 37 "https://foo.plus.sandbox.google.com" | |
| 38 }; | |
| 39 | |
| 40 const char* kPhotosManifestURLs[] = { | |
| 41 "https://ssl.gstatic.com/photos/nacl/foo", | |
| 42 "https://ssl.gstatic.com/s2/oz/nacl/foo" | |
| 43 }; | |
| 44 | |
| 45 const char* kBadPhotosAppURLs[] = { | |
| 46 "https://plus.google.com/foo", | |
| 47 "https://plus.google.com/foo", | |
| 48 "https://plus.google.com/foo", | |
| 49 "http://plus.google.com/foo", // http scheme | |
| 50 "https://plus.evil.com/foo", // domain not whitelisted | |
| 51 }; | |
| 52 | |
| 53 const char* kBadPhotosManifestURLs[] = { | |
| 54 "http://ssl.gstatic.com/photos/nacl/foo", // http scheme | |
| 55 "https://lss.gstatic.com/photos/nacl/foo", // bad hostname | |
| 56 "https://ssl.gstatic.com/wrong/photos/nacl/foo", // bad path | |
| 57 "https://ssl.gstatic.com/photos/nacl/foo", | |
| 58 "https://ssl.gstatic.com/photos/nacl/foo", | |
| 59 }; | |
| 60 | |
| 61 } // namespace | |
| 62 | |
| 63 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.
| |
| 64 | |
| 65 TEST_F(AppCategorizerTest, IsHangoutsUrl) { | |
| 66 for (size_t i = 0; i < arraysize(kChatAppURLs); ++i) { | |
| 67 EXPECT_TRUE(app_categorizer::IsHangoutsUrl(GURL(kChatAppURLs[i]))); | |
| 68 } | |
| 69 | |
| 70 for (size_t i = 0; i < arraysize(kBadChatAppURLs); ++i) { | |
| 71 EXPECT_FALSE(app_categorizer::IsHangoutsUrl(GURL(kBadChatAppURLs[i]))); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 TEST_F(AppCategorizerTest, IsWhitelistedApp) { | |
| 76 // Hangouts app | |
| 77 { | |
| 78 EXPECT_EQ(arraysize(kChatAppURLs), arraysize(kChatManifestFSs)); | |
| 79 for (size_t i = 0; i < arraysize(kChatAppURLs); ++i) { | |
| 80 EXPECT_TRUE(app_categorizer::IsWhitelistedApp( | |
| 81 GURL(kChatManifestFSs[i]), GURL(kChatAppURLs[i]))); | |
| 82 } | |
| 83 for (size_t i = 0; i < arraysize(kBadChatAppURLs); ++i) { | |
| 84 EXPECT_FALSE(app_categorizer::IsWhitelistedApp( | |
| 85 GURL("filesystem:https://irrelevant.com/"), | |
| 86 GURL(kBadChatAppURLs[i]))); | |
| 87 } | |
| 88 | |
| 89 // Manifest URL not filesystem | |
| 90 EXPECT_FALSE(app_categorizer::IsWhitelistedApp( | |
| 91 GURL("https://hangouts.google.com/foo"), | |
| 92 GURL("https://hangouts.google.com/hangouts/foo"))); | |
| 93 | |
| 94 // Manifest URL not https | |
| 95 EXPECT_FALSE(app_categorizer::IsWhitelistedApp( | |
| 96 GURL("filesystem:http://hangouts.google.com/foo"), | |
| 97 GURL("https://hangouts.google.com/hangouts/foo"))); | |
| 98 | |
| 99 // Manifest URL hostname does not match that of the app URL | |
| 100 EXPECT_FALSE(app_categorizer::IsWhitelistedApp( | |
| 101 GURL("filesystem:https://meet.google.com/foo"), | |
| 102 GURL("https://hangouts.google.com/hangouts/foo"))); | |
| 103 } | |
| 104 | |
| 105 // Photos app | |
| 106 { | |
| 107 EXPECT_EQ(arraysize(kPhotosAppURLs), arraysize(kPhotosManifestURLs)); | |
| 108 for (size_t i = 0; i < arraysize(kPhotosAppURLs); ++i) { | |
| 109 EXPECT_TRUE(app_categorizer::IsWhitelistedApp( | |
| 110 GURL(kPhotosManifestURLs[i]), GURL(kPhotosAppURLs[i]))); | |
| 111 } | |
| 112 // The app/manifest two sides do not have any coorelation for the Photos app | |
| 113 for (size_t i = 0; i < arraysize(kPhotosAppURLs); ++i) { | |
| 114 EXPECT_TRUE(app_categorizer::IsWhitelistedApp( | |
| 115 GURL(kPhotosManifestURLs[(i + 1) % arraysize(kPhotosAppURLs)]), | |
| 116 GURL(kPhotosAppURLs[i]))); | |
| 117 } | |
| 118 | |
| 119 EXPECT_EQ(arraysize(kBadPhotosAppURLs), arraysize(kBadPhotosManifestURLs)); | |
| 120 for (size_t i = 0; i < arraysize(kBadPhotosAppURLs); ++i) { | |
| 121 EXPECT_FALSE(app_categorizer::IsWhitelistedApp( | |
| 122 GURL(kBadPhotosManifestURLs[i]), GURL(kBadPhotosAppURLs[i]))); | |
| 123 } | |
| 124 } | |
| 125 } | |
| OLD | NEW |