OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/test/channel_id_test_util.h" | 5 #include "base/strings/string_piece.h" |
6 | 6 #include "content/child/site_isolation_stats_gatherer.h" |
7 #include <string> | |
8 | |
9 #include "crypto/ec_private_key.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
11 | 8 |
12 namespace net { | 9 using base::StringPiece; |
13 | 10 |
14 ::testing::AssertionResult KeysEqual(crypto::ECPrivateKey* key1, | 11 namespace content { |
15 crypto::ECPrivateKey* key2) { | 12 |
16 std::string public_key1, public_key2; | 13 TEST(SiteIsolationStatsGathererTest, SniffForJS) { |
17 EXPECT_TRUE(key1 && key1->ExportRawPublicKey(&public_key1)); | 14 StringPiece basic_js_data("var a = 4"); |
18 EXPECT_TRUE(key2 && key2->ExportRawPublicKey(&public_key2)); | 15 StringPiece js_data("\t\t\r\n var a = 4"); |
19 if (public_key1 == public_key2) | 16 StringPiece json_data("\t\t\r\n { \"name\" : \"chrome\", "); |
20 return ::testing::AssertionSuccess(); | 17 StringPiece empty_data(""); |
21 else | 18 |
22 return ::testing::AssertionFailure(); | 19 EXPECT_TRUE(SiteIsolationStatsGatherer::SniffForJS(js_data)); |
| 20 EXPECT_FALSE(SiteIsolationStatsGatherer::SniffForJS(json_data)); |
| 21 |
| 22 // Basic bounds check. |
| 23 EXPECT_FALSE(SiteIsolationStatsGatherer::SniffForJS(empty_data)); |
23 } | 24 } |
24 | 25 |
25 } // namespace net | 26 } // namespace content |
OLD | NEW |