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 <map> | 5 #include <map> |
6 | 6 |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
10 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
11 #include "chrome/browser/extensions/test_management_policy.h" | 11 #include "chrome/browser/extensions/test_management_policy.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_commands.h" | 14 #include "chrome/browser/ui/browser_commands.h" |
15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/extensions/manifest.h" | |
19 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
20 | 21 |
21 using extensions::Extension; | 22 using extensions::Extension; |
23 using extensions::Manifest; | |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // Find a browser other than |browser|. | 27 // Find a browser other than |browser|. |
26 Browser* FindOtherBrowser(Browser* browser) { | 28 Browser* FindOtherBrowser(Browser* browser) { |
27 Browser* found = NULL; | 29 Browser* found = NULL; |
28 for (BrowserList::const_iterator it = BrowserList::begin(); | 30 for (BrowserList::const_iterator it = BrowserList::begin(); |
29 it != BrowserList::end(); ++it) { | 31 it != BrowserList::end(); ++it) { |
30 if (*it == browser) | 32 if (*it == browser) |
31 continue; | 33 continue; |
32 found = *it; | 34 found = *it; |
33 } | 35 } |
34 | 36 |
35 return found; | 37 return found; |
36 } | 38 } |
37 | 39 |
38 } // namespace | 40 } // namespace |
39 | 41 |
40 class ExtensionManagementApiTest : public ExtensionApiTest { | 42 class ExtensionManagementApiTest : public ExtensionApiTest { |
41 public: | 43 public: |
42 virtual void SetUpCommandLine(CommandLine* command_line) { | 44 virtual void SetUpCommandLine(CommandLine* command_line) { |
43 ExtensionApiTest::SetUpCommandLine(command_line); | 45 ExtensionApiTest::SetUpCommandLine(command_line); |
44 command_line->AppendSwitch(switches::kEnablePanels); | 46 command_line->AppendSwitch(switches::kEnablePanels); |
45 } | 47 } |
46 | 48 |
47 virtual void InstallExtensions() { | 49 virtual void LoadExtensions() { |
48 FilePath basedir = test_data_dir_.AppendASCII("management"); | 50 FilePath basedir = test_data_dir_.AppendASCII("management"); |
49 | 51 |
50 // Load 4 enabled items. | 52 // Load 4 enabled items. |
51 InstallNamedExtension(basedir, "enabled_extension"); | 53 InstallNamedExtension(basedir, "enabled_extension"); |
52 InstallNamedExtension(basedir, "enabled_app"); | 54 InstallNamedExtension(basedir, "enabled_app"); |
53 InstallNamedExtension(basedir, "description"); | 55 InstallNamedExtension(basedir, "description"); |
54 InstallNamedExtension(basedir, "permissions"); | 56 InstallNamedExtension(basedir, "permissions"); |
55 | 57 |
56 // Load 2 disabled items. | 58 // Load 2 disabled items. |
57 InstallNamedExtension(basedir, "disabled_extension"); | 59 InstallNamedExtension(basedir, "disabled_extension"); |
58 DisableExtension(extension_ids_["disabled_extension"]); | 60 DisableExtension(extension_ids_["disabled_extension"]); |
59 InstallNamedExtension(basedir, "disabled_app"); | 61 InstallNamedExtension(basedir, "disabled_app"); |
60 DisableExtension(extension_ids_["disabled_app"]); | 62 DisableExtension(extension_ids_["disabled_app"]); |
61 } | 63 } |
62 | 64 |
63 // Load an app, and wait for a message from app "management/launch_on_install" | 65 // Load an app, and wait for a message from app "management/launch_on_install" |
64 // indicating that the new app has been launched. | 66 // indicating that the new app has been launched. |
65 void LoadAndWaitForLaunch(const std::string& app_path, | 67 void LoadAndWaitForLaunch(const std::string& app_path, |
66 std::string* out_app_id) { | 68 std::string* out_app_id) { |
67 ExtensionTestMessageListener launched_app("launched app", false); | 69 ExtensionTestMessageListener launched_app("launched app", false); |
68 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(app_path))); | 70 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(app_path))); |
69 | 71 |
70 if (out_app_id) | 72 if (out_app_id) |
71 *out_app_id = last_loaded_extension_id_; | 73 *out_app_id = last_loaded_extension_id_; |
72 | 74 |
73 ASSERT_TRUE(launched_app.WaitUntilSatisfied()); | 75 ASSERT_TRUE(launched_app.WaitUntilSatisfied()); |
74 } | 76 } |
75 | 77 |
76 protected: | 78 protected: |
77 void InstallNamedExtension(FilePath basedir, std::string name) { | 79 Extension* InstallNamedExtension(const FilePath& path, |
78 const Extension* extension = LoadExtension(basedir.AppendASCII(name)); | 80 const std::string& name) { |
79 ASSERT_TRUE(extension); | 81 const Extension* extension = LoadExtension(path.AppendASCII(name)); |
82 //ASSERT_TRUE(extension); | |
asargent_no_longer_on_chrome
2012/07/31 19:55:53
nit: you should leave this check in, but you can c
mitchellwrosen
2012/07/31 21:48:48
Sorry, forgot to un-comment this line. I was getti
asargent_no_longer_on_chrome
2012/07/31 22:33:00
yeah, ASSERT_TRUE(expr) compiles to something like
| |
80 extension_ids_[name] = extension->id(); | 83 extension_ids_[name] = extension->id(); |
84 return const_cast<Extension*>(extension); | |
81 } | 85 } |
82 | 86 |
83 // Maps installed extension names to their IDs.. | 87 // Maps installed extension names to their IDs. |
84 std::map<std::string, std::string> extension_ids_; | 88 std::map<std::string, std::string> extension_ids_; |
85 }; | 89 }; |
86 | 90 |
87 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Basics) { | 91 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Basics) { |
88 InstallExtensions(); | 92 LoadExtensions(); |
93 | |
94 FilePath basedir = test_data_dir_.AppendASCII("management"); | |
95 Extension* extension = InstallNamedExtension(basedir, "internal_extension"); | |
96 Manifest* manifest = const_cast<Manifest*>(extension->manifest()); | |
97 manifest->location_ = Extension::INTERNAL; | |
asargent_no_longer_on_chrome
2012/07/31 19:55:53
Instead of removing the const and relying on frien
mitchellwrosen
2012/07/31 21:48:48
Sure, but I'm not seeing any way to modify the ext
asargent_no_longer_on_chrome
2012/07/31 22:33:00
Sorry, I didn't think this all the way through. I
| |
98 | |
99 extension = InstallNamedExtension(basedir, "external_extension"); | |
100 manifest = const_cast<Manifest*>(extension->manifest()); | |
101 manifest->location_ = Extension::EXTERNAL_PREF; | |
102 | |
103 extension = InstallNamedExtension(basedir, "admin_extension"); | |
104 manifest = const_cast<Manifest*>(extension->manifest()); | |
105 manifest->location_ = Extension::EXTERNAL_POLICY_DOWNLOAD; | |
106 | |
89 ASSERT_TRUE(RunExtensionSubtest("management/test", "basics.html")); | 107 ASSERT_TRUE(RunExtensionSubtest("management/test", "basics.html")); |
90 } | 108 } |
91 | 109 |
92 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Uninstall) { | 110 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Uninstall) { |
93 InstallExtensions(); | 111 LoadExtensions(); |
94 ASSERT_TRUE(RunExtensionSubtest("management/test", "uninstall.html")); | 112 ASSERT_TRUE(RunExtensionSubtest("management/test", "uninstall.html")); |
95 } | 113 } |
96 | 114 |
97 // Tests actions on extensions when no management policy is in place. | 115 // Tests actions on extensions when no management policy is in place. |
98 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, ManagementPolicyAllowed) { | 116 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, ManagementPolicyAllowed) { |
99 InstallExtensions(); | 117 LoadExtensions(); |
100 ExtensionService* service = browser()->profile()->GetExtensionService(); | 118 ExtensionService* service = browser()->profile()->GetExtensionService(); |
101 EXPECT_TRUE(service->GetExtensionById(extension_ids_["enabled_extension"], | 119 EXPECT_TRUE(service->GetExtensionById(extension_ids_["enabled_extension"], |
102 false)); | 120 false)); |
103 | 121 |
104 // Ensure that all actions are allowed. | 122 // Ensure that all actions are allowed. |
105 extensions::ExtensionSystem::Get( | 123 extensions::ExtensionSystem::Get( |
106 browser()->profile())->management_policy()->UnregisterAllProviders(); | 124 browser()->profile())->management_policy()->UnregisterAllProviders(); |
107 | 125 |
108 ASSERT_TRUE(RunExtensionSubtest("management/management_policy", | 126 ASSERT_TRUE(RunExtensionSubtest("management/management_policy", |
109 "allowed.html")); | 127 "allowed.html")); |
110 // The last thing the test does is uninstall the "enabled_extension". | 128 // The last thing the test does is uninstall the "enabled_extension". |
111 EXPECT_FALSE(service->GetExtensionById(extension_ids_["enabled_extension"], | 129 EXPECT_FALSE(service->GetExtensionById(extension_ids_["enabled_extension"], |
112 true)); | 130 true)); |
113 } | 131 } |
114 | 132 |
115 // Tests actions on extensions when management policy prohibits those actions. | 133 // Tests actions on extensions when management policy prohibits those actions. |
116 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, ManagementPolicyProhibited) { | 134 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, ManagementPolicyProhibited) { |
117 InstallExtensions(); | 135 LoadExtensions(); |
118 ExtensionService* service = browser()->profile()->GetExtensionService(); | 136 ExtensionService* service = browser()->profile()->GetExtensionService(); |
119 EXPECT_TRUE(service->GetExtensionById(extension_ids_["enabled_extension"], | 137 EXPECT_TRUE(service->GetExtensionById(extension_ids_["enabled_extension"], |
120 false)); | 138 false)); |
121 | 139 |
122 // Prohibit status changes. | 140 // Prohibit status changes. |
123 extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get( | 141 extensions::ManagementPolicy* policy = extensions::ExtensionSystem::Get( |
124 browser()->profile())->management_policy(); | 142 browser()->profile())->management_policy(); |
125 policy->UnregisterAllProviders(); | 143 policy->UnregisterAllProviders(); |
126 extensions::TestManagementPolicyProvider provider( | 144 extensions::TestManagementPolicyProvider provider( |
127 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); | 145 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 ASSERT_EQ(2, browser()->tab_count()); | 250 ASSERT_EQ(2, browser()->tab_count()); |
233 #else | 251 #else |
234 // Find the app's browser. Opening in a new window will create | 252 // Find the app's browser. Opening in a new window will create |
235 // a new browser. | 253 // a new browser. |
236 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); | 254 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); |
237 Browser* app_browser = FindOtherBrowser(browser()); | 255 Browser* app_browser = FindOtherBrowser(browser()); |
238 ASSERT_TRUE(app_browser->is_app()); | 256 ASSERT_TRUE(app_browser->is_app()); |
239 ASSERT_FALSE(app_browser->is_type_panel()); | 257 ASSERT_FALSE(app_browser->is_type_panel()); |
240 #endif | 258 #endif |
241 } | 259 } |
OLD | NEW |