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" |
| 6 #include "chrome/browser/download/download_service.h" |
| 7 #include "chrome/browser/download/download_service_factory.h" |
| 8 #include "chrome/browser/download/download_test_observer.h" |
5 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
6 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
7 #include "chrome/browser/extensions/extension_install_ui.h" | 11 #include "chrome/browser/extensions/extension_install_ui.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/extensions/extension_file_util.h" | 16 #include "chrome/common/extensions/extension_file_util.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
14 | 18 |
15 class SkBitmap; | 19 class SkBitmap; |
16 | 20 |
17 namespace { | 21 namespace { |
18 | 22 |
| 23 // Observer waits for exactly one download to finish. |
| 24 |
19 class MockInstallUI : public ExtensionInstallUI { | 25 class MockInstallUI : public ExtensionInstallUI { |
20 public: | 26 public: |
21 explicit MockInstallUI(Profile* profile) : | 27 explicit MockInstallUI(Profile* profile) : |
22 ExtensionInstallUI(profile), confirmation_requested_(false) {} | 28 ExtensionInstallUI(profile), confirmation_requested_(false) {} |
23 | 29 |
24 // Did the Delegate request confirmation? | 30 // Did the Delegate request confirmation? |
25 bool confirmation_requested() { return confirmation_requested_; } | 31 bool confirmation_requested() { return confirmation_requested_; } |
26 | 32 |
27 // Overriding some of the ExtensionInstallUI API. | 33 // Overriding some of the ExtensionInstallUI API. |
28 void ConfirmInstall(Delegate* delegate, const Extension* extension) { | 34 void ConfirmInstall(Delegate* delegate, const Extension* extension) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 EXPECT_TRUE(InstallExtensionFromWebstore(crx_path, 1)); | 115 EXPECT_TRUE(InstallExtensionFromWebstore(crx_path, 1)); |
110 } | 116 } |
111 | 117 |
112 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PlatformAppCrx) { | 118 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PlatformAppCrx) { |
113 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 119 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
114 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 120 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
115 command_line->AppendSwitch(switches::kEnablePlatformApps); | 121 command_line->AppendSwitch(switches::kEnablePlatformApps); |
116 EXPECT_TRUE(InstallExtension( | 122 EXPECT_TRUE(InstallExtension( |
117 test_data_dir_.AppendASCII("generic_platform_app.crx"), 1)); | 123 test_data_dir_.AppendASCII("generic_platform_app.crx"), 1)); |
118 } | 124 } |
| 125 |
| 126 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PackAndInstallExtension) { |
| 127 const int kNumDownloadsExpected = 1; |
| 128 const bool kExpectFileSelectDialog = false; |
| 129 |
| 130 LOG(ERROR) << "PackAndInstallExtension: Packing extension"; |
| 131 FilePath crx_path = PackExtension( |
| 132 test_data_dir_.AppendASCII("common/background_page")); |
| 133 ASSERT_FALSE(crx_path.empty()); |
| 134 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end()); |
| 135 GURL url = GURL(std::string("file:///").append(crx_path_string)); |
| 136 |
| 137 MockInstallUI* mock_ui = new MockInstallUI(browser()->profile()); |
| 138 download_crx_util::SetMockInstallUIForTesting(mock_ui); |
| 139 |
| 140 LOG(ERROR) << "PackAndInstallExtension: Getting download manager"; |
| 141 content::DownloadManager* download_manager = |
| 142 DownloadServiceFactory::GetForProfile( |
| 143 browser()->profile())->GetDownloadManager(); |
| 144 |
| 145 LOG(ERROR) << "PackAndInstallExtension: Setting observer"; |
| 146 scoped_ptr<DownloadTestObserver> observer( |
| 147 new DownloadTestObserverTerminal( |
| 148 download_manager, kNumDownloadsExpected, kExpectFileSelectDialog, |
| 149 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 150 LOG(ERROR) << "PackAndInstallExtension: Navigating to URL"; |
| 151 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, |
| 152 ui_test_utils::BROWSER_TEST_NONE); |
| 153 |
| 154 EXPECT_TRUE(WaitForExtensionInstall()); |
| 155 LOG(ERROR) << "PackAndInstallExtension: Extension install"; |
| 156 EXPECT_TRUE(mock_ui->confirmation_requested()); |
| 157 LOG(ERROR) << "PackAndInstallExtension: Extension install confirmed"; |
| 158 } |
OLD | NEW |