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 "chrome/browser/download/download_crx_util.h" | 5 #include "chrome/browser/download/download_crx_util.h" |
6 #include "chrome/browser/download/download_service.h" | 6 #include "chrome/browser/download/download_service.h" |
7 #include "chrome/browser/download/download_service_factory.h" | 7 #include "chrome/browser/download/download_service_factory.h" |
8 #include "chrome/browser/download/download_test_observer.h" | 8 #include "chrome/browser/download/download_test_observer.h" |
9 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
11 #include "chrome/browser/extensions/extension_install_ui.h" | 11 #include "chrome/browser/extensions/extension_install_prompt.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/extensions/extension_file_util.h" | 16 #include "chrome/common/extensions/extension_file_util.h" |
17 #include "chrome/common/extensions/extension_switch_utils.h" | 17 #include "chrome/common/extensions/extension_switch_utils.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 | 19 |
20 class SkBitmap; | 20 class SkBitmap; |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Observer waits for exactly one download to finish. | 24 // Observer waits for exactly one download to finish. |
25 | 25 |
26 class MockInstallUI : public ExtensionInstallUI { | 26 class MockInstallPrompt : public ExtensionInstallPrompt { |
27 public: | 27 public: |
28 explicit MockInstallUI(Profile* profile) : | 28 explicit MockInstallPrompt(Profile* profile) : |
29 ExtensionInstallUI(profile), confirmation_requested_(false) {} | 29 ExtensionInstallPrompt(profile), confirmation_requested_(false) {} |
30 | 30 |
31 // Did the Delegate request confirmation? | 31 // Did the Delegate request confirmation? |
32 bool confirmation_requested() { return confirmation_requested_; } | 32 bool confirmation_requested() { return confirmation_requested_; } |
33 | 33 |
34 // Overriding some of the ExtensionInstallUI API. | 34 // Overriding some of the ExtensionInstallUI API. |
35 void ConfirmInstall(Delegate* delegate, | 35 void ConfirmInstall(Delegate* delegate, |
36 const extensions::Extension* extension) { | 36 const extensions::Extension* extension) { |
37 confirmation_requested_ = true; | 37 confirmation_requested_ = true; |
38 delegate->InstallUIProceed(); | 38 delegate->InstallUIProceed(); |
39 } | 39 } |
(...skipping 13 matching lines...) Expand all Loading... |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { | 55 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { |
56 public: | 56 public: |
57 // Installs a crx from |crx_relpath| (a path relative to the extension test | 57 // Installs a crx from |crx_relpath| (a path relative to the extension test |
58 // data dir) with expected id |id|. Returns whether a confirmation prompt | 58 // data dir) with expected id |id|. Returns whether a confirmation prompt |
59 // happened or not. | 59 // happened or not. |
60 bool DidWhitelistInstallPrompt(const std::string& ext_relpath, | 60 bool DidWhitelistInstallPrompt(const std::string& ext_relpath, |
61 const std::string& id) { | 61 const std::string& id) { |
62 ExtensionService* service = browser()->profile()->GetExtensionService(); | 62 ExtensionService* service = browser()->profile()->GetExtensionService(); |
63 MockInstallUI* mock_install_ui = new MockInstallUI(browser()->profile()); | 63 MockInstallPrompt* mock_install_ui = |
| 64 new MockInstallPrompt(browser()->profile()); |
64 FilePath ext_path = test_data_dir_.AppendASCII(ext_relpath); | 65 FilePath ext_path = test_data_dir_.AppendASCII(ext_relpath); |
65 | 66 |
66 std::string error; | 67 std::string error; |
67 base::DictionaryValue* parsed_manifest = | 68 base::DictionaryValue* parsed_manifest = |
68 extension_file_util::LoadManifest(ext_path, &error); | 69 extension_file_util::LoadManifest(ext_path, &error); |
69 if (!parsed_manifest) | 70 if (!parsed_manifest) |
70 return false; | 71 return false; |
71 | 72 |
72 scoped_ptr<WebstoreInstaller::Approval> approval( | 73 scoped_ptr<WebstoreInstaller::Approval> approval( |
73 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( | 74 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 const int kNumDownloadsExpected = 1; | 134 const int kNumDownloadsExpected = 1; |
134 const bool kExpectFileSelectDialog = false; | 135 const bool kExpectFileSelectDialog = false; |
135 | 136 |
136 LOG(ERROR) << "PackAndInstallExtension: Packing extension"; | 137 LOG(ERROR) << "PackAndInstallExtension: Packing extension"; |
137 FilePath crx_path = PackExtension( | 138 FilePath crx_path = PackExtension( |
138 test_data_dir_.AppendASCII("common/background_page")); | 139 test_data_dir_.AppendASCII("common/background_page")); |
139 ASSERT_FALSE(crx_path.empty()); | 140 ASSERT_FALSE(crx_path.empty()); |
140 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end()); | 141 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end()); |
141 GURL url = GURL(std::string("file:///").append(crx_path_string)); | 142 GURL url = GURL(std::string("file:///").append(crx_path_string)); |
142 | 143 |
143 MockInstallUI* mock_ui = new MockInstallUI(browser()->profile()); | 144 MockInstallPrompt* mock_prompt = new MockInstallPrompt(browser()->profile()); |
144 download_crx_util::SetMockInstallUIForTesting(mock_ui); | 145 download_crx_util::SetMockInstallPromptForTesting(mock_prompt); |
145 | 146 |
146 LOG(ERROR) << "PackAndInstallExtension: Getting download manager"; | 147 LOG(ERROR) << "PackAndInstallExtension: Getting download manager"; |
147 content::DownloadManager* download_manager = | 148 content::DownloadManager* download_manager = |
148 DownloadServiceFactory::GetForProfile( | 149 DownloadServiceFactory::GetForProfile( |
149 browser()->profile())->GetDownloadManager(); | 150 browser()->profile())->GetDownloadManager(); |
150 | 151 |
151 LOG(ERROR) << "PackAndInstallExtension: Setting observer"; | 152 LOG(ERROR) << "PackAndInstallExtension: Setting observer"; |
152 scoped_ptr<DownloadTestObserver> observer( | 153 scoped_ptr<DownloadTestObserver> observer( |
153 new DownloadTestObserverTerminal( | 154 new DownloadTestObserverTerminal( |
154 download_manager, kNumDownloadsExpected, kExpectFileSelectDialog, | 155 download_manager, kNumDownloadsExpected, kExpectFileSelectDialog, |
155 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 156 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
156 LOG(ERROR) << "PackAndInstallExtension: Navigating to URL"; | 157 LOG(ERROR) << "PackAndInstallExtension: Navigating to URL"; |
157 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, | 158 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, |
158 ui_test_utils::BROWSER_TEST_NONE); | 159 ui_test_utils::BROWSER_TEST_NONE); |
159 | 160 |
160 EXPECT_TRUE(WaitForExtensionInstall()); | 161 EXPECT_TRUE(WaitForExtensionInstall()); |
161 LOG(ERROR) << "PackAndInstallExtension: Extension install"; | 162 LOG(ERROR) << "PackAndInstallExtension: Extension install"; |
162 EXPECT_TRUE(mock_ui->confirmation_requested()); | 163 EXPECT_TRUE(mock_prompt->confirmation_requested()); |
163 LOG(ERROR) << "PackAndInstallExtension: Extension install confirmed"; | 164 LOG(ERROR) << "PackAndInstallExtension: Extension install confirmed"; |
164 } | 165 } |
OLD | NEW |