| 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/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/extensions/api/developer_private/inspectable_views_find
er.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
| 12 #include "chrome/browser/extensions/permissions_updater.h" | 13 #include "chrome/browser/extensions/permissions_updater.h" |
| 13 #include "chrome/browser/extensions/test_extension_system.h" | 14 #include "chrome/browser/extensions/test_extension_system.h" |
| 14 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" | 15 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
| 15 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/extensions/api/developer_private.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 17 #include "components/crx_file/id_util.h" | 19 #include "components/crx_file/id_util.h" |
| 18 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
| 19 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
| 20 #include "extensions/browser/management_policy.h" | 22 #include "extensions/browser/management_policy.h" |
| 21 #include "extensions/common/constants.h" | 23 #include "extensions/common/constants.h" |
| 22 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/extension_builder.h" | 25 #include "extensions/common/extension_builder.h" |
| 24 #include "extensions/common/feature_switch.h" | 26 #include "extensions/common/feature_switch.h" |
| 25 #include "extensions/common/value_builder.h" | 27 #include "extensions/common/value_builder.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Execute any pending deletion tasks. | 66 // Execute any pending deletion tasks. |
| 65 message_loop_.RunUntilIdle(); | 67 message_loop_.RunUntilIdle(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 static base::DictionaryValue* DeserializeJSONTestData( | 70 static base::DictionaryValue* DeserializeJSONTestData( |
| 69 const base::FilePath& path, | 71 const base::FilePath& path, |
| 70 std::string *error) { | 72 std::string *error) { |
| 71 base::Value* value; | 73 base::Value* value; |
| 72 | 74 |
| 73 JSONFileValueDeserializer deserializer(path); | 75 JSONFileValueDeserializer deserializer(path); |
| 74 value = deserializer.Deserialize(NULL, error); | 76 value = deserializer.Deserialize(nullptr, error); |
| 75 | 77 |
| 76 return static_cast<base::DictionaryValue*>(value); | 78 return static_cast<base::DictionaryValue*>(value); |
| 77 } | 79 } |
| 78 | 80 |
| 79 const scoped_refptr<const Extension> CreateExtension( | 81 const scoped_refptr<const Extension> CreateExtension( |
| 80 const std::string& name, | 82 const std::string& name, |
| 81 ListBuilder& permissions) { | 83 ListBuilder& permissions) { |
| 82 const std::string kId = crx_file::id_util::GenerateId(name); | 84 const std::string kId = crx_file::id_util::GenerateId(name); |
| 83 scoped_refptr<const Extension> extension = | 85 scoped_refptr<const Extension> extension = |
| 84 ExtensionBuilder().SetManifest( | 86 ExtensionBuilder().SetManifest( |
| 85 DictionaryBuilder() | 87 DictionaryBuilder() |
| 86 .Set("name", name) | 88 .Set("name", name) |
| 87 .Set("description", "an extension") | 89 .Set("description", "an extension") |
| 88 .Set("manifest_version", 2) | 90 .Set("manifest_version", 2) |
| 89 .Set("version", "1.0.0") | 91 .Set("version", "1.0.0") |
| 90 .Set("permissions", permissions)) | 92 .Set("permissions", permissions)) |
| 91 .SetLocation(Manifest::INTERNAL) | 93 .SetLocation(Manifest::INTERNAL) |
| 92 .SetID(kId) | 94 .SetID(kId) |
| 93 .Build(); | 95 .Build(); |
| 94 | 96 |
| 95 ExtensionRegistry::Get(profile())->AddEnabled(extension); | 97 ExtensionRegistry::Get(profile())->AddEnabled(extension); |
| 96 PermissionsUpdater(profile()).InitializePermissions(extension.get()); | 98 PermissionsUpdater(profile()).InitializePermissions(extension.get()); |
| 97 return extension; | 99 return extension; |
| 98 } | 100 } |
| 99 | 101 |
| 100 base::DictionaryValue* CreateExtensionDetailViewFromPath( | 102 base::DictionaryValue* CreateExtensionDetailViewFromPath( |
| 101 const base::FilePath& extension_path, | 103 const base::FilePath& extension_path, |
| 102 const std::vector<ExtensionPage>& pages, | 104 const InspectableViewsFinder::ViewList& views, |
| 103 Manifest::Location location) { | 105 Manifest::Location location) { |
| 104 std::string error; | 106 std::string error; |
| 105 | 107 |
| 106 base::FilePath manifest_path = extension_path.Append(kManifestFilename); | 108 base::FilePath manifest_path = extension_path.Append(kManifestFilename); |
| 107 scoped_ptr<base::DictionaryValue> extension_data(DeserializeJSONTestData( | 109 scoped_ptr<base::DictionaryValue> extension_data(DeserializeJSONTestData( |
| 108 manifest_path, &error)); | 110 manifest_path, &error)); |
| 109 EXPECT_EQ("", error); | 111 EXPECT_EQ("", error); |
| 110 | 112 |
| 111 scoped_refptr<Extension> extension(Extension::Create( | 113 scoped_refptr<Extension> extension(Extension::Create( |
| 112 extension_path, location, *extension_data, Extension::REQUIRE_KEY, | 114 extension_path, location, *extension_data, Extension::REQUIRE_KEY, |
| 113 &error)); | 115 &error)); |
| 114 EXPECT_TRUE(extension.get()); | 116 EXPECT_TRUE(extension.get()); |
| 115 EXPECT_EQ("", error); | 117 EXPECT_EQ("", error); |
| 116 | 118 |
| 117 return handler_->CreateExtensionDetailValue(extension.get(), pages, NULL); | 119 return handler_->CreateExtensionDetailValue( |
| 120 extension.get(), views, nullptr); |
| 118 } | 121 } |
| 119 | 122 |
| 120 void CompareExpectedAndActualOutput( | 123 void CompareExpectedAndActualOutput( |
| 121 const base::FilePath& extension_path, | 124 const base::FilePath& extension_path, |
| 122 const std::vector<ExtensionPage>& pages, | 125 const InspectableViewsFinder::ViewList& views, |
| 123 const base::FilePath& expected_output_path) { | 126 const base::FilePath& expected_output_path) { |
| 124 std::string error; | 127 std::string error; |
| 125 | 128 |
| 126 scoped_ptr<base::DictionaryValue> expected_output_data( | 129 scoped_ptr<base::DictionaryValue> expected_output_data( |
| 127 DeserializeJSONTestData(expected_output_path, &error)); | 130 DeserializeJSONTestData(expected_output_path, &error)); |
| 128 EXPECT_EQ("", error); | 131 EXPECT_EQ("", error); |
| 129 | 132 |
| 130 // Produce test output. | 133 // Produce test output. |
| 131 scoped_ptr<base::DictionaryValue> actual_output_data( | 134 scoped_ptr<base::DictionaryValue> actual_output_data( |
| 132 CreateExtensionDetailViewFromPath( | 135 CreateExtensionDetailViewFromPath( |
| 133 extension_path, pages, Manifest::INVALID_LOCATION)); | 136 extension_path, views, Manifest::INVALID_LOCATION)); |
| 134 | 137 |
| 135 // Compare the outputs. | 138 // Compare the outputs. |
| 136 // Ignore unknown fields in the actual output data. | 139 // Ignore unknown fields in the actual output data. |
| 137 std::string paths_details = " - expected (" + | 140 std::string paths_details = " - expected (" + |
| 138 expected_output_path.MaybeAsASCII() + ") vs. actual (" + | 141 expected_output_path.MaybeAsASCII() + ") vs. actual (" + |
| 139 extension_path.MaybeAsASCII() + ")"; | 142 extension_path.MaybeAsASCII() + ")"; |
| 140 for (base::DictionaryValue::Iterator field(*expected_output_data); | 143 for (base::DictionaryValue::Iterator field(*expected_output_data); |
| 141 !field.IsAtEnd(); field.Advance()) { | 144 !field.IsAtEnd(); field.Advance()) { |
| 142 const base::Value* expected_value = &field.value(); | 145 const base::Value* expected_value = &field.value(); |
| 143 base::Value* actual_value = NULL; | 146 base::Value* actual_value = nullptr; |
| 144 EXPECT_TRUE(actual_output_data->Get(field.key(), &actual_value)) << | 147 EXPECT_TRUE(actual_output_data->Get(field.key(), &actual_value)) << |
| 145 field.key() + " is missing" + paths_details; | 148 field.key() + " is missing" + paths_details; |
| 146 EXPECT_TRUE(expected_value->Equals(actual_value)) << field.key() + | 149 EXPECT_TRUE(expected_value->Equals(actual_value)) << field.key() + |
| 147 paths_details; | 150 paths_details; |
| 148 } | 151 } |
| 149 } | 152 } |
| 150 | 153 |
| 151 Profile* profile() { return profile_.get(); } | 154 Profile* profile() { return profile_.get(); } |
| 152 ExtensionSettingsHandler* handler() { return handler_.get(); } | 155 ExtensionSettingsHandler* handler() { return handler_.get(); } |
| 153 | 156 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 170 base::FilePath data_test_dir_path, extension_path, expected_output_path; | 173 base::FilePath data_test_dir_path, extension_path, expected_output_path; |
| 171 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); | 174 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); |
| 172 | 175 |
| 173 // Test Extension1 | 176 // Test Extension1 |
| 174 extension_path = data_test_dir_path.AppendASCII("extensions") | 177 extension_path = data_test_dir_path.AppendASCII("extensions") |
| 175 .AppendASCII("good") | 178 .AppendASCII("good") |
| 176 .AppendASCII("Extensions") | 179 .AppendASCII("Extensions") |
| 177 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 180 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 178 .AppendASCII("1.0.0.0"); | 181 .AppendASCII("1.0.0.0"); |
| 179 | 182 |
| 180 std::vector<ExtensionPage> pages; | 183 InspectableViewsFinder::ViewList views; |
| 181 pages.push_back(ExtensionPage( | 184 views.push_back(InspectableViewsFinder::ConstructView( |
| 182 GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/bar.html"), | 185 GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/bar.html"), |
| 183 42, 88, false, false)); | 186 42, 88, false, VIEW_TYPE_TAB_CONTENTS)); |
| 184 pages.push_back(ExtensionPage( | 187 views.push_back(InspectableViewsFinder::ConstructView( |
| 185 GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/dog.html"), | 188 GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/dog.html"), |
| 186 0, 0, false, false)); | 189 0, 0, false, VIEW_TYPE_TAB_CONTENTS)); |
| 187 | 190 |
| 188 expected_output_path = data_test_dir_path.AppendASCII("extensions") | 191 expected_output_path = data_test_dir_path.AppendASCII("extensions") |
| 189 .AppendASCII("ui") | 192 .AppendASCII("ui") |
| 190 .AppendASCII("create_extension_detail_value_expected_output") | 193 .AppendASCII("create_extension_detail_value_expected_output") |
| 191 .AppendASCII("good-extension1.json"); | 194 .AppendASCII("good-extension1.json"); |
| 192 | 195 |
| 193 CompareExpectedAndActualOutput(extension_path, pages, expected_output_path); | 196 CompareExpectedAndActualOutput(extension_path, views, expected_output_path); |
| 194 | 197 |
| 195 #if !defined(OS_CHROMEOS) | 198 #if !defined(OS_CHROMEOS) |
| 196 // Test Extension2 | 199 // Test Extension2 |
| 197 extension_path = data_test_dir_path.AppendASCII("extensions") | 200 extension_path = data_test_dir_path.AppendASCII("extensions") |
| 198 .AppendASCII("good") | 201 .AppendASCII("good") |
| 199 .AppendASCII("Extensions") | 202 .AppendASCII("Extensions") |
| 200 .AppendASCII("hpiknbiabeeppbpihjehijgoemciehgk") | 203 .AppendASCII("hpiknbiabeeppbpihjehijgoemciehgk") |
| 201 .AppendASCII("2"); | 204 .AppendASCII("2"); |
| 202 | 205 |
| 203 expected_output_path = data_test_dir_path.AppendASCII("extensions") | 206 expected_output_path = data_test_dir_path.AppendASCII("extensions") |
| 204 .AppendASCII("ui") | 207 .AppendASCII("ui") |
| 205 .AppendASCII("create_extension_detail_value_expected_output") | 208 .AppendASCII("create_extension_detail_value_expected_output") |
| 206 .AppendASCII("good-extension2.json"); | 209 .AppendASCII("good-extension2.json"); |
| 207 | 210 |
| 208 // It's OK to have duplicate URLs, so long as the IDs are different. | 211 // It's OK to have duplicate URLs, so long as the IDs are different. |
| 209 pages[1].url = pages[0].url; | 212 views[0]->url = |
| 213 "chrome-extension://hpiknbiabeeppbpihjehijgoemciehgk/bar.html"; |
| 214 views[1]->url = views[0]->url; |
| 210 | 215 |
| 211 CompareExpectedAndActualOutput(extension_path, pages, expected_output_path); | 216 CompareExpectedAndActualOutput(extension_path, views, expected_output_path); |
| 212 #endif | 217 #endif |
| 213 | 218 |
| 214 // Test Extension3 | 219 // Test Extension3 |
| 215 extension_path = data_test_dir_path.AppendASCII("extensions") | 220 extension_path = data_test_dir_path.AppendASCII("extensions") |
| 216 .AppendASCII("good") | 221 .AppendASCII("good") |
| 217 .AppendASCII("Extensions") | 222 .AppendASCII("Extensions") |
| 218 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") | 223 .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") |
| 219 .AppendASCII("1.0"); | 224 .AppendASCII("1.0"); |
| 220 | 225 |
| 221 expected_output_path = data_test_dir_path.AppendASCII("extensions") | 226 expected_output_path = data_test_dir_path.AppendASCII("extensions") |
| 222 .AppendASCII("ui") | 227 .AppendASCII("ui") |
| 223 .AppendASCII("create_extension_detail_value_expected_output") | 228 .AppendASCII("create_extension_detail_value_expected_output") |
| 224 .AppendASCII("good-extension3.json"); | 229 .AppendASCII("good-extension3.json"); |
| 225 | 230 |
| 226 pages.clear(); | 231 views.clear(); |
| 227 | 232 |
| 228 CompareExpectedAndActualOutput(extension_path, pages, expected_output_path); | 233 CompareExpectedAndActualOutput(extension_path, views, expected_output_path); |
| 229 } | 234 } |
| 230 | 235 |
| 231 // Test that using Manifest::UNPACKED for the extension location triggers the | 236 // Test that using Manifest::UNPACKED for the extension location triggers the |
| 232 // correct values in the details, including location, order, and allow_reload. | 237 // correct values in the details, including location, order, and allow_reload. |
| 233 TEST_F(ExtensionUITest, LocationLoadPropagation) { | 238 TEST_F(ExtensionUITest, LocationLoadPropagation) { |
| 234 base::FilePath data_test_dir_path, extension_path; | 239 base::FilePath data_test_dir_path, extension_path; |
| 235 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); | 240 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); |
| 236 | 241 |
| 237 extension_path = data_test_dir_path.AppendASCII("extensions") | 242 extension_path = data_test_dir_path.AppendASCII("extensions") |
| 238 .AppendASCII("good") | 243 .AppendASCII("good") |
| 239 .AppendASCII("Extensions") | 244 .AppendASCII("Extensions") |
| 240 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 245 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 241 .AppendASCII("1.0.0.0"); | 246 .AppendASCII("1.0.0.0"); |
| 242 | 247 |
| 243 std::vector<ExtensionPage> pages; | 248 InspectableViewsFinder::ViewList views; |
| 244 | 249 |
| 245 scoped_ptr<base::DictionaryValue> extension_details( | 250 scoped_ptr<base::DictionaryValue> extension_details( |
| 246 CreateExtensionDetailViewFromPath( | 251 CreateExtensionDetailViewFromPath( |
| 247 extension_path, pages, Manifest::UNPACKED)); | 252 extension_path, views, Manifest::UNPACKED)); |
| 248 | 253 |
| 249 bool ui_allow_reload = false; | 254 bool ui_allow_reload = false; |
| 250 bool ui_is_unpacked = false; | 255 bool ui_is_unpacked = false; |
| 251 base::FilePath::StringType ui_path; | 256 base::FilePath::StringType ui_path; |
| 252 | 257 |
| 253 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); | 258 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); |
| 254 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); | 259 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); |
| 255 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); | 260 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); |
| 256 EXPECT_EQ(true, ui_allow_reload); | 261 EXPECT_EQ(true, ui_allow_reload); |
| 257 EXPECT_EQ(true, ui_is_unpacked); | 262 EXPECT_EQ(true, ui_is_unpacked); |
| 258 EXPECT_EQ(extension_path, base::FilePath(ui_path)); | 263 EXPECT_EQ(extension_path, base::FilePath(ui_path)); |
| 259 } | 264 } |
| 260 | 265 |
| 261 // Test that using Manifest::EXTERNAL_PREF for the extension location triggers | 266 // Test that using Manifest::EXTERNAL_PREF for the extension location triggers |
| 262 // the correct values in the details, including location, order, and | 267 // the correct values in the details, including location, order, and |
| 263 // allow_reload. Contrast to Manifest::UNPACKED, which has somewhat different | 268 // allow_reload. Contrast to Manifest::UNPACKED, which has somewhat different |
| 264 // values. | 269 // values. |
| 265 TEST_F(ExtensionUITest, LocationExternalPrefPropagation) { | 270 TEST_F(ExtensionUITest, LocationExternalPrefPropagation) { |
| 266 base::FilePath data_test_dir_path, extension_path; | 271 base::FilePath data_test_dir_path, extension_path; |
| 267 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); | 272 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); |
| 268 | 273 |
| 269 extension_path = data_test_dir_path.AppendASCII("extensions") | 274 extension_path = data_test_dir_path.AppendASCII("extensions") |
| 270 .AppendASCII("good") | 275 .AppendASCII("good") |
| 271 .AppendASCII("Extensions") | 276 .AppendASCII("Extensions") |
| 272 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 277 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 273 .AppendASCII("1.0.0.0"); | 278 .AppendASCII("1.0.0.0"); |
| 274 | 279 |
| 275 std::vector<ExtensionPage> pages; | 280 InspectableViewsFinder::ViewList views; |
| 276 | 281 |
| 277 scoped_ptr<base::DictionaryValue> extension_details( | 282 scoped_ptr<base::DictionaryValue> extension_details( |
| 278 CreateExtensionDetailViewFromPath( | 283 CreateExtensionDetailViewFromPath( |
| 279 extension_path, pages, Manifest::EXTERNAL_PREF)); | 284 extension_path, views, Manifest::EXTERNAL_PREF)); |
| 280 | 285 |
| 281 bool ui_allow_reload = true; | 286 bool ui_allow_reload = true; |
| 282 bool ui_is_unpacked = true; | 287 bool ui_is_unpacked = true; |
| 283 base::FilePath::StringType ui_path; | 288 base::FilePath::StringType ui_path; |
| 284 | 289 |
| 285 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); | 290 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); |
| 286 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); | 291 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); |
| 287 EXPECT_FALSE(extension_details->GetString("path", &ui_path)); | 292 EXPECT_FALSE(extension_details->GetString("path", &ui_path)); |
| 288 EXPECT_FALSE(ui_allow_reload); | 293 EXPECT_FALSE(ui_allow_reload); |
| 289 EXPECT_FALSE(ui_is_unpacked); | 294 EXPECT_FALSE(ui_is_unpacked); |
| 290 } | 295 } |
| 291 | 296 |
| 292 // Test that the extension path is correctly propagated into the extension | 297 // Test that the extension path is correctly propagated into the extension |
| 293 // details. | 298 // details. |
| 294 TEST_F(ExtensionUITest, PathPropagation) { | 299 TEST_F(ExtensionUITest, PathPropagation) { |
| 295 base::FilePath data_test_dir_path, extension_path; | 300 base::FilePath data_test_dir_path, extension_path; |
| 296 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); | 301 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); |
| 297 | 302 |
| 298 extension_path = data_test_dir_path.AppendASCII("extensions") | 303 extension_path = data_test_dir_path.AppendASCII("extensions") |
| 299 .AppendASCII("good") | 304 .AppendASCII("good") |
| 300 .AppendASCII("Extensions") | 305 .AppendASCII("Extensions") |
| 301 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 306 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 302 .AppendASCII("1.0.0.0"); | 307 .AppendASCII("1.0.0.0"); |
| 303 | 308 |
| 304 std::vector<ExtensionPage> pages; | 309 InspectableViewsFinder::ViewList views; |
| 305 | 310 |
| 306 scoped_ptr<base::DictionaryValue> extension_details( | 311 scoped_ptr<base::DictionaryValue> extension_details( |
| 307 CreateExtensionDetailViewFromPath( | 312 CreateExtensionDetailViewFromPath( |
| 308 extension_path, pages, Manifest::UNPACKED)); | 313 extension_path, views, Manifest::UNPACKED)); |
| 309 | 314 |
| 310 base::FilePath::StringType ui_path; | 315 base::FilePath::StringType ui_path; |
| 311 | 316 |
| 312 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); | 317 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); |
| 313 EXPECT_EQ(extension_path, base::FilePath(ui_path)); | 318 EXPECT_EQ(extension_path, base::FilePath(ui_path)); |
| 314 } | 319 } |
| 315 | 320 |
| 316 // Test that the all_urls checkbox only shows up for extensions that want all | 321 // Test that the all_urls checkbox only shows up for extensions that want all |
| 317 // urls, and only when the switch is on. | 322 // urls, and only when the switch is on. |
| 318 TEST_F(ExtensionUITest, ExtensionUIAllUrlsCheckbox) { | 323 TEST_F(ExtensionUITest, ExtensionUIAllUrlsCheckbox) { |
| 319 // Start with the switch enabled. | 324 // Start with the switch enabled. |
| 320 scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch( | 325 scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch( |
| 321 new FeatureSwitch::ScopedOverride( | 326 new FeatureSwitch::ScopedOverride( |
| 322 FeatureSwitch::scripts_require_action(), true)); | 327 FeatureSwitch::scripts_require_action(), true)); |
| 323 // Two extensions - one with all urls, one without. | 328 // Two extensions - one with all urls, one without. |
| 324 scoped_refptr<const Extension> all_urls_extension = CreateExtension( | 329 scoped_refptr<const Extension> all_urls_extension = CreateExtension( |
| 325 "all_urls", ListBuilder().Append(kAllHostsPermission).Pass()); | 330 "all_urls", ListBuilder().Append(kAllHostsPermission).Pass()); |
| 326 scoped_refptr<const Extension> no_urls_extension = | 331 scoped_refptr<const Extension> no_urls_extension = |
| 327 CreateExtension("no urls", ListBuilder().Pass()); | 332 CreateExtension("no urls", ListBuilder().Pass()); |
| 328 | 333 |
| 329 scoped_ptr<base::DictionaryValue> value(handler()->CreateExtensionDetailValue( | 334 scoped_ptr<base::DictionaryValue> value(handler()->CreateExtensionDetailValue( |
| 330 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); | 335 all_urls_extension.get(), InspectableViewsFinder::ViewList(), nullptr)); |
| 331 bool result = false; | 336 bool result = false; |
| 332 const std::string kShowAllUrls = "showAllUrls"; | 337 const std::string kShowAllUrls = "showAllUrls"; |
| 333 const std::string kAllowAllUrls = "allowAllUrls"; | 338 const std::string kAllowAllUrls = "allowAllUrls"; |
| 334 | 339 |
| 335 // The extension should want all urls, but not currently have it. | 340 // The extension should want all urls, but not currently have it. |
| 336 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); | 341 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); |
| 337 EXPECT_TRUE(result); | 342 EXPECT_TRUE(result); |
| 338 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 343 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
| 339 EXPECT_FALSE(result); | 344 EXPECT_FALSE(result); |
| 340 | 345 |
| 341 // Give the extension all urls. | 346 // Give the extension all urls. |
| 342 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true); | 347 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true); |
| 343 | 348 |
| 344 // Now the extension should both want and have all urls. | 349 // Now the extension should both want and have all urls. |
| 345 value.reset(handler()->CreateExtensionDetailValue( | 350 value.reset(handler()->CreateExtensionDetailValue( |
| 346 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); | 351 all_urls_extension.get(), InspectableViewsFinder::ViewList(), nullptr)); |
| 347 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); | 352 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); |
| 348 EXPECT_TRUE(result); | 353 EXPECT_TRUE(result); |
| 349 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 354 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
| 350 EXPECT_TRUE(result); | 355 EXPECT_TRUE(result); |
| 351 | 356 |
| 352 // The other extension should neither want nor have all urls. | 357 // The other extension should neither want nor have all urls. |
| 353 value.reset(handler()->CreateExtensionDetailValue( | 358 value.reset(handler()->CreateExtensionDetailValue( |
| 354 no_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); | 359 no_urls_extension.get(), InspectableViewsFinder::ViewList(), nullptr)); |
| 355 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); | 360 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); |
| 356 EXPECT_FALSE(result); | 361 EXPECT_FALSE(result); |
| 357 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 362 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
| 358 EXPECT_FALSE(result); | 363 EXPECT_FALSE(result); |
| 359 | 364 |
| 360 // Revoke the first extension's permissions. | 365 // Revoke the first extension's permissions. |
| 361 util::SetAllowedScriptingOnAllUrls( | 366 util::SetAllowedScriptingOnAllUrls( |
| 362 all_urls_extension->id(), profile(), false); | 367 all_urls_extension->id(), profile(), false); |
| 363 | 368 |
| 364 // Turn off the switch and load another extension (so permissions are | 369 // Turn off the switch and load another extension (so permissions are |
| 365 // re-initialized). | 370 // re-initialized). |
| 366 enable_scripts_switch.reset(); | 371 enable_scripts_switch.reset(); |
| 367 | 372 |
| 368 // Since the extension doesn't have access to all urls (but normally would), | 373 // Since the extension doesn't have access to all urls (but normally would), |
| 369 // the extension should have the "want" flag even with the switch off. | 374 // the extension should have the "want" flag even with the switch off. |
| 370 value.reset(handler()->CreateExtensionDetailValue( | 375 value.reset(handler()->CreateExtensionDetailValue( |
| 371 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); | 376 all_urls_extension.get(), InspectableViewsFinder::ViewList(), nullptr)); |
| 372 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); | 377 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); |
| 373 EXPECT_TRUE(result); | 378 EXPECT_TRUE(result); |
| 374 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 379 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
| 375 EXPECT_FALSE(result); | 380 EXPECT_FALSE(result); |
| 376 | 381 |
| 377 // If we grant the extension all urls, then the checkbox should still be | 382 // If we grant the extension all urls, then the checkbox should still be |
| 378 // there, since it has an explicitly-set user preference. | 383 // there, since it has an explicitly-set user preference. |
| 379 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true); | 384 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true); |
| 380 value.reset(handler()->CreateExtensionDetailValue( | 385 value.reset(handler()->CreateExtensionDetailValue( |
| 381 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); | 386 all_urls_extension.get(), InspectableViewsFinder::ViewList(), nullptr)); |
| 382 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); | 387 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); |
| 383 EXPECT_TRUE(result); | 388 EXPECT_TRUE(result); |
| 384 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 389 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
| 385 EXPECT_TRUE(result); | 390 EXPECT_TRUE(result); |
| 386 | 391 |
| 387 // Load another extension with all urls (so permissions get re-init'd). | 392 // Load another extension with all urls (so permissions get re-init'd). |
| 388 all_urls_extension = CreateExtension( | 393 all_urls_extension = CreateExtension( |
| 389 "all_urls_II", ListBuilder().Append(kAllHostsPermission).Pass()); | 394 "all_urls_II", ListBuilder().Append(kAllHostsPermission).Pass()); |
| 390 | 395 |
| 391 // Even though the extension has all_urls permission, the checkbox shouldn't | 396 // Even though the extension has all_urls permission, the checkbox shouldn't |
| 392 // show up without the switch. | 397 // show up without the switch. |
| 393 value.reset(handler()->CreateExtensionDetailValue( | 398 value.reset(handler()->CreateExtensionDetailValue( |
| 394 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); | 399 all_urls_extension.get(), InspectableViewsFinder::ViewList(), nullptr)); |
| 395 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); | 400 EXPECT_TRUE(value->GetBoolean(kShowAllUrls, &result)); |
| 396 EXPECT_FALSE(result); | 401 EXPECT_FALSE(result); |
| 397 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 402 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
| 398 EXPECT_TRUE(result); | 403 EXPECT_TRUE(result); |
| 399 } | 404 } |
| 400 | 405 |
| 401 } // namespace extensions | 406 } // namespace extensions |
| OLD | NEW |