| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 16 #include "extensions/browser/extensions_test.h" | 16 #include "extensions/browser/extensions_test.h" |
| 17 #include "extensions/browser/sandboxed_unpacker.h" | 17 #include "extensions/browser/sandboxed_unpacker.h" |
| 18 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
| 19 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/extension_paths.h" | 20 #include "extensions/common/extension_paths.h" |
| 21 #include "extensions/common/switches.h" | 21 #include "extensions/common/switches.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| 27 class MockSandboxedUnpackerClient : public SandboxedUnpackerClient { | 27 class MockSandboxedUnpackerClient : public SandboxedUnpackerClient { |
| 28 public: | 28 public: |
| 29 MockSandboxedUnpackerClient(const scoped_refptr<base::MessageLoopProxy>& loop) |
| 30 : SandboxedUnpackerClient(loop) {} |
| 31 |
| 29 void WaitForUnpack() { | 32 void WaitForUnpack() { |
| 30 scoped_refptr<content::MessageLoopRunner> runner = | 33 scoped_refptr<content::MessageLoopRunner> runner = |
| 31 new content::MessageLoopRunner; | 34 new content::MessageLoopRunner; |
| 32 quit_closure_ = runner->QuitClosure(); | 35 quit_closure_ = runner->QuitClosure(); |
| 33 runner->Run(); | 36 runner->Run(); |
| 34 } | 37 } |
| 35 | 38 |
| 36 base::FilePath temp_dir() const { return temp_dir_; } | 39 base::FilePath temp_dir() const { return temp_dir_; } |
| 37 base::string16 unpack_err() const { return error_; } | 40 base::string16 unpack_err() const { return error_; } |
| 38 | 41 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 61 class SandboxedUnpackerTest : public ExtensionsTest { | 64 class SandboxedUnpackerTest : public ExtensionsTest { |
| 62 public: | 65 public: |
| 63 void SetUp() override { | 66 void SetUp() override { |
| 64 ExtensionsTest::SetUp(); | 67 ExtensionsTest::SetUp(); |
| 65 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); | 68 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); |
| 66 browser_threads_.reset(new content::TestBrowserThreadBundle( | 69 browser_threads_.reset(new content::TestBrowserThreadBundle( |
| 67 content::TestBrowserThreadBundle::IO_MAINLOOP)); | 70 content::TestBrowserThreadBundle::IO_MAINLOOP)); |
| 68 in_process_utility_thread_helper_.reset( | 71 in_process_utility_thread_helper_.reset( |
| 69 new content::InProcessUtilityThreadHelper); | 72 new content::InProcessUtilityThreadHelper); |
| 70 // It will delete itself. | 73 // It will delete itself. |
| 71 client_ = new MockSandboxedUnpackerClient; | 74 client_ = new MockSandboxedUnpackerClient( |
| 75 content::BrowserThread::GetMessageLoopProxyForThread( |
| 76 content::BrowserThread::UI)); |
| 72 } | 77 } |
| 73 | 78 |
| 74 void TearDown() override { | 79 void TearDown() override { |
| 75 // Need to destruct SandboxedUnpacker before the message loop since | 80 // Need to destruct SandboxedUnpacker before the message loop since |
| 76 // it posts a task to it. | 81 // it posts a task to it. |
| 77 sandboxed_unpacker_ = NULL; | 82 sandboxed_unpacker_ = NULL; |
| 78 base::RunLoop().RunUntilIdle(); | 83 base::RunLoop().RunUntilIdle(); |
| 79 ExtensionsTest::TearDown(); | 84 ExtensionsTest::TearDown(); |
| 80 } | 85 } |
| 81 | 86 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 EXPECT_EQ(base::string16(), GetInstallError()); | 149 EXPECT_EQ(base::string16(), GetInstallError()); |
| 145 } | 150 } |
| 146 | 151 |
| 147 TEST_F(SandboxedUnpackerTest, SkipHashCheck) { | 152 TEST_F(SandboxedUnpackerTest, SkipHashCheck) { |
| 148 SetupUnpacker("good_l10n.crx", "badhash"); | 153 SetupUnpacker("good_l10n.crx", "badhash"); |
| 149 // Check that there is no error message. | 154 // Check that there is no error message. |
| 150 EXPECT_EQ(base::string16(), GetInstallError()); | 155 EXPECT_EQ(base::string16(), GetInstallError()); |
| 151 } | 156 } |
| 152 | 157 |
| 153 } // namespace extensions | 158 } // namespace extensions |
| OLD | NEW |