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

Side by Side Diff: chrome/browser/extensions/webstore_startup_installer_browsertest.cc

Issue 437603002: Remove deprecated extension notification from WebstoreStartupInstallerTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: testingprofile -> profile() Created 6 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/scoped_observer.h"
6 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/extensions/extension_install_prompt.h" 8 #include "chrome/browser/extensions/extension_install_prompt.h"
8 #include "chrome/browser/extensions/extension_install_ui.h" 9 #include "chrome/browser/extensions/extension_install_ui.h"
9 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/startup_helper.h" 11 #include "chrome/browser/extensions/startup_helper.h"
11 #include "chrome/browser/extensions/webstore_installer_test.h" 12 #include "chrome/browser/extensions/webstore_installer_test.h"
12 #include "chrome/browser/infobars/infobar_service.h" 13 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/test_switches.h" 20 #include "chrome/test/base/test_switches.h"
20 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
26 #include "extensions/browser/extension_host.h" 27 #include "extensions/browser/extension_host.h"
27 #include "extensions/browser/extension_registry.h" 28 #include "extensions/browser/extension_registry.h"
29 #include "extensions/browser/extension_registry_observer.h"
28 #include "extensions/browser/extension_system.h" 30 #include "extensions/browser/extension_system.h"
29 #include "extensions/common/extension_builder.h" 31 #include "extensions/common/extension_builder.h"
30 #include "extensions/common/value_builder.h" 32 #include "extensions/common/value_builder.h"
31 #include "net/dns/mock_host_resolver.h" 33 #include "net/dns/mock_host_resolver.h"
32 #include "url/gurl.h" 34 #include "url/gurl.h"
33 35
34 using content::WebContents; 36 using content::WebContents;
35 using extensions::DictionaryBuilder; 37 using extensions::DictionaryBuilder;
36 using extensions::Extension; 38 using extensions::Extension;
37 using extensions::ExtensionBuilder; 39 using extensions::ExtensionBuilder;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 WebstoreStartupInstallUnpackFailureTest) { 231 WebstoreStartupInstallUnpackFailureTest) {
230 ExtensionInstallPrompt::g_auto_confirm_for_tests = 232 ExtensionInstallPrompt::g_auto_confirm_for_tests =
231 ExtensionInstallPrompt::ACCEPT; 233 ExtensionInstallPrompt::ACCEPT;
232 234
233 ui_test_utils::NavigateToURL(browser(), 235 ui_test_utils::NavigateToURL(browser(),
234 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); 236 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html"));
235 237
236 RunTest("runTest"); 238 RunTest("runTest");
237 } 239 }
238 240
239 class CommandLineWebstoreInstall : public WebstoreStartupInstallerTest, 241 class CommandLineWebstoreInstall
240 public content::NotificationObserver { 242 : public WebstoreStartupInstallerTest,
243 public content::NotificationObserver,
244 public extensions::ExtensionRegistryObserver {
241 public: 245 public:
242 CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {} 246 CommandLineWebstoreInstall()
247 : extensions_registry_observer_(this),
248 saw_install_(false),
249 browser_open_count_(0) {}
243 virtual ~CommandLineWebstoreInstall() {} 250 virtual ~CommandLineWebstoreInstall() {}
244 251
245 virtual void SetUpOnMainThread() OVERRIDE { 252 virtual void SetUpOnMainThread() OVERRIDE {
246 WebstoreStartupInstallerTest::SetUpOnMainThread(); 253 WebstoreStartupInstallerTest::SetUpOnMainThread();
247 registrar_.Add( 254 extensions_registry_observer_.Add(
248 this, 255 extensions::ExtensionRegistry::Get(browser()->profile()));
249 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
250 content::NotificationService::AllSources());
251 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, 256 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
252 content::NotificationService::AllSources()); 257 content::NotificationService::AllSources());
253 } 258 }
254 259
255 bool saw_install() { return saw_install_; } 260 bool saw_install() { return saw_install_; }
256 261
257 int browser_open_count() { return browser_open_count_; } 262 int browser_open_count() { return browser_open_count_; }
258 263
259 // NotificationObserver interface. 264 // NotificationObserver interface.
260 virtual void Observe(int type, 265 virtual void Observe(int type,
261 const content::NotificationSource& source, 266 const content::NotificationSource& source,
262 const content::NotificationDetails& details) OVERRIDE { 267 const content::NotificationDetails& details) OVERRIDE {
263 if (type == 268 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_OPENED);
264 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED) { 269 ++browser_open_count_;
265 const Extension* extension = 270 }
266 content::Details<const extensions::InstalledExtensionInfo>(details)-> 271
267 extension; 272 virtual void OnExtensionWillBeInstalled(
268 ASSERT_TRUE(extension != NULL); 273 content::BrowserContext* browser_context,
269 EXPECT_EQ(extension->id(), kTestExtensionId); 274 const extensions::Extension* extension,
270 saw_install_ = true; 275 bool is_update,
271 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { 276 bool from_ephemeral,
272 browser_open_count_++; 277 const std::string& old_name) OVERRIDE {
273 } else { 278 EXPECT_EQ(extension->id(), kTestExtensionId);
274 ASSERT_TRUE(false) << "Unexpected notification type : " << type; 279 saw_install_ = true;
275 }
276 } 280 }
277 281
278 content::NotificationRegistrar registrar_; 282 content::NotificationRegistrar registrar_;
279 283
284 ScopedObserver<extensions::ExtensionRegistry,
285 extensions::ExtensionRegistryObserver>
286 extensions_registry_observer_;
287
280 // Have we seen an installation notification for kTestExtensionId ? 288 // Have we seen an installation notification for kTestExtensionId ?
281 bool saw_install_; 289 bool saw_install_;
282 290
283 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? 291 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen?
284 int browser_open_count_; 292 int browser_open_count_;
285 }; 293 };
286 294
287 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) { 295 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) {
288 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 296 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
289 command_line->AppendSwitchASCII( 297 command_line->AppendSwitchASCII(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 337 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
330 command_line->AppendSwitchASCII( 338 command_line->AppendSwitchASCII(
331 switches::kLimitedInstallFromWebstore, "2"); 339 switches::kLimitedInstallFromWebstore, "2");
332 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), 340 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(),
333 base::MessageLoop::QuitWhenIdleClosure()); 341 base::MessageLoop::QuitWhenIdleClosure());
334 base::MessageLoop::current()->Run(); 342 base::MessageLoop::current()->Run();
335 343
336 EXPECT_TRUE(saw_install()); 344 EXPECT_TRUE(saw_install());
337 EXPECT_EQ(0, browser_open_count()); 345 EXPECT_EQ(0, browser_open_count());
338 } 346 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698