Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_settings_browsertest.cc

Issue 916243002: Enable keyboard shortcuts for chrome://extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix license comment and Rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_registry.h"
28 #include "extensions/browser/extension_system.h" 28 #include "extensions/browser/extension_system.h"
29 #include "extensions/browser/test_extension_registry_observer.h"
29 #include "extensions/common/extension_set.h" 30 #include "extensions/common/extension_set.h"
30 31
31 using extensions::Extension; 32 using extensions::Extension;
32 using extensions::TestManagementPolicyProvider; 33 using extensions::TestManagementPolicyProvider;
33 34
34 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() 35 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest()
35 : profile_(NULL), 36 : profile_(NULL),
36 policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS | 37 policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS |
37 TestManagementPolicyProvider::MUST_REMAIN_ENABLED | 38 TestManagementPolicyProvider::MUST_REMAIN_ENABLED |
38 TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) {} 39 TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) {}
(...skipping 13 matching lines...) Expand all
52 observer_.reset(new ExtensionTestNotificationObserver(browser())); 53 observer_.reset(new ExtensionTestNotificationObserver(browser()));
53 } 54 }
54 55
55 void ExtensionSettingsUIBrowserTest::InstallGoodExtension() { 56 void ExtensionSettingsUIBrowserTest::InstallGoodExtension() {
56 base::FilePath test_data_dir; 57 base::FilePath test_data_dir;
57 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) { 58 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
58 ADD_FAILURE(); 59 ADD_FAILURE();
59 return; 60 return;
60 } 61 }
61 base::FilePath extensions_data_dir = test_data_dir.AppendASCII("extensions"); 62 base::FilePath extensions_data_dir = test_data_dir.AppendASCII("extensions");
62 InstallExtension(extensions_data_dir.AppendASCII("good.crx")); 63 EXPECT_TRUE(InstallExtension(extensions_data_dir.AppendASCII("good.crx")));
64 }
65
66 void ExtensionSettingsUIBrowserTest::InstallErrorsExtension() {
67 base::FilePath test_data_dir;
68 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
69 ADD_FAILURE();
70 return;
71 }
72 base::FilePath extensions_data_dir = test_data_dir.AppendASCII("extensions");
73 extensions_data_dir = extensions_data_dir.AppendASCII("error_console");
74 EXPECT_TRUE(InstallUnpackedExtension(
75 extensions_data_dir.AppendASCII("runtime_and_manifest_errors"),
76 "pdlpifnclfacjobnmbpngemkalkjamnf"));
63 } 77 }
64 78
65 void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() { 79 void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() {
66 auto* extension_service = extensions::ExtensionSystem::Get(GetProfile()); 80 auto* extension_service = extensions::ExtensionSystem::Get(GetProfile());
67 extension_service->management_policy()->RegisterProvider(&policy_provider_); 81 extension_service->management_policy()->RegisterProvider(&policy_provider_);
68 } 82 }
69 83
70 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { 84 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt {
71 public: 85 public:
72 explicit MockAutoConfirmExtensionInstallPrompt( 86 explicit MockAutoConfirmExtensionInstallPrompt(
73 content::WebContents* web_contents) 87 content::WebContents* web_contents)
74 : ExtensionInstallPrompt(web_contents) {} 88 : ExtensionInstallPrompt(web_contents) {}
75 89
76 // Proceed without confirmation prompt. 90 // Proceed without confirmation prompt.
77 void ConfirmInstall(Delegate* delegate, 91 void ConfirmInstall(Delegate* delegate,
78 const Extension* extension, 92 const Extension* extension,
79 const ShowDialogCallback& show_dialog_callback) override { 93 const ShowDialogCallback& show_dialog_callback) override {
80 delegate->InstallUIProceed(); 94 delegate->InstallUIProceed();
81 } 95 }
82 }; 96 };
83 97
98 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension(
99 const base::FilePath& path, const char* id) {
100 if (path.empty())
101 return NULL;
102
103 Profile* profile = GetProfile();
104 ExtensionService* service =
105 extensions::ExtensionSystem::Get(profile)->extension_service();
106 service->set_show_extensions_prompts(false);
107 extensions::ExtensionRegistry* registry =
108 extensions::ExtensionRegistry::Get(profile);
109 extensions::TestExtensionRegistryObserver observer(registry, id);
110
111 extensions::UnpackedInstaller::Create(service)->Load(path);
112
113 // Test will timeout if extension is not loaded.
114 observer.WaitForExtensionLoaded();
115 return service->GetExtensionById(last_loaded_extension_id(), false);
116 }
117
84 const Extension* ExtensionSettingsUIBrowserTest::InstallExtension( 118 const Extension* ExtensionSettingsUIBrowserTest::InstallExtension(
85 const base::FilePath& path) { 119 const base::FilePath& path) {
86 Profile* profile = this->GetProfile(); 120 Profile* profile = GetProfile();
87 ExtensionService* service = 121 ExtensionService* service =
88 extensions::ExtensionSystem::Get(profile)->extension_service(); 122 extensions::ExtensionSystem::Get(profile)->extension_service();
89 extensions::ExtensionRegistry* registry = 123 extensions::ExtensionRegistry* registry =
90 extensions::ExtensionRegistry::Get(profile); 124 extensions::ExtensionRegistry::Get(profile);
91 service->set_show_extensions_prompts(false); 125 service->set_show_extensions_prompts(false);
92 size_t num_before = registry->enabled_extensions().size(); 126 size_t num_before = registry->enabled_extensions().size();
93 { 127 {
94 scoped_ptr<ExtensionInstallPrompt> install_ui; 128 scoped_ptr<ExtensionInstallPrompt> install_ui;
95 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( 129 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt(
96 browser()->tab_strip_model()->GetActiveWebContents())); 130 browser()->tab_strip_model()->GetActiveWebContents()));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 iter != errors->end(); ++iter) 169 iter != errors->end(); ++iter)
136 VLOG(1) << *iter; 170 VLOG(1) << *iter;
137 171
138 return NULL; 172 return NULL;
139 } 173 }
140 174
141 if (!observer_->WaitForExtensionViewsToLoad()) 175 if (!observer_->WaitForExtensionViewsToLoad())
142 return NULL; 176 return NULL;
143 return service->GetExtensionById(last_loaded_extension_id(), false); 177 return service->GetExtensionById(last_loaded_extension_id(), false);
144 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698