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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 ASSERT_EQ(0u, bg_pages.size()); | 29 ASSERT_EQ(0u, bg_pages.size()); |
30 } | 30 } |
31 | 31 |
32 bool AddExtensionForInstall(const std::string& relative_path, | 32 bool AddExtensionForInstall(const std::string& relative_path, |
33 std::vector<std::string>* extensions) { | 33 std::vector<std::string>* extensions) { |
34 base::FilePath source_root; | 34 base::FilePath source_root; |
35 PathService::Get(base::DIR_SOURCE_ROOT, &source_root); | 35 PathService::Get(base::DIR_SOURCE_ROOT, &source_root); |
36 base::FilePath crx_file_path = source_root.AppendASCII( | 36 base::FilePath crx_file_path = source_root.AppendASCII( |
37 "chrome/test/data/chromedriver/" + relative_path); | 37 "chrome/test/data/chromedriver/" + relative_path); |
38 std::string crx_contents; | 38 std::string crx_contents; |
39 if (!file_util::ReadFileToString(crx_file_path, &crx_contents)) | 39 if (!base::ReadFileToString(crx_file_path, &crx_contents)) |
40 return false; | 40 return false; |
41 | 41 |
42 std::string crx_encoded; | 42 std::string crx_encoded; |
43 if (!base::Base64Encode(crx_contents, &crx_encoded)) | 43 if (!base::Base64Encode(crx_contents, &crx_encoded)) |
44 return false; | 44 return false; |
45 extensions->push_back(crx_encoded); | 45 extensions->push_back(crx_encoded); |
46 return true; | 46 return true; |
47 } | 47 } |
48 | 48 |
49 TEST(ProcessExtensions, SingleExtensionWithBgPage) { | 49 TEST(ProcessExtensions, SingleExtensionWithBgPage) { |
50 std::vector<std::string> extensions; | 50 std::vector<std::string> extensions; |
51 ASSERT_TRUE(AddExtensionForInstall("ext_slow_loader.crx", &extensions)); | 51 ASSERT_TRUE(AddExtensionForInstall("ext_slow_loader.crx", &extensions)); |
52 | 52 |
53 base::ScopedTempDir extension_dir; | 53 base::ScopedTempDir extension_dir; |
54 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); | 54 ASSERT_TRUE(extension_dir.CreateUniqueTempDir()); |
55 | 55 |
56 CommandLine command(CommandLine::NO_PROGRAM); | 56 CommandLine command(CommandLine::NO_PROGRAM); |
57 std::vector<std::string> bg_pages; | 57 std::vector<std::string> bg_pages; |
58 Status status = internal::ProcessExtensions(extensions, extension_dir.path(), | 58 Status status = internal::ProcessExtensions(extensions, extension_dir.path(), |
59 false, &command, &bg_pages); | 59 false, &command, &bg_pages); |
60 ASSERT_TRUE(status.IsOk()); | 60 ASSERT_TRUE(status.IsOk()); |
61 ASSERT_TRUE(command.HasSwitch("load-extension")); | 61 ASSERT_TRUE(command.HasSwitch("load-extension")); |
62 base::FilePath temp_ext_path = command.GetSwitchValuePath("load-extension"); | 62 base::FilePath temp_ext_path = command.GetSwitchValuePath("load-extension"); |
63 ASSERT_TRUE(base::PathExists(temp_ext_path)); | 63 ASSERT_TRUE(base::PathExists(temp_ext_path)); |
64 std::string manifest_txt; | 64 std::string manifest_txt; |
65 ASSERT_TRUE(file_util::ReadFileToString( | 65 ASSERT_TRUE(base::ReadFileToString( |
66 temp_ext_path.AppendASCII("manifest.json"), &manifest_txt)); | 66 temp_ext_path.AppendASCII("manifest.json"), &manifest_txt)); |
67 scoped_ptr<base::Value> manifest(base::JSONReader::Read(manifest_txt)); | 67 scoped_ptr<base::Value> manifest(base::JSONReader::Read(manifest_txt)); |
68 ASSERT_TRUE(manifest); | 68 ASSERT_TRUE(manifest); |
69 base::DictionaryValue* manifest_dict = NULL; | 69 base::DictionaryValue* manifest_dict = NULL; |
70 ASSERT_TRUE(manifest->GetAsDictionary(&manifest_dict)); | 70 ASSERT_TRUE(manifest->GetAsDictionary(&manifest_dict)); |
71 std::string key; | 71 std::string key; |
72 ASSERT_TRUE(manifest_dict->GetString("key", &key)); | 72 ASSERT_TRUE(manifest_dict->GetString("key", &key)); |
73 ASSERT_EQ( | 73 ASSERT_EQ( |
74 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8qhZthEHjTIA3IYMzi79s2KFepVziY0du" | 74 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8qhZthEHjTIA3IYMzi79s2KFepVziY0du" |
75 "JzHcqRUB/YHSGseIUqcYXGazJhDz/" | 75 "JzHcqRUB/YHSGseIUqcYXGazJhDz/" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 base::DictionaryValue local_state; | 129 base::DictionaryValue local_state; |
130 local_state.SetString("myLocalKey", "ok"); | 130 local_state.SetString("myLocalKey", "ok"); |
131 local_state.SetStringWithoutPathExpansion("local.state.sub", "2"); | 131 local_state.SetStringWithoutPathExpansion("local.state.sub", "2"); |
132 Status status = internal::PrepareUserDataDir( | 132 Status status = internal::PrepareUserDataDir( |
133 temp_dir.path(), &prefs, &local_state); | 133 temp_dir.path(), &prefs, &local_state); |
134 ASSERT_EQ(kOk, status.code()); | 134 ASSERT_EQ(kOk, status.code()); |
135 | 135 |
136 base::FilePath prefs_file = | 136 base::FilePath prefs_file = |
137 temp_dir.path().AppendASCII("Default").AppendASCII("Preferences"); | 137 temp_dir.path().AppendASCII("Default").AppendASCII("Preferences"); |
138 std::string prefs_str; | 138 std::string prefs_str; |
139 ASSERT_TRUE(file_util::ReadFileToString(prefs_file, &prefs_str)); | 139 ASSERT_TRUE(base::ReadFileToString(prefs_file, &prefs_str)); |
140 scoped_ptr<base::Value> prefs_value(base::JSONReader::Read(prefs_str)); | 140 scoped_ptr<base::Value> prefs_value(base::JSONReader::Read(prefs_str)); |
141 const base::DictionaryValue* prefs_dict = NULL; | 141 const base::DictionaryValue* prefs_dict = NULL; |
142 ASSERT_TRUE(prefs_value->GetAsDictionary(&prefs_dict)); | 142 ASSERT_TRUE(prefs_value->GetAsDictionary(&prefs_dict)); |
143 AssertEQ(*prefs_dict, "myPrefsKey", "ok"); | 143 AssertEQ(*prefs_dict, "myPrefsKey", "ok"); |
144 AssertEQ(*prefs_dict, "pref.sub", "1"); | 144 AssertEQ(*prefs_dict, "pref.sub", "1"); |
145 | 145 |
146 base::FilePath local_state_file = temp_dir.path().AppendASCII("Local State"); | 146 base::FilePath local_state_file = temp_dir.path().AppendASCII("Local State"); |
147 std::string local_state_str; | 147 std::string local_state_str; |
148 ASSERT_TRUE(file_util::ReadFileToString(local_state_file, &local_state_str)); | 148 ASSERT_TRUE(base::ReadFileToString(local_state_file, &local_state_str)); |
149 scoped_ptr<base::Value> local_state_value( | 149 scoped_ptr<base::Value> local_state_value( |
150 base::JSONReader::Read(local_state_str)); | 150 base::JSONReader::Read(local_state_str)); |
151 const base::DictionaryValue* local_state_dict = NULL; | 151 const base::DictionaryValue* local_state_dict = NULL; |
152 ASSERT_TRUE(local_state_value->GetAsDictionary(&local_state_dict)); | 152 ASSERT_TRUE(local_state_value->GetAsDictionary(&local_state_dict)); |
153 AssertEQ(*local_state_dict, "myLocalKey", "ok"); | 153 AssertEQ(*local_state_dict, "myLocalKey", "ok"); |
154 AssertEQ(*local_state_dict, "local.state.sub", "2"); | 154 AssertEQ(*local_state_dict, "local.state.sub", "2"); |
155 } | 155 } |
OLD | NEW |