OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extensions/crx_installer.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
6 #include "chrome/browser/extensions/extension_browsertest.h" | 6 #include "chrome/browser/extensions/extension_browsertest.h" |
7 #include "chrome/browser/extensions/extension_install_ui.h" | 7 #include "chrome/browser/extensions/extension_install_ui.h" |
8 #include "chrome/browser/extensions/extensions_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/test/ui_test_utils.h" | 11 #include "chrome/test/ui_test_utils.h" |
12 | 12 |
13 class SkBitmap; | 13 class SkBitmap; |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class MockInstallUI : public ExtensionInstallUI { | 17 class MockInstallUI : public ExtensionInstallUI { |
18 public: | 18 public: |
(...skipping 22 matching lines...) Expand all Loading... |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { | 44 class ExtensionCrxInstallerTest : public ExtensionBrowserTest { |
45 public: | 45 public: |
46 // Installs a crx from |crx_relpath| (a path relative to the extension test | 46 // Installs a crx from |crx_relpath| (a path relative to the extension test |
47 // data dir) with expected id |id|. Returns whether a confirmation prompt | 47 // data dir) with expected id |id|. Returns whether a confirmation prompt |
48 // happened or not. | 48 // happened or not. |
49 bool DidWhitelistInstallPrompt(const std::string& crx_relpath, | 49 bool DidWhitelistInstallPrompt(const std::string& crx_relpath, |
50 const std::string& id) { | 50 const std::string& id) { |
51 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 51 ExtensionService* service = browser()->profile()->GetExtensionService(); |
52 MockInstallUI* mock_install_ui = new MockInstallUI(browser()->profile()); | 52 MockInstallUI* mock_install_ui = new MockInstallUI(browser()->profile()); |
53 | 53 |
54 scoped_refptr<CrxInstaller> installer( | 54 scoped_refptr<CrxInstaller> installer( |
55 new CrxInstaller(service, mock_install_ui /* ownership transferred */)); | 55 new CrxInstaller(service, mock_install_ui /* ownership transferred */)); |
56 | 56 |
57 installer->set_allow_silent_install(true); | 57 installer->set_allow_silent_install(true); |
58 installer->set_is_gallery_install(true); | 58 installer->set_is_gallery_install(true); |
59 CrxInstaller::SetWhitelistedInstallId(id); | 59 CrxInstaller::SetWhitelistedInstallId(id); |
60 | 60 |
61 FilePath crx_path = test_data_dir_.AppendASCII(crx_relpath); | 61 FilePath crx_path = test_data_dir_.AppendASCII(crx_relpath); |
62 installer->InstallCrx(crx_path); | 62 installer->InstallCrx(crx_path); |
63 ui_test_utils::RunMessageLoop(); | 63 ui_test_utils::RunMessageLoop(); |
64 | 64 |
65 return mock_install_ui->confirmation_requested(); | 65 return mock_install_ui->confirmation_requested(); |
66 } | 66 } |
67 }; | 67 }; |
68 | 68 |
69 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) { | 69 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) { |
70 // A regular extension should give no prompt. | 70 // A regular extension should give no prompt. |
71 EXPECT_FALSE(DidWhitelistInstallPrompt("good.crx", | 71 EXPECT_FALSE(DidWhitelistInstallPrompt("good.crx", |
72 "ldnnhddmnhbkjipkidpdiheffobcpfmf")); | 72 "ldnnhddmnhbkjipkidpdiheffobcpfmf")); |
73 #if !defined(OS_CHROMEOS) | 73 #if !defined(OS_CHROMEOS) |
74 // An extension with NPAPI should give a prompt. | 74 // An extension with NPAPI should give a prompt. |
75 EXPECT_TRUE(DidWhitelistInstallPrompt("uitest/plugins.crx", | 75 EXPECT_TRUE(DidWhitelistInstallPrompt("uitest/plugins.crx", |
76 "hdgllgikmikobbofgnabhfimcfoopgnd")); | 76 "hdgllgikmikobbofgnabhfimcfoopgnd")); |
77 #endif // !defined(OS_CHROMEOS) | 77 #endif // !defined(OS_CHROMEOS) |
78 } | 78 } |
OLD | NEW |