| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" | 6 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
| 7 #include "chrome/browser/extensions/extension_function_test_utils.h" | 7 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_service_test_base.h" | 9 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 base::DeleteFile(crx_path, false); | 257 base::DeleteFile(crx_path, false); |
| 258 EXPECT_TRUE(pack_args.Remove(1u, nullptr)); // Remove the pem key argument. | 258 EXPECT_TRUE(pack_args.Remove(1u, nullptr)); // Remove the pem key argument. |
| 259 EXPECT_TRUE(pack_args.Remove(1u, nullptr)); // Remove the flags argument. | 259 EXPECT_TRUE(pack_args.Remove(1u, nullptr)); // Remove the flags argument. |
| 260 EXPECT_TRUE(TestPackExtensionFunction( | 260 EXPECT_TRUE(TestPackExtensionFunction( |
| 261 pack_args, api::developer_private::PACK_STATUS_ERROR, 0)); | 261 pack_args, api::developer_private::PACK_STATUS_ERROR, 0)); |
| 262 | 262 |
| 263 base::DeleteFile(crx_path, false); | 263 base::DeleteFile(crx_path, false); |
| 264 base::DeleteFile(pem_path, false); | 264 base::DeleteFile(pem_path, false); |
| 265 } | 265 } |
| 266 | 266 |
| 267 // Test developerPrivate.requestFileSource. |
| 268 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateRequestFileSource) { |
| 269 ResetThreadBundle(content::TestBrowserThreadBundle::DEFAULT); |
| 270 // Testing of this function seems light, but that's because it basically just |
| 271 // forwards to reading a file to a string, and highlighting it - both of which |
| 272 // are already tested separately. |
| 273 const Extension* extension = LoadUnpackedExtension(); |
| 274 const char kErrorMessage[] = "Something went wrong"; |
| 275 api::developer_private::RequestFileSourceProperties properties; |
| 276 properties.extension_id = extension->id(); |
| 277 properties.path_suffix = "manifest.json"; |
| 278 properties.message = kErrorMessage; |
| 279 properties.manifest_key.reset(new std::string("name")); |
| 280 |
| 281 scoped_refptr<UIThreadExtensionFunction> function( |
| 282 new api::DeveloperPrivateRequestFileSourceFunction()); |
| 283 base::ListValue file_source_args; |
| 284 file_source_args.Append(properties.ToValue().release()); |
| 285 EXPECT_TRUE(RunFunction(function, file_source_args)) << function->GetError(); |
| 286 |
| 287 const base::Value* response_value = nullptr; |
| 288 ASSERT_TRUE(function->GetResultList()->Get(0u, &response_value)); |
| 289 scoped_ptr<api::developer_private::RequestFileSourceResponse> response = |
| 290 api::developer_private::RequestFileSourceResponse::FromValue( |
| 291 *response_value); |
| 292 EXPECT_FALSE(response->before_highlight.empty()); |
| 293 EXPECT_EQ("\"name\": \"foo\"", response->highlight); |
| 294 EXPECT_FALSE(response->after_highlight.empty()); |
| 295 EXPECT_EQ("foo: manifest.json", response->title); |
| 296 EXPECT_EQ(kErrorMessage, response->message); |
| 297 } |
| 298 |
| 267 } // namespace extensions | 299 } // namespace extensions |
| OLD | NEW |