OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 ExtensionsTest::SetUp(); | 67 ExtensionsTest::SetUp(); |
68 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); | 68 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); |
69 browser_threads_.reset(new content::TestBrowserThreadBundle( | 69 browser_threads_.reset(new content::TestBrowserThreadBundle( |
70 content::TestBrowserThreadBundle::IO_MAINLOOP)); | 70 content::TestBrowserThreadBundle::IO_MAINLOOP)); |
71 in_process_utility_thread_helper_.reset( | 71 in_process_utility_thread_helper_.reset( |
72 new content::InProcessUtilityThreadHelper); | 72 new content::InProcessUtilityThreadHelper); |
73 // It will delete itself. | 73 // It will delete itself. |
74 client_ = new MockSandboxedUnpackerClient; | 74 client_ = new MockSandboxedUnpackerClient; |
75 | 75 |
76 sandboxed_unpacker_ = new SandboxedUnpacker( | 76 sandboxed_unpacker_ = new SandboxedUnpacker( |
77 Manifest::INTERNAL, Extension::NO_FLAGS, extensions_dir_.path(), | 77 Manifest::INTERNAL, Extension::NO_FLAGS, extensions_dir_.GetPath(), |
78 base::ThreadTaskRunnerHandle::Get(), client_); | 78 base::ThreadTaskRunnerHandle::Get(), client_); |
79 } | 79 } |
80 | 80 |
81 void TearDown() override { | 81 void TearDown() override { |
82 // Need to destruct SandboxedUnpacker before the message loop since | 82 // Need to destruct SandboxedUnpacker before the message loop since |
83 // it posts a task to it. | 83 // it posts a task to it. |
84 sandboxed_unpacker_ = NULL; | 84 sandboxed_unpacker_ = NULL; |
85 base::RunLoop().RunUntilIdle(); | 85 base::RunLoop().RunUntilIdle(); |
86 ExtensionsTest::TearDown(); | 86 ExtensionsTest::TearDown(); |
87 } | 87 } |
(...skipping 14 matching lines...) Expand all Loading... |
102 base::Bind( | 102 base::Bind( |
103 &SandboxedUnpacker::StartWithCrx, sandboxed_unpacker_, | 103 &SandboxedUnpacker::StartWithCrx, sandboxed_unpacker_, |
104 extensions::CRXFileInfo(std::string(), crx_path, package_hash))); | 104 extensions::CRXFileInfo(std::string(), crx_path, package_hash))); |
105 client_->WaitForUnpack(); | 105 client_->WaitForUnpack(); |
106 } | 106 } |
107 | 107 |
108 void SetupUnpackerWithDirectory(const std::string& crx_name) { | 108 void SetupUnpackerWithDirectory(const std::string& crx_name) { |
109 base::ScopedTempDir temp_dir; | 109 base::ScopedTempDir temp_dir; |
110 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 110 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
111 base::FilePath crx_path = GetCrxFullPath(crx_name); | 111 base::FilePath crx_path = GetCrxFullPath(crx_name); |
112 ASSERT_TRUE(zip::Unzip(crx_path, temp_dir.path())); | 112 ASSERT_TRUE(zip::Unzip(crx_path, temp_dir.GetPath())); |
113 | 113 |
114 std::string fake_id = crx_file::id_util::GenerateId(crx_name); | 114 std::string fake_id = crx_file::id_util::GenerateId(crx_name); |
115 std::string fake_public_key; | 115 std::string fake_public_key; |
116 base::Base64Encode(std::string(2048, 'k'), &fake_public_key); | 116 base::Base64Encode(std::string(2048, 'k'), &fake_public_key); |
117 base::ThreadTaskRunnerHandle::Get()->PostTask( | 117 base::ThreadTaskRunnerHandle::Get()->PostTask( |
118 FROM_HERE, | 118 FROM_HERE, |
119 base::Bind(&SandboxedUnpacker::StartWithDirectory, sandboxed_unpacker_, | 119 base::Bind(&SandboxedUnpacker::StartWithDirectory, sandboxed_unpacker_, |
120 fake_id, fake_public_key, temp_dir.Take())); | 120 fake_id, fake_public_key, temp_dir.Take())); |
121 client_->WaitForUnpack(); | 121 client_->WaitForUnpack(); |
122 } | 122 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 EXPECT_EQ(base::string16(), GetInstallError()); | 182 EXPECT_EQ(base::string16(), GetInstallError()); |
183 } | 183 } |
184 | 184 |
185 TEST_F(SandboxedUnpackerTest, SkipHashCheck) { | 185 TEST_F(SandboxedUnpackerTest, SkipHashCheck) { |
186 SetupUnpacker("good_l10n.crx", "badhash"); | 186 SetupUnpacker("good_l10n.crx", "badhash"); |
187 // Check that there is no error message. | 187 // Check that there is no error message. |
188 EXPECT_EQ(base::string16(), GetInstallError()); | 188 EXPECT_EQ(base::string16(), GetInstallError()); |
189 } | 189 } |
190 | 190 |
191 } // namespace extensions | 191 } // namespace extensions |
OLD | NEW |