Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc

Issue 1947683005: Add test renderer host support to ExtensionServiceTestBase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests that end up creating two RenderViewHostFactories. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_api_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/extensions/api/developer_private/developer_private_api. h" 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/extensions/error_console/error_console.h" 14 #include "chrome/browser/extensions/error_console/error_console.h"
15 #include "chrome/browser/extensions/extension_function_test_utils.h" 15 #include "chrome/browser/extensions/extension_function_test_utils.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_service_test_base.h" 17 #include "chrome/browser/extensions/extension_service_test_base.h"
18 #include "chrome/browser/extensions/extension_util.h" 18 #include "chrome/browser/extensions/extension_util.h"
19 #include "chrome/browser/extensions/test_extension_dir.h" 19 #include "chrome/browser/extensions/test_extension_dir.h"
20 #include "chrome/browser/extensions/test_extension_system.h" 20 #include "chrome/browser/extensions/test_extension_system.h"
21 #include "chrome/browser/extensions/unpacked_installer.h" 21 #include "chrome/browser/extensions/unpacked_installer.h"
22 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/common/extensions/api/developer_private.h" 23 #include "chrome/common/extensions/api/developer_private.h"
24 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
25 #include "chrome/test/base/test_browser_window.h" 25 #include "chrome/test/base/test_browser_window.h"
26 #include "components/crx_file/id_util.h" 26 #include "components/crx_file/id_util.h"
27 #include "content/public/test/test_web_contents_factory.h" 27 #include "content/public/test/web_contents_tester.h"
28 #include "extensions/browser/event_router_factory.h" 28 #include "extensions/browser/event_router_factory.h"
29 #include "extensions/browser/extension_error_test_util.h" 29 #include "extensions/browser/extension_error_test_util.h"
30 #include "extensions/browser/extension_prefs.h" 30 #include "extensions/browser/extension_prefs.h"
31 #include "extensions/browser/extension_registry.h" 31 #include "extensions/browser/extension_registry.h"
32 #include "extensions/browser/extension_system.h" 32 #include "extensions/browser/extension_system.h"
33 #include "extensions/browser/test_extension_registry_observer.h" 33 #include "extensions/browser/test_extension_registry_observer.h"
34 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
35 #include "extensions/common/extension_builder.h" 35 #include "extensions/common/extension_builder.h"
36 #include "extensions/common/extension_set.h" 36 #include "extensions/common/extension_set.h"
37 #include "extensions/common/feature_switch.h" 37 #include "extensions/common/feature_switch.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // get an error. 325 // get an error.
326 base::DeleteFile(crx_path, false); 326 base::DeleteFile(crx_path, false);
327 EXPECT_TRUE(pack_args.Remove(1u, nullptr)); // Remove the pem key argument. 327 EXPECT_TRUE(pack_args.Remove(1u, nullptr)); // Remove the pem key argument.
328 EXPECT_TRUE(pack_args.Remove(1u, nullptr)); // Remove the flags argument. 328 EXPECT_TRUE(pack_args.Remove(1u, nullptr)); // Remove the flags argument.
329 EXPECT_TRUE(TestPackExtensionFunction( 329 EXPECT_TRUE(TestPackExtensionFunction(
330 pack_args, api::developer_private::PACK_STATUS_ERROR, 0)); 330 pack_args, api::developer_private::PACK_STATUS_ERROR, 0));
331 } 331 }
332 332
333 // Test developerPrivate.choosePath. 333 // Test developerPrivate.choosePath.
334 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateChoosePath) { 334 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateChoosePath) {
335 content::TestWebContentsFactory web_contents_factory; 335 std::unique_ptr<content::WebContents> web_contents(
336 content::WebContents* web_contents = 336 content::WebContentsTester::CreateTestWebContents(profile(), nullptr));
337 web_contents_factory.CreateWebContents(profile());
338 337
339 base::FilePath expected_dir_path = data_dir().AppendASCII("good_unpacked"); 338 base::FilePath expected_dir_path = data_dir().AppendASCII("good_unpacked");
340 api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&expected_dir_path); 339 api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&expected_dir_path);
341 340
342 // Try selecting a directory. 341 // Try selecting a directory.
343 base::ListValue choose_args; 342 base::ListValue choose_args;
344 choose_args.AppendString("FOLDER"); 343 choose_args.AppendString("FOLDER");
345 choose_args.AppendString("LOAD"); 344 choose_args.AppendString("LOAD");
346 scoped_refptr<UIThreadExtensionFunction> function( 345 scoped_refptr<UIThreadExtensionFunction> function(
347 new api::DeveloperPrivateChoosePathFunction()); 346 new api::DeveloperPrivateChoosePathFunction());
(...skipping 21 matching lines...) Expand all
369 // Try canceling the file dialog. 368 // Try canceling the file dialog.
370 api::EntryPicker::SkipPickerAndAlwaysCancelForTest(); 369 api::EntryPicker::SkipPickerAndAlwaysCancelForTest();
371 function = new api::DeveloperPrivateChoosePathFunction(); 370 function = new api::DeveloperPrivateChoosePathFunction();
372 function->SetRenderFrameHost(web_contents->GetMainFrame()); 371 function->SetRenderFrameHost(web_contents->GetMainFrame());
373 EXPECT_FALSE(RunFunction(function, choose_args)); 372 EXPECT_FALSE(RunFunction(function, choose_args));
374 EXPECT_EQ(std::string("File selection was canceled."), function->GetError()); 373 EXPECT_EQ(std::string("File selection was canceled."), function->GetError());
375 } 374 }
376 375
377 // Test developerPrivate.loadUnpacked. 376 // Test developerPrivate.loadUnpacked.
378 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateLoadUnpacked) { 377 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateLoadUnpacked) {
379 content::TestWebContentsFactory web_contents_factory; 378 std::unique_ptr<content::WebContents> web_contents(
380 content::WebContents* web_contents = 379 content::WebContentsTester::CreateTestWebContents(profile(), nullptr));
381 web_contents_factory.CreateWebContents(profile());
382 380
383 base::FilePath path = data_dir().AppendASCII("good_unpacked"); 381 base::FilePath path = data_dir().AppendASCII("good_unpacked");
384 api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&path); 382 api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&path);
385 383
386 // Try loading a good extension (it should succeed, and the extension should 384 // Try loading a good extension (it should succeed, and the extension should
387 // be added). 385 // be added).
388 scoped_refptr<UIThreadExtensionFunction> function( 386 scoped_refptr<UIThreadExtensionFunction> function(
389 new api::DeveloperPrivateLoadUnpackedFunction()); 387 new api::DeveloperPrivateLoadUnpackedFunction());
390 function->SetRenderFrameHost(web_contents->GetMainFrame()); 388 function->SetRenderFrameHost(web_contents->GetMainFrame());
391 ExtensionIdSet current_ids = registry()->enabled_extensions().GetIDs(); 389 ExtensionIdSet current_ids = registry()->enabled_extensions().GetIDs();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 .Append( 542 .Append(
545 DictionaryBuilder().Set("extensionId", extension->id()).Build()) 543 DictionaryBuilder().Set("extensionId", extension->id()).Build())
546 .Build(); 544 .Build();
547 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); 545 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction();
548 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); 546 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError();
549 // No more errors! 547 // No more errors!
550 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty()); 548 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty());
551 } 549 }
552 550
553 } // namespace extensions 551 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/tabs/tabs_api_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698