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/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/sandboxed_unpacker.h" | 13 #include "chrome/browser/extensions/sandboxed_unpacker.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "content/public/browser/render_process_host.h" | |
16 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
18 #include "extensions/common/constants.h" | 17 #include "extensions/common/constants.h" |
19 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
22 | 21 |
23 namespace extensions { | 22 namespace extensions { |
24 | 23 |
25 class MockSandboxedUnpackerClient : public SandboxedUnpackerClient { | 24 class MockSandboxedUnpackerClient : public SandboxedUnpackerClient { |
(...skipping 28 matching lines...) Expand all Loading... |
54 base::Closure quit_closure_; | 53 base::Closure quit_closure_; |
55 base::FilePath temp_dir_; | 54 base::FilePath temp_dir_; |
56 }; | 55 }; |
57 | 56 |
58 class SandboxedUnpackerTest : public testing::Test { | 57 class SandboxedUnpackerTest : public testing::Test { |
59 public: | 58 public: |
60 virtual void SetUp() { | 59 virtual void SetUp() { |
61 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); | 60 ASSERT_TRUE(extensions_dir_.CreateUniqueTempDir()); |
62 browser_threads_.reset(new content::TestBrowserThreadBundle( | 61 browser_threads_.reset(new content::TestBrowserThreadBundle( |
63 content::TestBrowserThreadBundle::IO_MAINLOOP)); | 62 content::TestBrowserThreadBundle::IO_MAINLOOP)); |
| 63 in_process_utility_thread_helper_.reset( |
| 64 new content::InProcessUtilityThreadHelper); |
64 // It will delete itself. | 65 // It will delete itself. |
65 client_ = new MockSandboxedUnpackerClient; | 66 client_ = new MockSandboxedUnpackerClient; |
66 content::RenderProcessHost::SetRunRendererInProcess(true); | |
67 } | 67 } |
68 | 68 |
69 virtual void TearDown() { | 69 virtual void TearDown() { |
70 // Need to destruct SandboxedUnpacker before the message loop since | 70 // Need to destruct SandboxedUnpacker before the message loop since |
71 // it posts a task to it. | 71 // it posts a task to it. |
72 sandboxed_unpacker_ = NULL; | 72 sandboxed_unpacker_ = NULL; |
73 base::RunLoop().RunUntilIdle(); | 73 base::RunLoop().RunUntilIdle(); |
74 content::RenderProcessHost::SetRunRendererInProcess(false); | |
75 } | 74 } |
76 | 75 |
77 void SetupUnpacker(const std::string& crx_name) { | 76 void SetupUnpacker(const std::string& crx_name) { |
78 base::FilePath original_path; | 77 base::FilePath original_path; |
79 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); | 78 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path)); |
80 original_path = original_path.AppendASCII("extensions") | 79 original_path = original_path.AppendASCII("extensions") |
81 .AppendASCII("unpacker") | 80 .AppendASCII("unpacker") |
82 .AppendASCII(crx_name); | 81 .AppendASCII(crx_name); |
83 ASSERT_TRUE(base::PathExists(original_path)) << original_path.value(); | 82 ASSERT_TRUE(base::PathExists(original_path)) << original_path.value(); |
84 | 83 |
(...skipping 13 matching lines...) Expand all Loading... |
98 | 97 |
99 base::FilePath GetInstallPath() { | 98 base::FilePath GetInstallPath() { |
100 return client_->temp_dir().AppendASCII(kTempExtensionName); | 99 return client_->temp_dir().AppendASCII(kTempExtensionName); |
101 } | 100 } |
102 | 101 |
103 protected: | 102 protected: |
104 base::ScopedTempDir extensions_dir_; | 103 base::ScopedTempDir extensions_dir_; |
105 MockSandboxedUnpackerClient* client_; | 104 MockSandboxedUnpackerClient* client_; |
106 scoped_refptr<SandboxedUnpacker> sandboxed_unpacker_; | 105 scoped_refptr<SandboxedUnpacker> sandboxed_unpacker_; |
107 scoped_ptr<content::TestBrowserThreadBundle> browser_threads_; | 106 scoped_ptr<content::TestBrowserThreadBundle> browser_threads_; |
| 107 scoped_ptr<content::InProcessUtilityThreadHelper> |
| 108 in_process_utility_thread_helper_; |
108 }; | 109 }; |
109 | 110 |
110 TEST_F(SandboxedUnpackerTest, NoCatalogsSuccess) { | 111 TEST_F(SandboxedUnpackerTest, NoCatalogsSuccess) { |
111 SetupUnpacker("no_l10n.crx"); | 112 SetupUnpacker("no_l10n.crx"); |
112 // Check that there is no _locales folder. | 113 // Check that there is no _locales folder. |
113 base::FilePath install_path = | 114 base::FilePath install_path = |
114 GetInstallPath().Append(kLocaleFolder); | 115 GetInstallPath().Append(kLocaleFolder); |
115 EXPECT_FALSE(base::PathExists(install_path)); | 116 EXPECT_FALSE(base::PathExists(install_path)); |
116 } | 117 } |
117 | 118 |
118 TEST_F(SandboxedUnpackerTest, WithCatalogsSuccess) { | 119 TEST_F(SandboxedUnpackerTest, WithCatalogsSuccess) { |
119 SetupUnpacker("good_l10n.crx"); | 120 SetupUnpacker("good_l10n.crx"); |
120 // Check that there is _locales folder. | 121 // Check that there is _locales folder. |
121 base::FilePath install_path = | 122 base::FilePath install_path = |
122 GetInstallPath().Append(kLocaleFolder); | 123 GetInstallPath().Append(kLocaleFolder); |
123 EXPECT_TRUE(base::PathExists(install_path)); | 124 EXPECT_TRUE(base::PathExists(install_path)); |
124 } | 125 } |
125 | 126 |
126 } // namespace extensions | 127 } // namespace extensions |
OLD | NEW |