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

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

Issue 1049483003: [Extensions] Update extensions UI to observe events and add test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Dan's Created 5 years, 8 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/api/management/management_api.h"
27 #include "extensions/browser/extension_registry.h" 28 #include "extensions/browser/extension_registry.h"
28 #include "extensions/browser/extension_system.h" 29 #include "extensions/browser/extension_system.h"
29 #include "extensions/browser/test_extension_registry_observer.h" 30 #include "extensions/browser/test_extension_registry_observer.h"
30 #include "extensions/common/extension_set.h" 31 #include "extensions/common/extension_set.h"
31 32
32 using extensions::Extension; 33 using extensions::Extension;
33 using extensions::TestManagementPolicyProvider; 34 using extensions::TestManagementPolicyProvider;
34 35
35 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() 36 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest()
36 : profile_(NULL), 37 : profile_(NULL),
37 policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS | 38 policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS |
38 TestManagementPolicyProvider::MUST_REMAIN_ENABLED | 39 TestManagementPolicyProvider::MUST_REMAIN_ENABLED |
39 TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) {} 40 TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) {
41 CHECK(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_));
42 test_data_dir_ = test_data_dir_.AppendASCII("extensions");
43 }
40 44
41 ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {} 45 ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {}
42 46
43 Profile* ExtensionSettingsUIBrowserTest::GetProfile() { 47 Profile* ExtensionSettingsUIBrowserTest::GetProfile() {
44 if (!profile_) { 48 if (!profile_) {
45 profile_ = browser() ? browser()->profile() : 49 profile_ = browser() ? browser()->profile() :
46 ProfileManager::GetActiveUserProfile(); 50 ProfileManager::GetActiveUserProfile();
47 } 51 }
48 return profile_; 52 return profile_;
49 } 53 }
50 54
51 void ExtensionSettingsUIBrowserTest::SetUpOnMainThread() { 55 void ExtensionSettingsUIBrowserTest::SetUpOnMainThread() {
52 WebUIBrowserTest::SetUpOnMainThread(); 56 WebUIBrowserTest::SetUpOnMainThread();
53 observer_.reset(new ExtensionTestNotificationObserver(browser())); 57 observer_.reset(new ExtensionTestNotificationObserver(browser()));
54 } 58 }
55 59
56 void ExtensionSettingsUIBrowserTest::InstallGoodExtension() { 60 void ExtensionSettingsUIBrowserTest::InstallGoodExtension() {
57 base::FilePath test_data_dir; 61 EXPECT_TRUE(InstallExtension(test_data_dir_.AppendASCII("good.crx")));
58 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)) {
59 ADD_FAILURE();
60 return;
61 }
62 base::FilePath extensions_data_dir = test_data_dir.AppendASCII("extensions");
63 EXPECT_TRUE(InstallExtension(extensions_data_dir.AppendASCII("good.crx")));
64 } 62 }
65 63
66 void ExtensionSettingsUIBrowserTest::InstallErrorsExtension() { 64 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( 65 EXPECT_TRUE(InstallUnpackedExtension(
75 extensions_data_dir.AppendASCII("runtime_and_manifest_errors"), 66 test_data_dir_.AppendASCII("error_console")
76 "pdlpifnclfacjobnmbpngemkalkjamnf")); 67 .AppendASCII("runtime_and_manifest_errors")));
68 }
69
70 void ExtensionSettingsUIBrowserTest::InstallSharedModule() {
71 base::FilePath shared_module_path =
72 test_data_dir_.AppendASCII("api_test").AppendASCII("shared_module");
73 EXPECT_TRUE(InstallUnpackedExtension(
74 shared_module_path.AppendASCII("shared")));
75 EXPECT_TRUE(InstallUnpackedExtension(
76 shared_module_path.AppendASCII("import_pass")));
77 }
78
79 void ExtensionSettingsUIBrowserTest::InstallPackagedApp() {
80 EXPECT_TRUE(InstallUnpackedExtension(
81 test_data_dir_.AppendASCII("packaged_app")));
77 } 82 }
78 83
79 void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() { 84 void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() {
80 auto* extension_service = extensions::ExtensionSystem::Get(GetProfile()); 85 auto* extension_service = extensions::ExtensionSystem::Get(GetProfile());
81 extension_service->management_policy()->RegisterProvider(&policy_provider_); 86 extension_service->management_policy()->RegisterProvider(&policy_provider_);
82 } 87 }
83 88
89 void ExtensionSettingsUIBrowserTest::SetAutoConfirmUninstall() {
90 extensions::ManagementUninstallFunctionBase::SetAutoConfirmForTest(true);
91 }
92
84 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { 93 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt {
85 public: 94 public:
86 explicit MockAutoConfirmExtensionInstallPrompt( 95 explicit MockAutoConfirmExtensionInstallPrompt(
87 content::WebContents* web_contents) 96 content::WebContents* web_contents)
88 : ExtensionInstallPrompt(web_contents) {} 97 : ExtensionInstallPrompt(web_contents) {}
89 98
90 // Proceed without confirmation prompt. 99 // Proceed without confirmation prompt.
91 void ConfirmInstall(Delegate* delegate, 100 void ConfirmInstall(Delegate* delegate,
92 const Extension* extension, 101 const Extension* extension,
93 const ShowDialogCallback& show_dialog_callback) override { 102 const ShowDialogCallback& show_dialog_callback) override {
94 delegate->InstallUIProceed(); 103 delegate->InstallUIProceed();
95 } 104 }
96 }; 105 };
97 106
98 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( 107 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension(
99 const base::FilePath& path, const char* id) { 108 const base::FilePath& path) {
100 if (path.empty()) 109 if (path.empty())
101 return NULL; 110 return NULL;
102 111
103 Profile* profile = GetProfile(); 112 Profile* profile = GetProfile();
104 ExtensionService* service = 113 ExtensionService* service =
105 extensions::ExtensionSystem::Get(profile)->extension_service(); 114 extensions::ExtensionSystem::Get(profile)->extension_service();
106 service->set_show_extensions_prompts(false); 115 service->set_show_extensions_prompts(false);
107 extensions::ExtensionRegistry* registry = 116 extensions::ExtensionRegistry* registry =
108 extensions::ExtensionRegistry::Get(profile); 117 extensions::ExtensionRegistry::Get(profile);
109 extensions::TestExtensionRegistryObserver observer(registry, id); 118 extensions::TestExtensionRegistryObserver observer(registry);
119 extensions::UnpackedInstaller::Create(service)->Load(path);
120 base::FilePath extension_path = base::MakeAbsoluteFilePath(path);
121 const Extension* extension = nullptr;
122 do {
123 extension = observer.WaitForExtensionLoaded();
124 } while (extension->path() != extension_path);
110 125
111 extensions::UnpackedInstaller::Create(service)->Load(path); 126 return extension;
112
113 // Test will timeout if extension is not loaded.
114 observer.WaitForExtensionLoaded();
115 return service->GetExtensionById(last_loaded_extension_id(), false);
116 } 127 }
117 128
118 const Extension* ExtensionSettingsUIBrowserTest::InstallExtension( 129 const Extension* ExtensionSettingsUIBrowserTest::InstallExtension(
119 const base::FilePath& path) { 130 const base::FilePath& path) {
120 Profile* profile = GetProfile(); 131 Profile* profile = GetProfile();
121 ExtensionService* service = 132 ExtensionService* service =
122 extensions::ExtensionSystem::Get(profile)->extension_service(); 133 extensions::ExtensionSystem::Get(profile)->extension_service();
123 extensions::ExtensionRegistry* registry = 134 extensions::ExtensionRegistry* registry =
124 extensions::ExtensionRegistry::Get(profile); 135 extensions::ExtensionRegistry::Get(profile);
125 service->set_show_extensions_prompts(false); 136 service->set_show_extensions_prompts(false);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 iter != errors->end(); ++iter) 180 iter != errors->end(); ++iter)
170 VLOG(1) << *iter; 181 VLOG(1) << *iter;
171 182
172 return NULL; 183 return NULL;
173 } 184 }
174 185
175 if (!observer_->WaitForExtensionViewsToLoad()) 186 if (!observer_->WaitForExtensionViewsToLoad())
176 return NULL; 187 return NULL;
177 return service->GetExtensionById(last_loaded_extension_id(), false); 188 return service->GetExtensionById(last_loaded_extension_id(), false);
178 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698