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/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "chrome/browser/download/download_crx_util.h" | 7 #include "chrome/browser/download/download_crx_util.h" |
8 #include "chrome/browser/extensions/browser_action_test_util.h" | 8 #include "chrome/browser/extensions/browser_action_test_util.h" |
9 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
11 #include "chrome/browser/extensions/extension_install_prompt.h" | 11 #include "chrome/browser/extensions/extension_install_prompt.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_util.h" |
13 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" | 14 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 #include "content/public/browser/download_manager.h" | 21 #include "content/public/browser/download_manager.h" |
21 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
(...skipping 20 matching lines...) Expand all Loading... |
43 namespace extensions { | 44 namespace extensions { |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 class MockInstallPrompt; | 48 class MockInstallPrompt; |
48 | 49 |
49 // This class holds information about things that happen with a | 50 // This class holds information about things that happen with a |
50 // MockInstallPrompt. We create the MockInstallPrompt but need to pass | 51 // MockInstallPrompt. We create the MockInstallPrompt but need to pass |
51 // ownership of it to CrxInstaller, so it isn't safe to hang this data on | 52 // ownership of it to CrxInstaller, so it isn't safe to hang this data on |
52 // MockInstallPrompt itself becuase we can't guarantee it's lifetime. | 53 // MockInstallPrompt itself becuase we can't guarantee it's lifetime. |
53 class MockPromptProxy : | 54 class MockPromptProxy : public base::RefCountedThreadSafe<MockPromptProxy> { |
54 public base::RefCountedThreadSafe<MockPromptProxy> { | |
55 public: | 55 public: |
56 explicit MockPromptProxy(content::WebContents* web_contents); | 56 explicit MockPromptProxy(content::WebContents* web_contents); |
57 | 57 |
58 bool did_succeed() const { return !extension_id_.empty(); } | 58 bool did_succeed() const { return !extension_id_.empty(); } |
59 const std::string& extension_id() { return extension_id_; } | 59 const std::string& extension_id() { return extension_id_; } |
60 bool confirmation_requested() const { return confirmation_requested_; } | 60 bool confirmation_requested() const { return confirmation_requested_; } |
61 const base::string16& error() const { return error_; } | 61 const base::string16& error() const { return error_; } |
62 | 62 |
63 // To have any effect, this should be called before CreatePrompt. | 63 // To have any effect, this should be called before CreatePrompt. |
64 void set_record_oauth2_grant(bool record_oauth2_grant) { | 64 void set_record_oauth2_grant(bool record_oauth2_grant) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 virtual void OnInstallFailure(const CrxInstallerError& error) OVERRIDE { | 110 virtual void OnInstallFailure(const CrxInstallerError& error) OVERRIDE { |
111 proxy_->set_error(error.message()); | 111 proxy_->set_error(error.message()); |
112 base::MessageLoopForUI::current()->Quit(); | 112 base::MessageLoopForUI::current()->Quit(); |
113 } | 113 } |
114 | 114 |
115 private: | 115 private: |
116 scoped_refptr<MockPromptProxy> proxy_; | 116 scoped_refptr<MockPromptProxy> proxy_; |
117 }; | 117 }; |
118 | 118 |
119 | 119 MockPromptProxy::MockPromptProxy(content::WebContents* web_contents) |
120 MockPromptProxy::MockPromptProxy(content::WebContents* web_contents) : | 120 : web_contents_(web_contents), confirmation_requested_(false) { |
121 web_contents_(web_contents), | |
122 confirmation_requested_(false) { | |
123 } | 121 } |
124 | 122 |
125 MockPromptProxy::~MockPromptProxy() {} | 123 MockPromptProxy::~MockPromptProxy() {} |
126 | 124 |
127 scoped_ptr<ExtensionInstallPrompt> MockPromptProxy::CreatePrompt() { | 125 scoped_ptr<ExtensionInstallPrompt> MockPromptProxy::CreatePrompt() { |
128 scoped_ptr<MockInstallPrompt> prompt( | 126 scoped_ptr<MockInstallPrompt> prompt( |
129 new MockInstallPrompt(web_contents_, this)); | 127 new MockInstallPrompt(web_contents_, this)); |
130 if (record_oauth2_grant_.get()) | 128 if (record_oauth2_grant_.get()) |
131 prompt->set_record_oauth2_grant(*record_oauth2_grant_.get()); | 129 prompt->set_record_oauth2_grant(*record_oauth2_grant_.get()); |
132 return prompt.PassAs<ExtensionInstallPrompt>(); | 130 return prompt.PassAs<ExtensionInstallPrompt>(); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), | 357 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), |
360 mock_prompt->error()) << kTestData[i]; | 358 mock_prompt->error()) << kTestData[i]; |
361 } | 359 } |
362 } | 360 } |
363 } | 361 } |
364 | 362 |
365 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) { | 363 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) { |
366 base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx"); | 364 base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx"); |
367 crx_path = crx_path.AppendASCII("theme_hidpi.crx"); | 365 crx_path = crx_path.AppendASCII("theme_hidpi.crx"); |
368 | 366 |
369 ASSERT_TRUE(InstallExtension(crx_path,1)); | 367 ASSERT_TRUE(InstallExtension(crx_path, 1)); |
370 | 368 |
371 const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm"); | 369 const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm"); |
372 ExtensionService* service = extensions::ExtensionSystem::Get( | 370 ExtensionService* service = extensions::ExtensionSystem::Get( |
373 browser()->profile())->extension_service(); | 371 browser()->profile())->extension_service(); |
374 ASSERT_TRUE(service); | 372 ASSERT_TRUE(service); |
375 const extensions::Extension* extension = | 373 const extensions::Extension* extension = |
376 service->GetExtensionById(extension_id, false); | 374 service->GetExtensionById(extension_id, false); |
377 ASSERT_TRUE(extension); | 375 ASSERT_TRUE(extension); |
378 EXPECT_EQ(extension_id, extension->id()); | 376 EXPECT_EQ(extension_id, extension->id()); |
379 | 377 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 419 |
422 // Install version 2 of the extension and check that it is indeed delayed. | 420 // Install version 2 of the extension and check that it is indeed delayed. |
423 ASSERT_TRUE(UpdateExtensionWaitForIdle( | 421 ASSERT_TRUE(UpdateExtensionWaitForIdle( |
424 extension_id, crx_path.AppendASCII("v2.crx"), 0)); | 422 extension_id, crx_path.AppendASCII("v2.crx"), 0)); |
425 | 423 |
426 ASSERT_EQ(1u, service->delayed_installs()->size()); | 424 ASSERT_EQ(1u, service->delayed_installs()->size()); |
427 extension = service->GetExtensionById(extension_id, false); | 425 extension = service->GetExtensionById(extension_id, false); |
428 ASSERT_EQ("1.0", extension->version()->GetString()); | 426 ASSERT_EQ("1.0", extension->version()->GetString()); |
429 | 427 |
430 // Make the extension idle again by closing the popup. This should not trigger | 428 // Make the extension idle again by closing the popup. This should not trigger |
431 //the delayed install. | 429 // the delayed install. |
432 content::RenderProcessHostWatcher terminated_observer( | 430 content::RenderProcessHostWatcher terminated_observer( |
433 extension_host->render_process_host(), | 431 extension_host->render_process_host(), |
434 content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); | 432 content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
435 extension_host->render_view_host()->ClosePage(); | 433 extension_host->render_view_host()->ClosePage(); |
436 terminated_observer.Wait(); | 434 terminated_observer.Wait(); |
437 ASSERT_EQ(1u, service->delayed_installs()->size()); | 435 ASSERT_EQ(1u, service->delayed_installs()->size()); |
438 | 436 |
439 // Install version 3 of the extension. Because the extension is idle, | 437 // Install version 3 of the extension. Because the extension is idle, |
440 // this install should succeed. | 438 // this install should succeed. |
441 ASSERT_TRUE(UpdateExtensionWaitForIdle( | 439 ASSERT_TRUE(UpdateExtensionWaitForIdle( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 // Wait for background task completion that sends replay to UI thread. | 526 // Wait for background task completion that sends replay to UI thread. |
529 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 527 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
530 // Wait for UI thread task completion. | 528 // Wait for UI thread task completion. |
531 base::RunLoop().RunUntilIdle(); | 529 base::RunLoop().RunUntilIdle(); |
532 } | 530 } |
533 | 531 |
534 EXPECT_FALSE(base::PathExists(extension_path)); | 532 EXPECT_FALSE(base::PathExists(extension_path)); |
535 } | 533 } |
536 #endif | 534 #endif |
537 | 535 |
| 536 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotSync) { |
| 537 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 538 browser()->profile())->extension_service(); |
| 539 scoped_refptr<CrxInstaller> crx_installer( |
| 540 CrxInstaller::CreateSilent(service)); |
| 541 crx_installer->set_install_flag(kInstallFlagDoNotSync, true); |
| 542 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); |
| 543 EXPECT_TRUE(WaitForCrxInstallerDone()); |
| 544 ASSERT_TRUE(crx_installer->extension()); |
| 545 |
| 546 const ExtensionPrefs* extension_prefs = |
| 547 ExtensionPrefs::Get(browser()->profile()); |
| 548 EXPECT_TRUE(extension_prefs->DoNotSync(crx_installer->extension()->id())); |
| 549 EXPECT_FALSE(extensions::util::ShouldSyncApp(crx_installer->extension(), |
| 550 browser()->profile())); |
| 551 } |
| 552 |
538 } // namespace extensions | 553 } // namespace extensions |
OLD | NEW |