OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
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/app_installer/win/app_installer_util.h" | |
6 | |
7 #include <map> | |
8 #include <string> | |
9 | |
10 #include "base/files/file_util.h" | |
11 #include "base/path_service.h" | |
12 #include "base/strings/sys_string_conversions.h" | |
13 #include "net/test/spawned_test_server/spawned_test_server.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace app_installer { | |
17 | |
18 TEST(AppInstallerUtilTest, ParseTag) { | |
19 std::map<std::string, std::string> parsed_pairs; | |
20 | |
21 parsed_pairs.clear(); | |
22 EXPECT_TRUE(ParseTag("key1=value1&key2=value2", &parsed_pairs)); | |
23 EXPECT_EQ(2, parsed_pairs.size()); | |
24 EXPECT_EQ("value1", parsed_pairs["key1"]); | |
25 EXPECT_EQ("value2", parsed_pairs["key2"]); | |
26 | |
27 parsed_pairs.clear(); | |
28 EXPECT_FALSE(ParseTag("a&b", &parsed_pairs)); | |
29 | |
30 parsed_pairs.clear(); | |
31 EXPECT_FALSE(ParseTag("#=a", &parsed_pairs)); | |
32 | |
33 parsed_pairs.clear(); | |
34 EXPECT_FALSE(ParseTag("a=\01", &parsed_pairs)); | |
35 } | |
36 | |
37 void TestFetchUrlWithScheme(net::SpawnedTestServer::Type type, bool success) { | |
38 net::SpawnedTestServer http_server( | |
39 type, net::SpawnedTestServer::kLocalhost, | |
40 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
41 ASSERT_TRUE(http_server.Start()); | |
42 | |
43 std::vector<uint8_t> response_data; | |
44 net::HostPortPair host_port = http_server.host_port_pair(); | |
45 EXPECT_EQ(success, | |
46 FetchUrl(L"user agent", base::SysUTF8ToWide(host_port.host()), | |
47 host_port.port(), L"files/extensions/app/manifest.json", | |
48 &response_data)); | |
49 if (success) { | |
50 EXPECT_TRUE(response_data.size()); | |
51 base::FilePath source_root; | |
52 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_root)); | |
53 base::FilePath file_path = source_root.Append( | |
54 FILE_PATH_LITERAL("chrome/test/data/extensions/app/manifest.json")); | |
55 std::string file_contents; | |
56 EXPECT_TRUE(base::ReadFileToString(file_path, &file_contents)); | |
57 EXPECT_EQ(file_contents, | |
58 std::string(response_data.begin(), response_data.end())); | |
59 } else { | |
60 EXPECT_FALSE(response_data.size()); | |
61 } | |
62 | |
63 ASSERT_TRUE(http_server.Stop()); | |
64 } | |
65 | |
66 TEST(AppInstallerUtilTest, FetchUrlHttps) { | |
67 TestFetchUrlWithScheme(net::SpawnedTestServer::TYPE_HTTPS, true); | |
68 } | |
69 | |
70 TEST(AppInstallerUtilTest, FetchUrlNoHttps) { | |
71 TestFetchUrlWithScheme(net::SpawnedTestServer::TYPE_HTTP, false); | |
72 } | |
73 | |
74 } // namespace app_installer | |
OLD | NEW |