OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/base64.h" | 5 #include "base/base64.h" |
6 #include "base/base_paths.h" | 6 #include "base/base_paths.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/test/chromedriver/chrome/status.h" | 14 #include "chrome/test/chromedriver/chrome/status.h" |
15 #include "chrome/test/chromedriver/chrome_launcher.h" | 15 #include "chrome/test/chromedriver/chrome_launcher.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 TEST(ProcessCommandLineArgs, NoArgs) { | |
19 CommandLine command(CommandLine::NO_PROGRAM); | |
20 base::ListValue switches; | |
21 ASSERT_TRUE(switches.empty()); | |
22 Status status = internal::ProcessCommandLineArgs(&switches, &command); | |
23 ASSERT_TRUE(status.IsOk()); | |
24 ASSERT_TRUE(command.GetSwitches().empty()); | |
25 } | |
26 | |
27 TEST(ProcessCommandLineArgs, SingleArgWithoutValue) { | |
28 CommandLine command(CommandLine::NO_PROGRAM); | |
29 base::ListValue switches; | |
30 switches.AppendString("enable-nacl"); | |
31 ASSERT_EQ(1u, switches.GetSize()); | |
32 Status status = internal::ProcessCommandLineArgs(&switches, &command); | |
33 ASSERT_TRUE(status.IsOk()); | |
34 ASSERT_EQ(1u, command.GetSwitches().size()); | |
35 ASSERT_TRUE(command.HasSwitch("enable-nacl")); | |
36 } | |
37 | |
38 TEST(ProcessCommandLineArgs, SingleArgWithValue) { | |
39 CommandLine command(CommandLine::NO_PROGRAM); | |
40 base::ListValue switches; | |
41 switches.AppendString("load-extension=/test/extension"); | |
42 ASSERT_EQ(1u, switches.GetSize()); | |
43 Status status = internal::ProcessCommandLineArgs(&switches, &command); | |
44 ASSERT_TRUE(status.IsOk()); | |
45 ASSERT_EQ(1u, command.GetSwitches().size()); | |
46 ASSERT_TRUE(command.HasSwitch("load-extension")); | |
47 ASSERT_EQ("/test/extension", command.GetSwitchValueASCII("load-extension")); | |
48 } | |
49 | |
50 TEST(ProcessCommandLineArgs, MultipleArgs) { | |
51 CommandLine command(CommandLine::NO_PROGRAM); | |
52 base::ListValue switches; | |
53 switches.AppendString("disable-sync"); | |
54 switches.AppendString("user-data-dir=/test/user/data"); | |
55 ASSERT_EQ(2u, switches.GetSize()); | |
56 Status status = internal::ProcessCommandLineArgs(&switches, &command); | |
57 ASSERT_TRUE(status.IsOk()); | |
58 ASSERT_EQ(2u, command.GetSwitches().size()); | |
59 ASSERT_TRUE(command.HasSwitch("disable-sync")); | |
60 ASSERT_TRUE(command.HasSwitch("user-data-dir")); | |
61 ASSERT_EQ("/test/user/data", command.GetSwitchValueASCII("user-data-dir")); | |
62 } | |
63 | |
64 TEST(ProcessExtensions, NoExtension) { | 18 TEST(ProcessExtensions, NoExtension) { |
65 CommandLine command(CommandLine::NO_PROGRAM); | 19 CommandLine command(CommandLine::NO_PROGRAM); |
66 base::ListValue extensions; | 20 std::vector<std::string> extensions; |
67 base::FilePath extension_dir; | 21 base::FilePath extension_dir; |
68 Status status = internal::ProcessExtensions(&extensions, extension_dir, | 22 Status status = internal::ProcessExtensions(extensions, extension_dir, |
69 &command); | 23 &command); |
70 ASSERT_TRUE(status.IsOk()); | 24 ASSERT_TRUE(status.IsOk()); |
71 ASSERT_FALSE(command.HasSwitch("load-extension")); | 25 ASSERT_FALSE(command.HasSwitch("load-extension")); |
72 } | 26 } |
73 | 27 |
74 TEST(ProcessExtensions, SingleExtension) { | 28 TEST(ProcessExtensions, SingleExtension) { |
75 base::FilePath source_root; | 29 base::FilePath source_root; |
76 PathService::Get(base::DIR_SOURCE_ROOT, &source_root); | 30 PathService::Get(base::DIR_SOURCE_ROOT, &source_root); |
77 base::FilePath crx_file_path = source_root.AppendASCII( | 31 base::FilePath crx_file_path = source_root.AppendASCII( |
78 "chrome/test/data/chromedriver/ext_test_1.crx"); | 32 "chrome/test/data/chromedriver/ext_test_1.crx"); |
79 std::string crx_contents; | 33 std::string crx_contents; |
80 ASSERT_TRUE(file_util::ReadFileToString(crx_file_path, &crx_contents)); | 34 ASSERT_TRUE(file_util::ReadFileToString(crx_file_path, &crx_contents)); |
81 | 35 |
82 base::ListValue extensions; | 36 std::vector<std::string> extensions; |
83 std::string crx_encoded; | 37 std::string crx_encoded; |
84 ASSERT_TRUE(base::Base64Encode(crx_contents, &crx_encoded)); | 38 ASSERT_TRUE(base::Base64Encode(crx_contents, &crx_encoded)); |
85 extensions.AppendString(crx_encoded); | 39 extensions.push_back(crx_encoded); |
86 | 40 |
87 base::ScopedTempDir extension_dir; | 41 base::ScopedTempDir extension_dir; |
88 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); | 42 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); |
89 | 43 |
90 CommandLine command(CommandLine::NO_PROGRAM); | 44 CommandLine command(CommandLine::NO_PROGRAM); |
91 Status status = internal::ProcessExtensions(&extensions, extension_dir.path(), | 45 Status status = internal::ProcessExtensions(extensions, extension_dir.path(), |
92 &command); | 46 &command); |
93 ASSERT_TRUE(status.IsOk()); | 47 ASSERT_TRUE(status.IsOk()); |
94 ASSERT_TRUE(command.HasSwitch("load-extension")); | 48 ASSERT_TRUE(command.HasSwitch("load-extension")); |
95 base::FilePath temp_ext_path = command.GetSwitchValuePath("load-extension"); | 49 base::FilePath temp_ext_path = command.GetSwitchValuePath("load-extension"); |
96 ASSERT_TRUE(file_util::PathExists(temp_ext_path)); | 50 ASSERT_TRUE(file_util::PathExists(temp_ext_path)); |
97 } | 51 } |
98 | 52 |
99 TEST(ProcessExtensions, MultipleExtensions) { | 53 TEST(ProcessExtensions, MultipleExtensions) { |
100 base::FilePath source_root; | 54 base::FilePath source_root; |
101 PathService::Get(base::DIR_SOURCE_ROOT, &source_root); | 55 PathService::Get(base::DIR_SOURCE_ROOT, &source_root); |
102 base::FilePath test_ext_path = source_root.AppendASCII( | 56 base::FilePath test_ext_path = source_root.AppendASCII( |
103 "chrome/test/data/chromedriver"); | 57 "chrome/test/data/chromedriver"); |
104 base::FilePath test_crx_1 = test_ext_path.AppendASCII("ext_test_1.crx"); | 58 base::FilePath test_crx_1 = test_ext_path.AppendASCII("ext_test_1.crx"); |
105 base::FilePath test_crx_2 = test_ext_path.AppendASCII("ext_test_2.crx"); | 59 base::FilePath test_crx_2 = test_ext_path.AppendASCII("ext_test_2.crx"); |
106 | 60 |
107 std::string crx_1_contents, crx_2_contents; | 61 std::string crx_1_contents, crx_2_contents; |
108 ASSERT_TRUE(file_util::ReadFileToString(test_crx_1, &crx_1_contents)); | 62 ASSERT_TRUE(file_util::ReadFileToString(test_crx_1, &crx_1_contents)); |
109 ASSERT_TRUE(file_util::ReadFileToString(test_crx_2, &crx_2_contents)); | 63 ASSERT_TRUE(file_util::ReadFileToString(test_crx_2, &crx_2_contents)); |
110 | 64 |
111 base::ListValue extensions; | 65 std::vector<std::string> extensions; |
112 std::string crx_1_encoded, crx_2_encoded; | 66 std::string crx_1_encoded, crx_2_encoded; |
113 ASSERT_TRUE(base::Base64Encode(crx_1_contents, &crx_1_encoded)); | 67 ASSERT_TRUE(base::Base64Encode(crx_1_contents, &crx_1_encoded)); |
114 ASSERT_TRUE(base::Base64Encode(crx_2_contents, &crx_2_encoded)); | 68 ASSERT_TRUE(base::Base64Encode(crx_2_contents, &crx_2_encoded)); |
115 extensions.AppendString(crx_1_encoded); | 69 extensions.push_back(crx_1_encoded); |
116 extensions.AppendString(crx_2_encoded); | 70 extensions.push_back(crx_2_encoded); |
117 | 71 |
118 base::ScopedTempDir extension_dir; | 72 base::ScopedTempDir extension_dir; |
119 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); | 73 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); |
120 | 74 |
121 CommandLine command(CommandLine::NO_PROGRAM); | 75 CommandLine command(CommandLine::NO_PROGRAM); |
122 Status status = internal::ProcessExtensions(&extensions, extension_dir.path(), | 76 Status status = internal::ProcessExtensions(extensions, extension_dir.path(), |
123 &command); | 77 &command); |
124 ASSERT_TRUE(status.IsOk()); | 78 ASSERT_TRUE(status.IsOk()); |
125 ASSERT_TRUE(command.HasSwitch("load-extension")); | 79 ASSERT_TRUE(command.HasSwitch("load-extension")); |
126 CommandLine::StringType ext_paths = command.GetSwitchValueNative( | 80 CommandLine::StringType ext_paths = command.GetSwitchValueNative( |
127 "load-extension"); | 81 "load-extension"); |
128 std::vector<CommandLine::StringType> ext_path_list; | 82 std::vector<CommandLine::StringType> ext_path_list; |
129 base::SplitString(ext_paths, FILE_PATH_LITERAL(','), &ext_path_list); | 83 base::SplitString(ext_paths, FILE_PATH_LITERAL(','), &ext_path_list); |
130 ASSERT_EQ(2u, ext_path_list.size()); | 84 ASSERT_EQ(2u, ext_path_list.size()); |
131 ASSERT_TRUE(file_util::PathExists(base::FilePath(ext_path_list[0]))); | 85 ASSERT_TRUE(file_util::PathExists(base::FilePath(ext_path_list[0]))); |
132 ASSERT_TRUE(file_util::PathExists(base::FilePath(ext_path_list[1]))); | 86 ASSERT_TRUE(file_util::PathExists(base::FilePath(ext_path_list[1]))); |
(...skipping 16 matching lines...) Expand all Loading... |
149 temp_dir.path().AppendASCII("Default").AppendASCII("Preferences"); | 103 temp_dir.path().AppendASCII("Default").AppendASCII("Preferences"); |
150 std::string prefs_str; | 104 std::string prefs_str; |
151 ASSERT_TRUE(file_util::ReadFileToString(prefs_file, &prefs_str)); | 105 ASSERT_TRUE(file_util::ReadFileToString(prefs_file, &prefs_str)); |
152 ASSERT_TRUE(prefs_str.find("myPrefsKey") != std::string::npos); | 106 ASSERT_TRUE(prefs_str.find("myPrefsKey") != std::string::npos); |
153 | 107 |
154 base::FilePath local_state_file = temp_dir.path().AppendASCII("Local State"); | 108 base::FilePath local_state_file = temp_dir.path().AppendASCII("Local State"); |
155 std::string local_state_str; | 109 std::string local_state_str; |
156 ASSERT_TRUE(file_util::ReadFileToString(local_state_file, &local_state_str)); | 110 ASSERT_TRUE(file_util::ReadFileToString(local_state_file, &local_state_str)); |
157 ASSERT_TRUE(local_state_str.find("myLocalKey") != std::string::npos); | 111 ASSERT_TRUE(local_state_str.find("myLocalKey") != std::string::npos); |
158 } | 112 } |
OLD | NEW |