OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/webui/extensions/extension_settings_browsertest.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_settings_browsertest.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/crx_installer.h" | 11 #include "chrome/browser/extensions/crx_installer.h" |
12 #include "chrome/browser/extensions/extension_error_reporter.h" | 12 #include "chrome/browser/extensions/extension_error_reporter.h" |
13 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
14 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" | 14 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
16 #include "chrome/browser/extensions/unpacked_installer.h" | 16 #include "chrome/browser/extensions/unpacked_installer.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
26 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 27 #include "extensions/browser/extension_registry.h" |
27 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
28 #include "extensions/common/extension_set.h" | 29 #include "extensions/common/extension_set.h" |
29 | 30 |
30 using extensions::Extension; | 31 using extensions::Extension; |
31 | 32 |
32 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() | 33 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() |
33 : profile_(NULL) {} | 34 : profile_(NULL) {} |
34 | 35 |
35 ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {} | 36 ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {} |
36 | 37 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 const ShowDialogCallback& show_dialog_callback) override { | 70 const ShowDialogCallback& show_dialog_callback) override { |
70 delegate->InstallUIProceed(); | 71 delegate->InstallUIProceed(); |
71 } | 72 } |
72 }; | 73 }; |
73 | 74 |
74 const Extension* ExtensionSettingsUIBrowserTest::InstallExtension( | 75 const Extension* ExtensionSettingsUIBrowserTest::InstallExtension( |
75 const base::FilePath& path) { | 76 const base::FilePath& path) { |
76 Profile* profile = this->GetProfile(); | 77 Profile* profile = this->GetProfile(); |
77 ExtensionService* service = | 78 ExtensionService* service = |
78 extensions::ExtensionSystem::Get(profile)->extension_service(); | 79 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 80 extensions::ExtensionRegistry* registry = |
| 81 extensions::ExtensionRegistry::Get(profile); |
79 service->set_show_extensions_prompts(false); | 82 service->set_show_extensions_prompts(false); |
80 size_t num_before = service->extensions()->size(); | 83 size_t num_before = registry->enabled_extensions().size(); |
81 { | 84 { |
82 scoped_ptr<ExtensionInstallPrompt> install_ui; | 85 scoped_ptr<ExtensionInstallPrompt> install_ui; |
83 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( | 86 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( |
84 browser()->tab_strip_model()->GetActiveWebContents())); | 87 browser()->tab_strip_model()->GetActiveWebContents())); |
85 | 88 |
86 base::FilePath crx_path = path; | 89 base::FilePath crx_path = path; |
87 DCHECK(crx_path.Extension() == FILE_PATH_LITERAL(".crx")); | 90 DCHECK(crx_path.Extension() == FILE_PATH_LITERAL(".crx")); |
88 if (crx_path.empty()) | 91 if (crx_path.empty()) |
89 return NULL; | 92 return NULL; |
90 | 93 |
91 scoped_refptr<extensions::CrxInstaller> installer( | 94 scoped_refptr<extensions::CrxInstaller> installer( |
92 extensions::CrxInstaller::Create(service, install_ui.Pass())); | 95 extensions::CrxInstaller::Create(service, install_ui.Pass())); |
93 installer->set_expected_id(std::string()); | 96 installer->set_expected_id(std::string()); |
94 installer->set_is_gallery_install(false); | 97 installer->set_is_gallery_install(false); |
95 installer->set_install_source(extensions::Manifest::INTERNAL); | 98 installer->set_install_source(extensions::Manifest::INTERNAL); |
96 installer->set_install_immediately(true); | 99 installer->set_install_immediately(true); |
97 installer->set_off_store_install_allow_reason( | 100 installer->set_off_store_install_allow_reason( |
98 extensions::CrxInstaller::OffStoreInstallAllowedInTest); | 101 extensions::CrxInstaller::OffStoreInstallAllowedInTest); |
99 | 102 |
100 observer_->Watch( | 103 observer_->Watch( |
101 extensions::NOTIFICATION_CRX_INSTALLER_DONE, | 104 extensions::NOTIFICATION_CRX_INSTALLER_DONE, |
102 content::Source<extensions::CrxInstaller>(installer.get())); | 105 content::Source<extensions::CrxInstaller>(installer.get())); |
103 | 106 |
104 installer->InstallCrx(crx_path); | 107 installer->InstallCrx(crx_path); |
105 | 108 |
106 observer_->Wait(); | 109 observer_->Wait(); |
107 } | 110 } |
108 | 111 |
109 size_t num_after = service->extensions()->size(); | 112 size_t num_after = registry->enabled_extensions().size(); |
110 if (num_before + 1 != num_after) { | 113 if (num_before + 1 != num_after) { |
111 VLOG(1) << "Num extensions before: " << base::IntToString(num_before) | 114 VLOG(1) << "Num extensions before: " << base::IntToString(num_before) |
112 << " num after: " << base::IntToString(num_after) | 115 << " num after: " << base::IntToString(num_after) |
113 << " Installed extensions follow:"; | 116 << " Installed extensions follow:"; |
114 | 117 |
115 for (extensions::ExtensionSet::const_iterator it = | 118 for (const scoped_refptr<const Extension>& extension : |
116 service->extensions()->begin(); | 119 registry->enabled_extensions()) |
117 it != service->extensions()->end(); ++it) | 120 VLOG(1) << " " << extension->id(); |
118 VLOG(1) << " " << (*it)->id(); | |
119 | 121 |
120 VLOG(1) << "Errors follow:"; | 122 VLOG(1) << "Errors follow:"; |
121 const std::vector<base::string16>* errors = | 123 const std::vector<base::string16>* errors = |
122 ExtensionErrorReporter::GetInstance()->GetErrors(); | 124 ExtensionErrorReporter::GetInstance()->GetErrors(); |
123 for (std::vector<base::string16>::const_iterator iter = errors->begin(); | 125 for (std::vector<base::string16>::const_iterator iter = errors->begin(); |
124 iter != errors->end(); ++iter) | 126 iter != errors->end(); ++iter) |
125 VLOG(1) << *iter; | 127 VLOG(1) << *iter; |
126 | 128 |
127 return NULL; | 129 return NULL; |
128 } | 130 } |
129 | 131 |
130 if (!observer_->WaitForExtensionViewsToLoad()) | 132 if (!observer_->WaitForExtensionViewsToLoad()) |
131 return NULL; | 133 return NULL; |
132 return service->GetExtensionById(last_loaded_extension_id(), false); | 134 return service->GetExtensionById(last_loaded_extension_id(), false); |
133 } | 135 } |
OLD | NEW |