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 "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" |
21 #include "chrome/test/base/testing_profile.h" | |
20 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
21 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
22 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
25 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
26 #include "extensions/browser/extension_host.h" | 28 #include "extensions/browser/extension_host.h" |
27 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
30 #include "extensions/browser/extension_registry_observer.h" | |
28 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
29 #include "extensions/common/extension_builder.h" | 32 #include "extensions/common/extension_builder.h" |
30 #include "extensions/common/value_builder.h" | 33 #include "extensions/common/value_builder.h" |
31 #include "net/dns/mock_host_resolver.h" | 34 #include "net/dns/mock_host_resolver.h" |
32 #include "url/gurl.h" | 35 #include "url/gurl.h" |
33 | 36 |
34 using content::WebContents; | 37 using content::WebContents; |
35 using extensions::DictionaryBuilder; | 38 using extensions::DictionaryBuilder; |
36 using extensions::Extension; | 39 using extensions::Extension; |
37 using extensions::ExtensionBuilder; | 40 using extensions::ExtensionBuilder; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 WebstoreStartupInstallUnpackFailureTest) { | 232 WebstoreStartupInstallUnpackFailureTest) { |
230 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 233 ExtensionInstallPrompt::g_auto_confirm_for_tests = |
231 ExtensionInstallPrompt::ACCEPT; | 234 ExtensionInstallPrompt::ACCEPT; |
232 | 235 |
233 ui_test_utils::NavigateToURL(browser(), | 236 ui_test_utils::NavigateToURL(browser(), |
234 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); | 237 GenerateTestServerUrl(kAppDomain, "install_unpack_failure.html")); |
235 | 238 |
236 RunTest("runTest"); | 239 RunTest("runTest"); |
237 } | 240 } |
238 | 241 |
239 class CommandLineWebstoreInstall : public WebstoreStartupInstallerTest, | 242 class CommandLineWebstoreInstall |
240 public content::NotificationObserver { | 243 : public WebstoreStartupInstallerTest, |
244 public content::NotificationObserver, | |
245 public extensions::ExtensionRegistryObserver { | |
241 public: | 246 public: |
242 CommandLineWebstoreInstall() : saw_install_(false), browser_open_count_(0) {} | 247 CommandLineWebstoreInstall() |
248 : extensions_registry_observer_(this), | |
249 saw_install_(false), | |
250 browser_open_count_(0) {} | |
243 virtual ~CommandLineWebstoreInstall() {} | 251 virtual ~CommandLineWebstoreInstall() {} |
244 | 252 |
245 virtual void SetUpOnMainThread() OVERRIDE { | 253 virtual void SetUpOnMainThread() OVERRIDE { |
246 WebstoreStartupInstallerTest::SetUpOnMainThread(); | 254 WebstoreStartupInstallerTest::SetUpOnMainThread(); |
247 registrar_.Add( | 255 extensions_registry_observer_.Add( |
248 this, | 256 extensions::ExtensionRegistry::Get(&profile_)); |
249 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, | |
250 content::NotificationService::AllSources()); | |
251 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, | 257 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, |
252 content::NotificationService::AllSources()); | 258 content::NotificationService::AllSources()); |
253 } | 259 } |
254 | 260 |
255 bool saw_install() { return saw_install_; } | 261 bool saw_install() { return saw_install_; } |
256 | 262 |
257 int browser_open_count() { return browser_open_count_; } | 263 int browser_open_count() { return browser_open_count_; } |
258 | 264 |
259 // NotificationObserver interface. | 265 // NotificationObserver interface. |
260 virtual void Observe(int type, | 266 virtual void Observe(int type, |
261 const content::NotificationSource& source, | 267 const content::NotificationSource& source, |
262 const content::NotificationDetails& details) OVERRIDE { | 268 const content::NotificationDetails& details) OVERRIDE { |
263 if (type == | 269 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSER_OPENED) |
264 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED) { | 270 << "Unexpected notification type : " << type; |
not at google - send to devlin
2014/07/31 17:24:58
eh who cares about the message
limasdf
2014/07/31 17:31:49
Done. Removed printing message.
| |
265 const Extension* extension = | 271 browser_open_count_++; |
not at google - send to devlin
2014/07/31 17:24:58
++brower_open_count_;
limasdf
2014/07/31 17:31:49
Done.
| |
266 content::Details<const extensions::InstalledExtensionInfo>(details)-> | 272 } |
267 extension; | 273 |
268 ASSERT_TRUE(extension != NULL); | 274 virtual void OnExtensionWillBeInstalled( |
269 EXPECT_EQ(extension->id(), kTestExtensionId); | 275 content::BrowserContext* browser_context, |
270 saw_install_ = true; | 276 const extensions::Extension* extension, |
271 } else if (type == chrome::NOTIFICATION_BROWSER_OPENED) { | 277 bool is_update, |
272 browser_open_count_++; | 278 bool from_ephemeral, |
273 } else { | 279 const std::string& old_name) OVERRIDE { |
274 ASSERT_TRUE(false) << "Unexpected notification type : " << type; | 280 EXPECT_EQ(extension->id(), kTestExtensionId); |
275 } | 281 saw_install_ = true; |
276 } | 282 } |
277 | 283 |
278 content::NotificationRegistrar registrar_; | 284 content::NotificationRegistrar registrar_; |
279 | 285 |
286 ScopedObserver<extensions::ExtensionRegistry, | |
287 extensions::ExtensionRegistryObserver> | |
288 extensions_registry_observer_; | |
289 | |
290 TestingProfile profile_; | |
291 | |
280 // Have we seen an installation notification for kTestExtensionId ? | 292 // Have we seen an installation notification for kTestExtensionId ? |
281 bool saw_install_; | 293 bool saw_install_; |
282 | 294 |
283 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? | 295 // How many NOTIFICATION_BROWSER_OPENED notifications have we seen? |
284 int browser_open_count_; | 296 int browser_open_count_; |
285 }; | 297 }; |
286 | 298 |
287 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) { | 299 IN_PROC_BROWSER_TEST_F(CommandLineWebstoreInstall, Accept) { |
288 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 300 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
289 command_line->AppendSwitchASCII( | 301 command_line->AppendSwitchASCII( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 341 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
330 command_line->AppendSwitchASCII( | 342 command_line->AppendSwitchASCII( |
331 switches::kLimitedInstallFromWebstore, "2"); | 343 switches::kLimitedInstallFromWebstore, "2"); |
332 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), | 344 helper.LimitedInstallFromWebstore(*command_line, browser()->profile(), |
333 base::MessageLoop::QuitWhenIdleClosure()); | 345 base::MessageLoop::QuitWhenIdleClosure()); |
334 base::MessageLoop::current()->Run(); | 346 base::MessageLoop::current()->Run(); |
335 | 347 |
336 EXPECT_TRUE(saw_install()); | 348 EXPECT_TRUE(saw_install()); |
337 EXPECT_EQ(0, browser_open_count()); | 349 EXPECT_EQ(0, browser_open_count()); |
338 } | 350 } |
OLD | NEW |